error using struct content translated with SIP from cpp
Phil Thompson
phil at riverbankcomputing.com
Sun Dec 19 16:52:07 GMT 2021
On 18/12/2021 14:59, Marian Thomsen wrote:
> Hello,
>
> I'm searching for a solution for an encoding error (a possible
> constraint violation) that occures when the following struct is in the
> data to encode.
> I'm trying to pass an ecoded string to company name that turns to
> garbage. This only happens in the first encoding iteration the next
> ones are fine (the string is always the same).
>
>
> typedef unsigned char OSUTF8CHAR;
>
> struct ASN1T_DangerousGoodsExtended {
>
> %TypeHeaderCode
> #include <ITS-Container.h>
> %End
>
> // ...
>
> const OSUTF8CHAR* companyName; // <- causes the encoding error
>
> // ...
>
> ASN1T_DangerousGoodsExtended ();
> } ;
>
>
> This is the code extract of the sip translation:
>
> extern "C" {static PyObject
> *varget_ASN1T_DangerousGoodsExtended_companyName(void *, PyObject *,
> PyObject *);}
> static PyObject *varget_ASN1T_DangerousGoodsExtended_companyName(void
> *sipSelf, PyObject *, PyObject *)
> {
> const ::OSUTF8CHAR*sipVal;
> ::ASN1T_DangerousGoodsExtended *sipCpp = reinterpret_cast<
> ::ASN1T_DangerousGoodsExtended *>(sipSelf);
>
> sipVal = sipCpp->companyName;
>
> if (sipVal == SIP_NULLPTR)
> {
> Py_INCREF(Py_None);
> return Py_None;
> }
>
> return PyBytes_FromString((char *)sipVal);
> }
>
>
> extern "C" {static int
> varset_ASN1T_DangerousGoodsExtended_companyName(void *, PyObject *,
> PyObject *);}
> static int varset_ASN1T_DangerousGoodsExtended_companyName(void
> *sipSelf, PyObject *sipPy, PyObject *sipPySelf)
> {
> const ::OSUTF8CHAR*sipVal;
> ::ASN1T_DangerousGoodsExtended *sipCpp = reinterpret_cast<
> ::ASN1T_DangerousGoodsExtended *>(sipSelf);
>
> sipVal = (const unsigned char *)sipBytes_AsString(sipPy);
>
> if (PyErr_Occurred() != SIP_NULLPTR)
> return -1;
>
> sipCpp->companyName = sipVal;
>
> sipKeepReference(sipPySelf, -65, sipPy);
>
> return 0;
> }
>
> If someone has an idea that could help me, I would be greatflul for an
> answer.
>
> Regards
>
> M.T.
Use the /Encoding/ annotation...
https://www.riverbankcomputing.com/static/Docs/sip/annotations.html#variable-annotation-Encoding
Phil
More information about the PyQt
mailing list