A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-January/142738.html below:

[Python-Dev] C struct for Str( )

[Python-Dev] C struct for Str( )Eddy Quicksall Eddy at Quicksall.com
Fri Jan 15 18:31:23 EST 2016
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 <W:\Python-3.5.1\Include\python.h>
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

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4