PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/python/c-api/objbuffer.html

https://bitbucket.org/stillzhl/manuals
HTML | 213 lines | 195 code | 18 blank | 0 comment | 0 complexity | 16e2d63592436f47554f35e796c420e4 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Old Buffer Protocol &mdash; Python v2.7.3 documentation</title>
  7. <link rel="stylesheet" href="../_static/default.css" type="text/css" />
  8. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '2.7.3',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="../_static/jquery.js"></script>
  19. <script type="text/javascript" src="../_static/underscore.js"></script>
  20. <script type="text/javascript" src="../_static/doctools.js"></script>
  21. <script type="text/javascript" src="../_static/sidebar.js"></script>
  22. <link rel="search" type="application/opensearchdescription+xml"
  23. title="Search within Python v2.7.3 documentation"
  24. href="../_static/opensearch.xml"/>
  25. <link rel="author" title="About these documents" href="../about.html" />
  26. <link rel="copyright" title="Copyright" href="../copyright.html" />
  27. <link rel="top" title="Python v2.7.3 documentation" href="../index.html" />
  28. <link rel="up" title="Abstract Objects Layer" href="abstract.html" />
  29. <link rel="next" title="Concrete Objects Layer" href="concrete.html" />
  30. <link rel="prev" title="Iterator Protocol" href="iter.html" />
  31. <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
  32. <script type="text/javascript" src="../_static/copybutton.js"></script>
  33. <script type="text/javascript" src="../_static/version_switch.js"></script>
  34. </head>
  35. <body>
  36. <div class="related">
  37. <h3>Navigation</h3>
  38. <ul>
  39. <li class="right" style="margin-right: 10px">
  40. <a href="../genindex.html" title="General Index"
  41. accesskey="I">index</a></li>
  42. <li class="right" >
  43. <a href="../py-modindex.html" title="Python Module Index"
  44. >modules</a> |</li>
  45. <li class="right" >
  46. <a href="concrete.html" title="Concrete Objects Layer"
  47. accesskey="N">next</a> |</li>
  48. <li class="right" >
  49. <a href="iter.html" title="Iterator Protocol"
  50. accesskey="P">previous</a> |</li>
  51. <li><img src="../_static/py.png" alt=""
  52. style="vertical-align: middle; margin-top: -1px"/></li>
  53. <li><a href="http://www.python.org/">Python</a> &raquo;</li>
  54. <li>
  55. <span class="version_switcher_placeholder">2.7.3</span>
  56. <a href="../index.html">Documentation</a> &raquo;
  57. </li>
  58. <li><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
  59. <li><a href="abstract.html" accesskey="U">Abstract Objects Layer</a> &raquo;</li>
  60. </ul>
  61. </div>
  62. <div class="document">
  63. <div class="documentwrapper">
  64. <div class="bodywrapper">
  65. <div class="body">
  66. <div class="section" id="old-buffer-protocol">
  67. <span id="abstract-buffer"></span><h1>Old Buffer Protocol<a class="headerlink" href="#old-buffer-protocol" title="Permalink to this headline"></a></h1>
  68. <p>This section describes the legacy buffer protocol, which has been introduced
  69. in Python 1.6. It is still supported but deprecated in the Python 2.x series.
  70. Python 3 introduces a new buffer protocol which fixes weaknesses and
  71. shortcomings of the protocol, and has been backported to Python 2.6. See
  72. <a class="reference internal" href="buffer.html#bufferobjects"><em>Buffers and Memoryview Objects</em></a> for more information.</p>
  73. <dl class="function">
  74. <dt id="PyObject_AsCharBuffer">
  75. int <tt class="descname">PyObject_AsCharBuffer</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*obj</em>, const char<em>&nbsp;**buffer</em>, Py_ssize_t<em>&nbsp;*buffer_len</em><big>)</big><a class="headerlink" href="#PyObject_AsCharBuffer" title="Permalink to this definition"></a></dt>
  76. <dd><p>Returns a pointer to a read-only memory location usable as character-based
  77. input. The <em>obj</em> argument must support the single-segment character buffer
  78. interface. On success, returns <tt class="docutils literal"><span class="pre">0</span></tt>, sets <em>buffer</em> to the memory location
  79. and <em>buffer_len</em> to the buffer length. Returns <tt class="docutils literal"><span class="pre">-1</span></tt> and sets a
  80. <a class="reference internal" href="../library/exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a> on error.</p>
  81. <p class="versionadded">
  82. <span class="versionmodified">New in version 1.6.</span></p>
  83. <p class="versionchanged">
  84. <span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span> <span class="pre">*</span></tt> type for <em>buffer_len</em>. This might
  85. require changes in your code for properly supporting 64-bit systems.</p>
  86. </dd></dl>
  87. <dl class="function">
  88. <dt id="PyObject_AsReadBuffer">
  89. int <tt class="descname">PyObject_AsReadBuffer</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*obj</em>, const void<em>&nbsp;**buffer</em>, Py_ssize_t<em>&nbsp;*buffer_len</em><big>)</big><a class="headerlink" href="#PyObject_AsReadBuffer" title="Permalink to this definition"></a></dt>
  90. <dd><p>Returns a pointer to a read-only memory location containing arbitrary data.
  91. The <em>obj</em> argument must support the single-segment readable buffer
  92. interface. On success, returns <tt class="docutils literal"><span class="pre">0</span></tt>, sets <em>buffer</em> to the memory location
  93. and <em>buffer_len</em> to the buffer length. Returns <tt class="docutils literal"><span class="pre">-1</span></tt> and sets a
  94. <a class="reference internal" href="../library/exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a> on error.</p>
  95. <p class="versionadded">
  96. <span class="versionmodified">New in version 1.6.</span></p>
  97. <p class="versionchanged">
  98. <span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span> <span class="pre">*</span></tt> type for <em>buffer_len</em>. This might
  99. require changes in your code for properly supporting 64-bit systems.</p>
  100. </dd></dl>
  101. <dl class="function">
  102. <dt id="PyObject_CheckReadBuffer">
  103. int <tt class="descname">PyObject_CheckReadBuffer</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><big>)</big><a class="headerlink" href="#PyObject_CheckReadBuffer" title="Permalink to this definition"></a></dt>
  104. <dd><p>Returns <tt class="docutils literal"><span class="pre">1</span></tt> if <em>o</em> supports the single-segment readable buffer interface.
  105. Otherwise returns <tt class="docutils literal"><span class="pre">0</span></tt>.</p>
  106. <p class="versionadded">
  107. <span class="versionmodified">New in version 2.2.</span></p>
  108. </dd></dl>
  109. <dl class="function">
  110. <dt id="PyObject_AsWriteBuffer">
  111. int <tt class="descname">PyObject_AsWriteBuffer</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*obj</em>, void<em>&nbsp;**buffer</em>, Py_ssize_t<em>&nbsp;*buffer_len</em><big>)</big><a class="headerlink" href="#PyObject_AsWriteBuffer" title="Permalink to this definition"></a></dt>
  112. <dd><p>Returns a pointer to a writeable memory location. The <em>obj</em> argument must
  113. support the single-segment, character buffer interface. On success,
  114. returns <tt class="docutils literal"><span class="pre">0</span></tt>, sets <em>buffer</em> to the memory location and <em>buffer_len</em> to the
  115. buffer length. Returns <tt class="docutils literal"><span class="pre">-1</span></tt> and sets a <a class="reference internal" href="../library/exceptions.html#exceptions.TypeError" title="exceptions.TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a> on error.</p>
  116. <p class="versionadded">
  117. <span class="versionmodified">New in version 1.6.</span></p>
  118. <p class="versionchanged">
  119. <span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span> <span class="pre">*</span></tt> type for <em>buffer_len</em>. This might
  120. require changes in your code for properly supporting 64-bit systems.</p>
  121. </dd></dl>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. <div class="sphinxsidebar">
  127. <div class="sphinxsidebarwrapper">
  128. <h4>Previous topic</h4>
  129. <p class="topless"><a href="iter.html"
  130. title="previous chapter">Iterator Protocol</a></p>
  131. <h4>Next topic</h4>
  132. <p class="topless"><a href="concrete.html"
  133. title="next chapter">Concrete Objects Layer</a></p>
  134. <h3>This Page</h3>
  135. <ul class="this-page-menu">
  136. <li><a href="../bugs.html">Report a Bug</a></li>
  137. <li><a href="../_sources/c-api/objbuffer.txt"
  138. rel="nofollow">Show Source</a></li>
  139. </ul>
  140. <div id="searchbox" style="display: none">
  141. <h3>Quick search</h3>
  142. <form class="search" action="../search.html" method="get">
  143. <input type="text" name="q" size="18" />
  144. <input type="submit" value="Go" />
  145. <input type="hidden" name="check_keywords" value="yes" />
  146. <input type="hidden" name="area" value="default" />
  147. </form>
  148. <p class="searchtip" style="font-size: 90%">
  149. Enter search terms or a module, class or function name.
  150. </p>
  151. </div>
  152. <script type="text/javascript">$('#searchbox').show(0);</script>
  153. </div>
  154. </div>
  155. <div class="clearer"></div>
  156. </div>
  157. <div class="related">
  158. <h3>Navigation</h3>
  159. <ul>
  160. <li class="right" style="margin-right: 10px">
  161. <a href="../genindex.html" title="General Index"
  162. >index</a></li>
  163. <li class="right" >
  164. <a href="../py-modindex.html" title="Python Module Index"
  165. >modules</a> |</li>
  166. <li class="right" >
  167. <a href="concrete.html" title="Concrete Objects Layer"
  168. >next</a> |</li>
  169. <li class="right" >
  170. <a href="iter.html" title="Iterator Protocol"
  171. >previous</a> |</li>
  172. <li><img src="../_static/py.png" alt=""
  173. style="vertical-align: middle; margin-top: -1px"/></li>
  174. <li><a href="http://www.python.org/">Python</a> &raquo;</li>
  175. <li>
  176. <span class="version_switcher_placeholder">2.7.3</span>
  177. <a href="../index.html">Documentation</a> &raquo;
  178. </li>
  179. <li><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
  180. <li><a href="abstract.html" >Abstract Objects Layer</a> &raquo;</li>
  181. </ul>
  182. </div>
  183. <div class="footer">
  184. &copy; <a href="../copyright.html">Copyright</a> 1990-2013, Python Software Foundation.
  185. <br />
  186. The Python Software Foundation is a non-profit corporation.
  187. <a href="http://www.python.org/psf/donations/">Please donate.</a>
  188. <br />
  189. Last updated on Mar 20, 2013.
  190. <a href="../bugs.html">Found a bug</a>?
  191. <br />
  192. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
  193. </div>
  194. </body>
  195. </html>