diff options
Diffstat (limited to 'devdocs/python~3.12/c-api%2Fmarshal.html')
| -rw-r--r-- | devdocs/python~3.12/c-api%2Fmarshal.html | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/devdocs/python~3.12/c-api%2Fmarshal.html b/devdocs/python~3.12/c-api%2Fmarshal.html new file mode 100644 index 00000000..c7ae2158 --- /dev/null +++ b/devdocs/python~3.12/c-api%2Fmarshal.html @@ -0,0 +1,30 @@ + <span id="marshalling-utils"></span><h1>Data marshalling support</h1> <p>These routines allow C code to work with serialized objects using the same data format as the <a class="reference internal" href="../library/marshal#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code>marshal</code></a> module. There are functions to write data into the serialization format, and additional functions that can be used to read the data back. Files used to store marshalled data must be opened in binary mode.</p> <p>Numeric values are stored with the least significant byte first.</p> <p>The module supports two versions of the data format: version 0 is the historical version, version 1 shares interned strings in the file, and upon unmarshalling. Version 2 uses a binary format for floating point numbers. <code>Py_MARSHAL_VERSION</code> indicates the current file format (currently 2).</p> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_WriteLongToFile"> +<code>void PyMarshal_WriteLongToFile(long value, FILE *file, int version)</code> </dt> <dd> +<p>Marshal a <span class="c-expr sig sig-inline c"><span class="kt">long</span></span> integer, <em>value</em>, to <em>file</em>. This will only write the least-significant 32 bits of <em>value</em>; regardless of the size of the native <span class="c-expr sig sig-inline c"><span class="kt">long</span></span> type. <em>version</em> indicates the file format.</p> <p>This function can fail, in which case it sets the error indicator. Use <a class="reference internal" href="exceptions#c.PyErr_Occurred" title="PyErr_Occurred"><code>PyErr_Occurred()</code></a> to check for that.</p> </dd> +</dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_WriteObjectToFile"> +<code>void PyMarshal_WriteObjectToFile(PyObject *value, FILE *file, int version)</code> </dt> <dd> +<p>Marshal a Python object, <em>value</em>, to <em>file</em>. <em>version</em> indicates the file format.</p> <p>This function can fail, in which case it sets the error indicator. Use <a class="reference internal" href="exceptions#c.PyErr_Occurred" title="PyErr_Occurred"><code>PyErr_Occurred()</code></a> to check for that.</p> </dd> +</dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_WriteObjectToString"> +<code>PyObject *PyMarshal_WriteObjectToString(PyObject *value, int version)</code> </dt> <dd> +<em class="refcount">Return value: New reference.</em><p>Return a bytes object containing the marshalled representation of <em>value</em>. <em>version</em> indicates the file format.</p> </dd> +</dl> <p>The following functions allow marshalled values to be read back in.</p> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_ReadLongFromFile"> +<code>long PyMarshal_ReadLongFromFile(FILE *file)</code> </dt> <dd> +<p>Return a C <span class="c-expr sig sig-inline c"><span class="kt">long</span></span> from the data stream in a <span class="c-expr sig sig-inline c"><span class="n">FILE</span><span class="p">*</span></span> opened for reading. Only a 32-bit value can be read in using this function, regardless of the native size of <span class="c-expr sig sig-inline c"><span class="kt">long</span></span>.</p> <p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions#EOFError" title="EOFError"><code>EOFError</code></a>) and returns <code>-1</code>.</p> </dd> +</dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_ReadShortFromFile"> +<code>int PyMarshal_ReadShortFromFile(FILE *file)</code> </dt> <dd> +<p>Return a C <span class="c-expr sig sig-inline c"><span class="kt">short</span></span> from the data stream in a <span class="c-expr sig sig-inline c"><span class="n">FILE</span><span class="p">*</span></span> opened for reading. Only a 16-bit value can be read in using this function, regardless of the native size of <span class="c-expr sig sig-inline c"><span class="kt">short</span></span>.</p> <p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions#EOFError" title="EOFError"><code>EOFError</code></a>) and returns <code>-1</code>.</p> </dd> +</dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_ReadObjectFromFile"> +<code>PyObject *PyMarshal_ReadObjectFromFile(FILE *file)</code> </dt> <dd> +<em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a <span class="c-expr sig sig-inline c"><span class="n">FILE</span><span class="p">*</span></span> opened for reading.</p> <p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions#EOFError" title="EOFError"><code>EOFError</code></a>, <a class="reference internal" href="../library/exceptions#ValueError" title="ValueError"><code>ValueError</code></a> or <a class="reference internal" href="../library/exceptions#TypeError" title="TypeError"><code>TypeError</code></a>) and returns <code>NULL</code>.</p> </dd> +</dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_ReadLastObjectFromFile"> +<code>PyObject *PyMarshal_ReadLastObjectFromFile(FILE *file)</code> </dt> <dd> +<em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a <span class="c-expr sig sig-inline c"><span class="n">FILE</span><span class="p">*</span></span> opened for reading. Unlike <a class="reference internal" href="#c.PyMarshal_ReadObjectFromFile" title="PyMarshal_ReadObjectFromFile"><code>PyMarshal_ReadObjectFromFile()</code></a>, this function assumes that no further objects will be read from the file, allowing it to aggressively load file data into memory so that the de-serialization can operate from data in memory rather than reading a byte at a time from the file. Only use these variant if you are certain that you won’t be reading anything else from the file.</p> <p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions#EOFError" title="EOFError"><code>EOFError</code></a>, <a class="reference internal" href="../library/exceptions#ValueError" title="ValueError"><code>ValueError</code></a> or <a class="reference internal" href="../library/exceptions#TypeError" title="TypeError"><code>TypeError</code></a>) and returns <code>NULL</code>.</p> </dd> +</dl> <dl class="c function"> <dt class="sig sig-object c" id="c.PyMarshal_ReadObjectFromString"> +<code>PyObject *PyMarshal_ReadObjectFromString(const char *data, Py_ssize_t len)</code> </dt> <dd> +<em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a byte buffer containing <em>len</em> bytes pointed to by <em>data</em>.</p> <p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions#EOFError" title="EOFError"><code>EOFError</code></a>, <a class="reference internal" href="../library/exceptions#ValueError" title="ValueError"><code>ValueError</code></a> or <a class="reference internal" href="../library/exceptions#TypeError" title="TypeError"><code>TypeError</code></a>) and returns <code>NULL</code>.</p> </dd> +</dl> <div class="_attribution"> + <p class="_attribution-p"> + © 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br> + <a href="https://docs.python.org/3.12/c-api/marshal.html" class="_attribution-link">https://docs.python.org/3.12/c-api/marshal.html</a> + </p> +</div> |
