(original) (raw)

I don't quite see what this has to do with has to do with the development of Python, Eddy. You can always reference the C API at https://docs.python.org/3/c-api/index.html . And \`PyBytesObject\` is an instance of \`bytes\` in Python.

On Fri, 15 Jan 2016 at 15:33 Eddy Quicksall <Eddy@quicksall.com> wrote:
I want to fill an Str() string from a C function. But I think I am using the
wrong structure (PyBytesObject). I have written a C function to dump the
Python class but as you can see the structure I'm using does not match the
data in the class.

Can someone please tell me the correct structure:

\--------- Python snip ---------
class \_vendorRecord\_2:
vendorListNumber = str()
vendorNumber = str()
vendorName = str('x' \* 20)

vendorRecord\_2 = \_vendorRecord\_2()

print(len(vendorRecord\_2.vendorName))
print(vendorRecord\_2.vendorName + '|')
XBaseDump\_PythonString(py\_object(vendorRecord\_2.vendorName))

\--------- C function --------
#define MS\_NO\_COREDLL
#undef \_DEBUG
#include
DSI\_DLL void CALL\_TYPE XBaseDump\_PythonString( PyBytesObject \*pBytesObject )
{
printf( "ob\_size = %d, ob\_shash = %X, ob\_sval = %s\\n",
pBytesObject->ob\_base.ob\_size, pBytesObject->ob\_shash, pBytesObject->ob\_sval
);
printf( "offsetof(ob\_size) = %d, offsetof(ob\_sval) = %d\\n", offsetof(
PyBytesObject, ob\_base.ob\_size ),
offsetof( PyBytesObject, ob\_sval ) );
printf( "sizeof(PyBytesObject) = %d\\n", sizeof(PyBytesObject) );
DsmDumpBytes( pBytesObject, 32 );
}

\-------- output ------------
20
xxxxxxxxxxxxxxxxxxxx|
ob\_size = 20, ob\_shash = 70768D53, ob\_sval = σsci
offsetof(ob\_size) = 8, offsetof(ob\_sval) = 16
sizeof(PyBytesObject) = 20
0000: 03 00 00 00 60 B0 DC 1D 14 00 00 00 53 8D 76 70 ....-...........
0016: E5 73 63 69 00 00 00 00 78 78 78 78 78 78 78 78 V...............




\---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/brett%40python.org