Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gershnik committed Mar 30, 2023
2 parents cf6e7ef + 7bd08d7 commit 70824a8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/inc/sys_string/impl/platforms/python_any.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ namespace sysstr::util

template <typename T>
struct HasHashMember <T, decltype((void)T::hash, 0)> : std::true_type { };

template<class T>
constexpr void gccIsAPieceOfShit_assignHash(T & obj) {
if constexpr(HasHashMember<T>::value)
obj.hash = -1;
}

template<class T>
constexpr void gccIsAPieceOfShit_assignData(T & obj, void * data) {
obj.any = data;
}

constexpr void gccIsAPieceOfShit_assignData(void * & obj, void * data) {
obj = data;
}

template<PyUnicode_Kind Kind>
struct PyUnicodeObject_wrapper : PyUnicodeObject
Expand All @@ -452,14 +467,10 @@ namespace sysstr::util
PyUnicodeObject{{{PyObject_HEAD_INIT(&PyUnicode_Type)}}}
{
this->_base._base.length = size;
if constexpr (HasHashMember<PyASCIIObject>::value) //pypy lacks hash
this->_base._base.hash = -1;
gccIsAPieceOfShit_assignHash(this->_base._base); //pypy lacks hash in PyASCIIObject
this->_base._base.state.kind = Kind;
this->_base._base.state.ready = 1;
if constexpr (std::is_same_v<decltype(this->data), void *>)
this->data = const_cast<void *>(chars);
else
this->data.any = const_cast<void *>(chars);
gccIsAPieceOfShit_assignData(this->data, const_cast<void *>(chars));
if constexpr (Kind == PyUnicode_1BYTE_KIND)
{
this->_base._base.state.ascii = 1;
Expand Down

0 comments on commit 70824a8

Please sign in to comment.