[Python-Dev] C struct for Str( ) (original) (raw)

Victor Pantoja victor.pantoja at gmail.com
Fri Jan 15 20:08:15 EST 2016


Hi Eddy

You can try some of the lists in https://mail.python.org/mailman/listinfo.

Best, victor

2016-01-15 22:23 GMT-02:00 Eddy Quicksall <Eddy at quicksall.com>:

Sorry, I must be on the wrong list. Can you please give me the correct list?

Eddy From: Brett Cannon [mailto:brett at python.org] Sent: Friday, January 15, 2016 6:58 PM To: Eddy Quicksall; python-dev at python.org Subject: Re: [Python-Dev] C struct for Str( ) 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 at 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 vendorRecord2: vendorListNumber = str() vendorNumber = str() vendorName = str('x' * 20) vendorRecord2 = vendorRecord2() print(len(vendorRecord2.vendorName)) print(vendorRecord2.vendorName + '|') XBaseDumpPythonString(pyobject(vendorRecord2.vendorName)) --------- C function -------- #define MSNOCOREDLL #undef DEBUG #include <W:\Python-3.5.1\Include\python.h> DSIDLL void CALLTYPE XBaseDumpPythonString( PyBytesObject *pBytesObject ) { printf( "obsize = %d, obshash = %X, obsval = %s\n", pBytesObject->obbase.obsize, pBytesObject->obshash, pBytesObject->obsval ); printf( "offsetof(obsize) = %d, offsetof(obsval) = %d\n", offsetof( PyBytesObject, obbase.obsize ), offsetof( PyBytesObject, obsval ) ); printf( "sizeof(PyBytesObject) = %d\n", sizeof(PyBytesObject) ); DsmDumpBytes( pBytesObject, 32 ); } -------- output ------------ 20 xxxxxxxxxxxxxxxxxxxx| obsize = 20, obshash = 70768D53, obsval = σsci offsetof(obsize) = 8, offsetof(obsval) = 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 at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/brett%40python.org

<https://www.avast.com/sig-email?utmmedium=email&utmsource=link&utmcampaign=sig-email&utmcontent=emailclient> This email has been sent from a virus-free computer protected by Avast. www.avast.com <https://www.avast.com/sig-email?utmmedium=email&utmsource=link&utmcampaign=sig-email&utmcontent=emailclient>


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/victor.pantoja%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160115/8c7e9366/attachment.html>



More information about the Python-Dev mailing list