1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
<html xmlns="http://www.w3.org/1999/xhtml">
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
<title>Data marshalling support — Python 3.5.1 documentation</title>
11
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
12
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
14
<script type="text/javascript">
15
var DOCUMENTATION_OPTIONS = {
18
COLLAPSE_INDEX: false,
23
<script type="text/javascript" src="../_static/jquery.js"></script>
24
<script type="text/javascript" src="../_static/underscore.js"></script>
25
<script type="text/javascript" src="../_static/doctools.js"></script>
26
<script type="text/javascript" src="../_static/sidebar.js"></script>
27
<link rel="search" type="application/opensearchdescription+xml"
28
title="Search within Python 3.5.1 documentation"
29
href="../_static/opensearch.xml"/>
30
<link rel="author" title="About these documents" href="../about.html" />
31
<link rel="copyright" title="Copyright" href="../copyright.html" />
32
<link rel="top" title="Python 3.5.1 documentation" href="../contents.html" />
33
<link rel="up" title="Utilities" href="utilities.html" />
34
<link rel="next" title="Parsing arguments and building values" href="arg.html" />
35
<link rel="prev" title="Importing Modules" href="import.html" />
36
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
<script type="text/javascript" src="../_static/copybutton.js"></script>
38
<script type="text/javascript" src="../_static/version_switch.js"></script>
43
<body role="document">
44
<div class="related" role="navigation" aria-label="related navigation">
47
<li class="right" style="margin-right: 10px">
48
<a href="../genindex.html" title="General Index"
49
accesskey="I">index</a></li>
51
<a href="../py-modindex.html" title="Python Module Index"
54
<a href="arg.html" title="Parsing arguments and building values"
55
accesskey="N">next</a> |</li>
57
<a href="import.html" title="Importing Modules"
58
accesskey="P">previous</a> |</li>
59
<li><img src="../_static/py.png" alt=""
60
style="vertical-align: middle; margin-top: -1px"/></li>
61
<li><a href="https://www.python.org/">Python</a> »</li>
63
<span class="version_switcher_placeholder">3.5.1</span>
64
<a href="../index.html">Documentation </a> »
67
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> »</li>
68
<li class="nav-item nav-item-2"><a href="utilities.html" accesskey="U">Utilities</a> »</li>
72
<div class="document">
73
<div class="documentwrapper">
74
<div class="bodywrapper">
75
<div class="body" role="main">
77
<div class="section" id="data-marshalling-support">
78
<span id="marshalling-utils"></span><h1>Data marshalling support<a class="headerlink" href="#data-marshalling-support" title="Permalink to this headline">¶</a></h1>
79
<p>These routines allow C code to work with serialized objects using the same
80
data format as the <a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal"><span class="pre">marshal</span></code></a> module. There are functions to write data
81
into the serialization format, and additional functions that can be used to
82
read the data back. Files used to store marshalled data must be opened in
84
<p>Numeric values are stored with the least significant byte first.</p>
85
<p>The module supports two versions of the data format: version 0 is the
86
historical version, version 1 shares interned strings in the file, and upon
87
unmarshalling. Version 2 uses a binary format for floating point numbers.
88
<em>Py_MARSHAL_VERSION</em> indicates the current file format (currently 2).</p>
90
<dt id="c.PyMarshal_WriteLongToFile">
91
void <code class="descname">PyMarshal_WriteLongToFile</code><span class="sig-paren">(</span>long<em> value</em>, FILE<em> *file</em>, int<em> version</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_WriteLongToFile" title="Permalink to this definition">¶</a></dt>
92
<dd><p>Marshal a <code class="xref c c-type docutils literal"><span class="pre">long</span></code> integer, <em>value</em>, to <em>file</em>. This will only write
93
the least-significant 32 bits of <em>value</em>; regardless of the size of the
94
native <code class="xref c c-type docutils literal"><span class="pre">long</span></code> type. <em>version</em> indicates the file format.</p>
98
<dt id="c.PyMarshal_WriteObjectToFile">
99
void <code class="descname">PyMarshal_WriteObjectToFile</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *value</em>, FILE<em> *file</em>, int<em> version</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_WriteObjectToFile" title="Permalink to this definition">¶</a></dt>
100
<dd><p>Marshal a Python object, <em>value</em>, to <em>file</em>.
101
<em>version</em> indicates the file format.</p>
104
<dl class="function">
105
<dt id="c.PyMarshal_WriteObjectToString">
106
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_WriteObjectToString</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *value</em>, int<em> version</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_WriteObjectToString" title="Permalink to this definition">¶</a></dt>
107
<dd><em class="refcount">Return value: New reference.</em><p>Return a string object containing the marshalled representation of <em>value</em>.
108
<em>version</em> indicates the file format.</p>
111
<p>The following functions allow marshalled values to be read back in.</p>
112
<p>XXX What about error detection? It appears that reading past the end of the
113
file will always result in a negative numeric value (where that’s relevant),
114
but it’s not clear that negative values won’t be handled properly when there’s
115
no error. What’s the right way to tell? Should only non-negative values be
116
written using these routines?</p>
117
<dl class="function">
118
<dt id="c.PyMarshal_ReadLongFromFile">
119
long <code class="descname">PyMarshal_ReadLongFromFile</code><span class="sig-paren">(</span>FILE<em> *file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadLongFromFile" title="Permalink to this definition">¶</a></dt>
120
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">long</span></code> from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened
121
for reading. Only a 32-bit value can be read in using this function,
122
regardless of the native size of <code class="xref c c-type docutils literal"><span class="pre">long</span></code>.</p>
123
<p>On error, raise an exception and return <code class="docutils literal"><span class="pre">-1</span></code>.</p>
126
<dl class="function">
127
<dt id="c.PyMarshal_ReadShortFromFile">
128
int <code class="descname">PyMarshal_ReadShortFromFile</code><span class="sig-paren">(</span>FILE<em> *file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadShortFromFile" title="Permalink to this definition">¶</a></dt>
129
<dd><p>Return a C <code class="xref c c-type docutils literal"><span class="pre">short</span></code> from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened
130
for reading. Only a 16-bit value can be read in using this function,
131
regardless of the native size of <code class="xref c c-type docutils literal"><span class="pre">short</span></code>.</p>
132
<p>On error, raise an exception and return <code class="docutils literal"><span class="pre">-1</span></code>.</p>
135
<dl class="function">
136
<dt id="c.PyMarshal_ReadObjectFromFile">
137
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_ReadObjectFromFile</code><span class="sig-paren">(</span>FILE<em> *file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadObjectFromFile" title="Permalink to this definition">¶</a></dt>
138
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened for
140
<p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal"><span class="pre">EOFError</span></code></a> or
141
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>) and returns <em>NULL</em>.</p>
144
<dl class="function">
145
<dt id="c.PyMarshal_ReadLastObjectFromFile">
146
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_ReadLastObjectFromFile</code><span class="sig-paren">(</span>FILE<em> *file</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadLastObjectFromFile" title="Permalink to this definition">¶</a></dt>
147
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a <code class="xref c c-type docutils literal"><span class="pre">FILE*</span></code> opened for
148
reading. Unlike <a class="reference internal" href="#c.PyMarshal_ReadObjectFromFile" title="PyMarshal_ReadObjectFromFile"><code class="xref c c-func docutils literal"><span class="pre">PyMarshal_ReadObjectFromFile()</span></code></a>, this function
149
assumes that no further objects will be read from the file, allowing it to
150
aggressively load file data into memory so that the de-serialization can
151
operate from data in memory rather than reading a byte at a time from the
152
file. Only use these variant if you are certain that you won’t be reading
153
anything else from the file.</p>
154
<p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal"><span class="pre">EOFError</span></code></a> or
155
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>) and returns <em>NULL</em>.</p>
158
<dl class="function">
159
<dt id="c.PyMarshal_ReadObjectFromString">
160
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="descname">PyMarshal_ReadObjectFromString</code><span class="sig-paren">(</span>const char<em> *string</em>, Py_ssize_t<em> len</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyMarshal_ReadObjectFromString" title="Permalink to this definition">¶</a></dt>
161
<dd><em class="refcount">Return value: New reference.</em><p>Return a Python object from the data stream in a character buffer
162
containing <em>len</em> bytes pointed to by <em>string</em>.</p>
163
<p>On error, sets the appropriate exception (<a class="reference internal" href="../library/exceptions.html#EOFError" title="EOFError"><code class="xref py py-exc docutils literal"><span class="pre">EOFError</span></code></a> or
164
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>) and returns <em>NULL</em>.</p>
173
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
174
<div class="sphinxsidebarwrapper">
175
<h4>Previous topic</h4>
176
<p class="topless"><a href="import.html"
177
title="previous chapter">Importing Modules</a></p>
179
<p class="topless"><a href="arg.html"
180
title="next chapter">Parsing arguments and building values</a></p>
182
<ul class="this-page-menu">
183
<li><a href="../bugs.html">Report a Bug</a></li>
184
<li><a href="../_sources/c-api/marshal.txt"
185
rel="nofollow">Show Source</a></li>
188
<div id="searchbox" style="display: none" role="search">
189
<h3>Quick search</h3>
190
<form class="search" action="../search.html" method="get">
191
<input type="text" name="q" />
192
<input type="submit" value="Go" />
193
<input type="hidden" name="check_keywords" value="yes" />
194
<input type="hidden" name="area" value="default" />
196
<p class="searchtip" style="font-size: 90%">
197
Enter search terms or a module, class or function name.
200
<script type="text/javascript">$('#searchbox').show(0);</script>
203
<div class="clearer"></div>
205
<div class="related" role="navigation" aria-label="related navigation">
208
<li class="right" style="margin-right: 10px">
209
<a href="../genindex.html" title="General Index"
212
<a href="../py-modindex.html" title="Python Module Index"
215
<a href="arg.html" title="Parsing arguments and building values"
218
<a href="import.html" title="Importing Modules"
220
<li><img src="../_static/py.png" alt=""
221
style="vertical-align: middle; margin-top: -1px"/></li>
222
<li><a href="https://www.python.org/">Python</a> »</li>
224
<span class="version_switcher_placeholder">3.5.1</span>
225
<a href="../index.html">Documentation </a> »
228
<li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> »</li>
229
<li class="nav-item nav-item-2"><a href="utilities.html" >Utilities</a> »</li>
233
© <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
235
The Python Software Foundation is a non-profit corporation.
236
<a href="https://www.python.org/psf/donations/">Please donate.</a>
238
Last updated on Jan 22, 2016.
239
<a href="../bugs.html">Found a bug</a>?
241
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
b'\\ No newline at end of file'