Skip to content

Commit 0e3f776

Browse files
committed
Fix slice compilation on MSVC
cxxbridge-demo.lib(blobstore.o) : error LNK2019: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z) referenced in function "public: __cdecl rust::cxxbridge1::Slice<unsigned char const >::Slice<unsigned char const >(unsigned char const *,unsigned __int64)" (??0?$Slice@$$CBE@cxxbridge1@rust@@qeaa@PEBE_K@Z) cxxbridge-demo.lib(blobstore.o) : error LNK2001: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z) cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z) cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "void __cdecl sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@@YAXPEAXPEBX_K@Z) Hint on symbols that are defined and could potentially match: "void __cdecl rust::cxxbridge1::sliceInit(void *,void const *,unsigned __int64)" (?sliceInit@cxxbridge1@rust@@YAXPEAXPEBX_K@Z) cxxbridge-demo.lib(blobstore.o) : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl sliceLen(void const *)" (?sliceLen@@YA_KPEBX@Z) referenced in function "public: unsigned __int64 __cdecl rust::cxxbridge1::Slice<unsigned char const >::size(void)const " (?size@?$Slice@$$CBE@cxxbridge1@rust@@QEBA_KXZ) cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "unsigned __int64 __cdecl sliceLen(void const *)" (?sliceLen@@YA_KPEBX@Z) Hint on symbols that are defined and could potentially match: "unsigned __int64 __cdecl rust::cxxbridge1::sliceLen(void const *)" (?sliceLen@cxxbridge1@rust@@YA_KPEBX@Z) cxxbridge-demo.lib(blobstore.o) : error LNK2019: unresolved external symbol "void * __cdecl slicePtr(void const *)" (?slicePtr@@YAPEAXPEBX@Z) referenced in function "private: void * __cdecl rust::cxxbridge1::Slice<unsigned char const >::ptr(void)const " (?ptr@?$Slice@$$CBE@cxxbridge1@rust@@AEBAPEAXXZ) cxxbridge-demo.lib(main.rs.o) : error LNK2001: unresolved external symbol "void * __cdecl slicePtr(void const *)" (?slicePtr@@YAPEAXPEBX@Z) Hint on symbols that are defined and could potentially match: "void * __cdecl rust::cxxbridge1::slicePtr(void const *)" (?slicePtr@cxxbridge1@rust@@YAPEAXPEBX@Z) D:\a\cxx\cxx\target\debug\deps\demo.exe : fatal error LNK1120: 3 unresolved externals
1 parent 9bffb93 commit 0e3f776

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

include/cxx.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ class Slice final
180180
void swap(Slice &) noexcept;
181181

182182
private:
183-
void *ptr() const noexcept;
184-
185183
std::array<std::uintptr_t, 2> repr;
186184
};
187185

@@ -487,26 +485,27 @@ constexpr unsafe_bitcopy_t unsafe_bitcopy{};
487485

488486
#ifndef CXXBRIDGE1_RUST_SLICE
489487
#define CXXBRIDGE1_RUST_SLICE
488+
void sliceInit(void *, const void *, std::size_t) noexcept;
489+
void *slicePtr(const void *) noexcept;
490+
std::size_t sliceLen(const void *) noexcept;
491+
490492
template <typename T>
491493
Slice<T>::Slice() noexcept {
492-
void sliceInit(void *, const void *, std::size_t) noexcept;
493494
sliceInit(this, reinterpret_cast<void *>(align_of<T>()), 0);
494495
}
495496

496497
template <typename T>
497498
Slice<T>::Slice(T *s, std::size_t count) noexcept {
498-
void sliceInit(void *, const void *, std::size_t) noexcept;
499499
sliceInit(this, const_cast<typename std::remove_const<T>::type *>(s), count);
500500
}
501501

502502
template <typename T>
503503
T *Slice<T>::data() const noexcept {
504-
return reinterpret_cast<T *>(this->ptr());
504+
return reinterpret_cast<T *>(slicePtr(this));
505505
}
506506

507507
template <typename T>
508508
std::size_t Slice<T>::size() const noexcept {
509-
std::size_t sliceLen(const void *) noexcept;
510509
return sliceLen(this);
511510
}
512511

@@ -523,7 +522,7 @@ bool Slice<T>::empty() const noexcept {
523522
template <typename T>
524523
T &Slice<T>::operator[](std::size_t n) const noexcept {
525524
assert(n < this->size());
526-
auto pos = static_cast<char *>(this->ptr()) + size_of<T>() * n;
525+
auto pos = static_cast<char *>(slicePtr(this)) + size_of<T>() * n;
527526
return *reinterpret_cast<T *>(pos);
528527
}
529528

@@ -663,7 +662,7 @@ bool Slice<T>::iterator::operator>=(const iterator &other) const noexcept {
663662
template <typename T>
664663
typename Slice<T>::iterator Slice<T>::begin() const noexcept {
665664
iterator it;
666-
it.pos = this->ptr();
665+
it.pos = slicePtr(this);
667666
it.stride = size_of<T>();
668667
return it;
669668
}
@@ -679,12 +678,6 @@ template <typename T>
679678
void Slice<T>::swap(Slice &rhs) noexcept {
680679
std::swap(*this, rhs);
681680
}
682-
683-
template <typename T>
684-
void *Slice<T>::ptr() const noexcept {
685-
void *slicePtr(const void *) noexcept;
686-
return slicePtr(this);
687-
}
688681
#endif // CXXBRIDGE1_RUST_SLICE
689682

690683
#ifndef CXXBRIDGE1_RUST_BOX

0 commit comments

Comments
 (0)