annotate Doc/c-api/objbuffer.rst @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 521eac31a893
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
1 .. highlightlang:: c
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
2
64996
4cf77d193f57 Buffers are not sequence objects (!). Put them in the abstract objects layers
Antoine Pitrou <solipsis@pitrou.net>
parents: 64989
diff changeset
3 Old Buffer Protocol
4cf77d193f57 Buffers are not sequence objects (!). Put them in the abstract objects layers
Antoine Pitrou <solipsis@pitrou.net>
parents: 64989
diff changeset
4 -------------------
64989
dc3833984734 Discourage use of the old buffer API funcs
Antoine Pitrou <solipsis@pitrou.net>
parents: 53500
diff changeset
5
dc3833984734 Discourage use of the old buffer API funcs
Antoine Pitrou <solipsis@pitrou.net>
parents: 53500
diff changeset
6 .. deprecated:: 3.0
dc3833984734 Discourage use of the old buffer API funcs
Antoine Pitrou <solipsis@pitrou.net>
parents: 53500
diff changeset
7
dc3833984734 Discourage use of the old buffer API funcs
Antoine Pitrou <solipsis@pitrou.net>
parents: 53500
diff changeset
8 These functions were part of the "old buffer protocol" API in Python 2.
64996
4cf77d193f57 Buffers are not sequence objects (!). Put them in the abstract objects layers
Antoine Pitrou <solipsis@pitrou.net>
parents: 64989
diff changeset
9 In Python 3, this protocol doesn't exist anymore but the functions are still
4cf77d193f57 Buffers are not sequence objects (!). Put them in the abstract objects layers
Antoine Pitrou <solipsis@pitrou.net>
parents: 64989
diff changeset
10 exposed to ease porting 2.x code. They act as a compatibility wrapper
4cf77d193f57 Buffers are not sequence objects (!). Put them in the abstract objects layers
Antoine Pitrou <solipsis@pitrou.net>
parents: 64989
diff changeset
11 around the :ref:`new buffer protocol <bufferobjects>`, but they don't give
4cf77d193f57 Buffers are not sequence objects (!). Put them in the abstract objects layers
Antoine Pitrou <solipsis@pitrou.net>
parents: 64989
diff changeset
12 you control over the lifetime of the resources acquired when a buffer is
4cf77d193f57 Buffers are not sequence objects (!). Put them in the abstract objects layers
Antoine Pitrou <solipsis@pitrou.net>
parents: 64989
diff changeset
13 exported.
64989
dc3833984734 Discourage use of the old buffer API funcs
Antoine Pitrou <solipsis@pitrou.net>
parents: 53500
diff changeset
14
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64996
diff changeset
15 Therefore, it is recommended that you call :c:func:`PyObject_GetBuffer`
64989
dc3833984734 Discourage use of the old buffer API funcs
Antoine Pitrou <solipsis@pitrou.net>
parents: 53500
diff changeset
16 (or the ``y*`` or ``w*`` :ref:`format codes <arg-parsing>` with the
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64996
diff changeset
17 :c:func:`PyArg_ParseTuple` family of functions) to get a buffer view over
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64996
diff changeset
18 an object, and :c:func:`PyBuffer_Release` when the buffer view can be released.
64989
dc3833984734 Discourage use of the old buffer API funcs
Antoine Pitrou <solipsis@pitrou.net>
parents: 53500
diff changeset
19
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
20
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64996
diff changeset
21 .. c:function:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
22
45435
42b3b117391d Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44812
diff changeset
23 Returns a pointer to a read-only memory location usable as character-based
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
24 input. The *obj* argument must support the single-segment character buffer
53498
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
25 interface. On success, returns ``0``, sets *buffer* to the memory location
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
26 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
27 :exc:`TypeError` on error.
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
28
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
29
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64996
diff changeset
30 .. c:function:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
31
53498
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
32 Returns a pointer to a read-only memory location containing arbitrary data.
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
33 The *obj* argument must support the single-segment readable buffer
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
34 interface. On success, returns ``0``, sets *buffer* to the memory location
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
35 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
36 :exc:`TypeError` on error.
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
37
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
38
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64996
diff changeset
39 .. c:function:: int PyObject_CheckReadBuffer(PyObject *o)
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
40
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
41 Returns ``1`` if *o* supports the single-segment readable buffer interface.
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
42 Otherwise returns ``0``.
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
43
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
44
65137
521eac31a893 Migrate to Sphinx 1.0 C language constructs.
Georg Brandl <georg@python.org>
parents: 64996
diff changeset
45 .. c:function:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
44812
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
46
1e8b9e7c34ce Split C API docs in Py3k branch.
Georg Brandl <georg@python.org>
parents:
diff changeset
47 Returns a pointer to a writable memory location. The *obj* argument must
53498
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
48 support the single-segment, character buffer interface. On success,
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
49 returns ``0``, sets *buffer* to the memory location and *buffer_len* to the
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
50 buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error.
1fca1c932696 Merged revisions 71920-71923,71925-71929,71931-71934,71937 via svnmerge from
Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
parents: 45435
diff changeset
51