1from libc.stdio cimport FILE 2 3cdef extern from "Python.h": 4 5 ########################################################################### 6 # Data marshalling support 7 ########################################################################### 8 9 const int Py_MARSHAL_VERSION 10 11 void PyMarshal_WriteLongToFile(long value, FILE *file, int version) 12 # Marshal a long integer, value, to file. This will only write the 13 # least-significant 32 bits of value, regardless of the size of the native 14 # long type. version indicates the file format. 15 16 void PyMarshal_WriteObjectToFile(object value, FILE *file, int version) 17 # Marshal a Python object, value, to file. version indicates the file 18 # format. 19 20 bytes PyMarshal_WriteObjectToString(object value, int version) 21 # Return value: New reference. 22 # Return a bytes object containing the marshalled representation of value. 23 # version indicates the file format. 24 25 long PyMarshal_ReadLongFromFile(FILE *file) except? -1 26 # Return a C long from the data stream in a FILE* opened for reading. Only 27 # a 32-bit value can be read in using this function, regardless of the 28 # native size of long. 29 30 # On error, sets the appropriate exception (EOFError) and returns -1. 31 32 int PyMarshal_ReadShortFromFile(FILE *file) except? -1 33 # Return a C short from the data stream in a FILE* opened for reading. Only 34 # a 16-bit value can be read in using this function, regardless of the 35 # native size of short. 36 37 # On error, sets the appropriate exception (EOFError) and returns -1. 38 39 object PyMarshal_ReadObjectFromFile(FILE *file) 40 # Return value: New reference. 41 # Return a Python object from the data stream in a FILE* opened for 42 # reading. 43 44 # On error, sets the appropriate exception (EOFError, ValueError or 45 # TypeError) and returns NULL. 46 47 object PyMarshal_ReadLastObjectFromFile(FILE *file) 48 # Return value: New reference. 49 # Return a Python object from the data stream in a FILE* opened for 50 # reading. Unlike PyMarshal_ReadObjectFromFile(), this function assumes 51 # that no further objects will be read from the file, allowing it to 52 # aggressively load file data into memory so that the de-serialization can 53 # operate from data in memory, rather than reading a byte at a time from the 54 # file. Only use these variant if you are certain that you won’t be reading 55 # anything else from the file. 56 57 # On error, sets the appropriate exception (EOFError, ValueError or 58 # TypeError) and returns NULL. 59 60 object PyMarshal_ReadObjectFromString(const char *data, Py_ssize_t len) 61 # Return value: New reference. 62 # Return a Python object from the data stream in a byte buffer containing 63 # len bytes pointed to by data. 64 65 # On error, sets the appropriate exception (EOFError, ValueError or 66 # TypeError) and returns NULL. 67