summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2012-07-02 16:22:18 (GMT)
committerdgp <dgp@users.sourceforge.net>2012-07-02 16:22:18 (GMT)
commitff8f7134b39aa2fe4fe16fbda8ce58584f1dc645 (patch)
treea55b666665dee68835dc95f84554c3895f1cbcb2 /generic
parentb3b04348558215a3acd092d58664c31a255781bf (diff)
downloadtcl-bug_1189293.zip
tcl-bug_1189293.tar.gz
tcl-bug_1189293.tar.bz2
1189293 Make '<<' redirects binary safe. Don't use strlen() (or equivalent)bug_1189293
to find end of written data bytes.
Diffstat (limited to 'generic')
0 files changed, 0 insertions, 0 deletions
d the suboffset value dictates how many bytes to add to the pointer after de-referencing. A @@ -114,16 +114,16 @@ The new-style Py_buffer struct } - .. cmember:: Py_ssize_t itemsize + .. c:member:: Py_ssize_t itemsize This is a storage for the itemsize (in bytes) of each element of the shared memory. It is technically un-necessary as it can be obtained - using :cfunc:`PyBuffer_SizeFromFormat`, however an exporter may know + using :c:func:`PyBuffer_SizeFromFormat`, however an exporter may know this information without parsing the format string and it is necessary to know the itemsize for proper interpretation of striding. Therefore, storing it is more convenient and faster. - .. cmember:: void *internal + .. c:member:: void *internal This is for use internally by the exporting object. For example, this might be re-cast as an integer by the exporter and used to store flags @@ -136,14 +136,14 @@ Buffer related functions ======================== -.. cfunction:: int PyObject_CheckBuffer(PyObject *obj) +.. c:function:: int PyObject_CheckBuffer(PyObject *obj) Return 1 if *obj* supports the buffer interface otherwise 0. -.. cfunction:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) +.. c:function:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) - Export *obj* into a :ctype:`Py_buffer`, *view*. These arguments must + Export *obj* into a :c:type:`Py_buffer`, *view*. These arguments must never be *NULL*. The *flags* argument is a bit field indicating what kind of buffer the caller is prepared to deal with and therefore what kind of buffer the exporter is allowed to return. The buffer interface @@ -156,131 +156,131 @@ Buffer related functions just not possible. These errors should be a :exc:`BufferError` unless there is another error that is actually causing the problem. The exporter can use flags information to simplify how much of the - :cdata:`Py_buffer` structure is filled in with non-default values and/or + :c:data:`Py_buffer` structure is filled in with non-default values and/or raise an error if the object can't support a simpler view of its memory. 0 is returned on success and -1 on error. The following table gives possible values to the *flags* arguments. - +------------------------------+---------------------------------------------------+ - | Flag | Description | - +==============================+===================================================+ - | :cmacro:`PyBUF_SIMPLE` | This is the default flag state. The returned | - | | buffer may or may not have writable memory. The | - | | format of the data will be assumed to be unsigned | - | | bytes. This is a "stand-alone" flag constant. It | - | | never needs to be '|'d to the others. The exporter| - | | will raise an error if it cannot provide such a | - | | contiguous buffer of bytes. | - | | | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_WRITABLE` | The returned buffer must be writable. If it is | - | | not writable, then raise an error. | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_STRIDES` | This implies :cmacro:`PyBUF_ND`. The returned | - | | buffer must provide strides information (i.e. the | - | | strides cannot be NULL). This would be used when | - | | the consumer can handle strided, discontiguous | - | | arrays. Handling strides automatically assumes | - | | you can handle shape. The exporter can raise an | - | | error if a strided representation of the data is | - | | not possible (i.e. without the suboffsets). | - | | | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_ND` | The returned buffer must provide shape | - | | information. The memory will be assumed C-style | - | | contiguous (last dimension varies the | - | | fastest). The exporter may raise an error if it | - | | cannot provide this kind of contiguous buffer. If | - | | this is not given then shape will be *NULL*. | - | | | - | | | - | | | - +------------------------------+---------------------------------------------------+ - |:cmacro:`PyBUF_C_CONTIGUOUS` | These flags indicate that the contiguity returned | - |:cmacro:`PyBUF_F_CONTIGUOUS` | buffer must be respectively, C-contiguous (last | - |:cmacro:`PyBUF_ANY_CONTIGUOUS`| dimension varies the fastest), Fortran contiguous | - | | (first dimension varies the fastest) or either | - | | one. All of these flags imply | - | | :cmacro:`PyBUF_STRIDES` and guarantee that the | - | | strides buffer info structure will be filled in | - | | correctly. | - | | | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_INDIRECT` | This flag indicates the returned buffer must have | - | | suboffsets information (which can be NULL if no | - | | suboffsets are needed). This can be used when | - | | the consumer can handle indirect array | - | | referencing implied by these suboffsets. This | - | | implies :cmacro:`PyBUF_STRIDES`. | - | | | - | | | - | | | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_FORMAT` | The returned buffer must have true format | - | | information if this flag is provided. This would | - | | be used when the consumer is going to be checking | - | | for what 'kind' of data is actually stored. An | - | | exporter should always be able to provide this | - | | information if requested. If format is not | - | | explicitly requested then the format must be | - | | returned as *NULL* (which means ``'B'``, or | - | | unsigned bytes) | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_STRIDED` | This is equivalent to ``(PyBUF_STRIDES | | - | | PyBUF_WRITABLE)``. | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_STRIDED_RO` | This is equivalent to ``(PyBUF_STRIDES)``. | - | | | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_RECORDS` | This is equivalent to ``(PyBUF_STRIDES | | - | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_RECORDS_RO` | This is equivalent to ``(PyBUF_STRIDES | | - | | PyBUF_FORMAT)``. | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_FULL` | This is equivalent to ``(PyBUF_INDIRECT | | - | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_FULL_RO` | This is equivalent to ``(PyBUF_INDIRECT | | - | | PyBUF_FORMAT)``. | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_CONTIG` | This is equivalent to ``(PyBUF_ND | | - | | PyBUF_WRITABLE)``. | - +------------------------------+---------------------------------------------------+ - | :cmacro:`PyBUF_CONTIG_RO` | This is equivalent to ``(PyBUF_ND)``. | - | | | - +------------------------------+---------------------------------------------------+ - - -.. cfunction:: void PyBuffer_Release(Py_buffer *view) + +-------------------------------+---------------------------------------------------+ + | Flag | Description | + +===============================+===================================================+ + | :c:macro:`PyBUF_SIMPLE` | This is the default flag state. The returned | + | | buffer may or may not have writable memory. The | + | | format of the data will be assumed to be unsigned | + | | bytes. This is a "stand-alone" flag constant. It | + | | never needs to be '|'d to the others. The exporter| + | | will raise an error if it cannot provide such a | + | | contiguous buffer of bytes. | + | | | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_WRITABLE` | The returned buffer must be writable. If it is | + | | not writable, then raise an error. | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_STRIDES` | This implies :c:macro:`PyBUF_ND`. The returned | + | | buffer must provide strides information (i.e. the | + | | strides cannot be NULL). This would be used when | + | | the consumer can handle strided, discontiguous | + | | arrays. Handling strides automatically assumes | + | | you can handle shape. The exporter can raise an | + | | error if a strided representation of the data is | + | | not possible (i.e. without the suboffsets). | + | | | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_ND` | The returned buffer must provide shape | + | | information. The memory will be assumed C-style | + | | contiguous (last dimension varies the | + | | fastest). The exporter may raise an error if it | + | | cannot provide this kind of contiguous buffer. If | + | | this is not given then shape will be *NULL*. | + | | | + | | | + | | | + +-------------------------------+---------------------------------------------------+ + |:c:macro:`PyBUF_C_CONTIGUOUS` | These flags indicate that the contiguity returned | + |:c:macro:`PyBUF_F_CONTIGUOUS` | buffer must be respectively, C-contiguous (last | + |:c:macro:`PyBUF_ANY_CONTIGUOUS`| dimension varies the fastest), Fortran contiguous | + | | (first dimension varies the fastest) or either | + | | one. All of these flags imply | + | | :c:macro:`PyBUF_STRIDES` and guarantee that the | + | | strides buffer info structure will be filled in | + | | correctly. | + | | | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_INDIRECT` | This flag indicates the returned buffer must have | + | | suboffsets information (which can be NULL if no | + | | suboffsets are needed). This can be used when | + | | the consumer can handle indirect array | + | | referencing implied by these suboffsets. This | + | | implies :c:macro:`PyBUF_STRIDES`. | + | | | + | | | + | | | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_FORMAT` | The returned buffer must have true format | + | | information if this flag is provided. This would | + | | be used when the consumer is going to be checking | + | | for what 'kind' of data is actually stored. An | + | | exporter should always be able to provide this | + | | information if requested. If format is not | + | | explicitly requested then the format must be | + | | returned as *NULL* (which means ``'B'``, or | + | | unsigned bytes) | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_STRIDED` | This is equivalent to ``(PyBUF_STRIDES | | + | | PyBUF_WRITABLE)``. | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_STRIDED_RO` | This is equivalent to ``(PyBUF_STRIDES)``. | + | | | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_RECORDS` | This is equivalent to ``(PyBUF_STRIDES | | + | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_RECORDS_RO` | This is equivalent to ``(PyBUF_STRIDES | | + | | PyBUF_FORMAT)``. | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_FULL` | This is equivalent to ``(PyBUF_INDIRECT | | + | | PyBUF_FORMAT | PyBUF_WRITABLE)``. | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_FULL_RO` | This is equivalent to ``(PyBUF_INDIRECT | | + | | PyBUF_FORMAT)``. | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_CONTIG` | This is equivalent to ``(PyBUF_ND | | + | | PyBUF_WRITABLE)``. | + +-------------------------------+---------------------------------------------------+ + | :c:macro:`PyBUF_CONTIG_RO` | This is equivalent to ``(PyBUF_ND)``. | + | | | + +-------------------------------+---------------------------------------------------+ + + +.. c:function:: void PyBuffer_Release(Py_buffer *view) Release the buffer *view*. This should be called when the buffer is no longer being used as it may free memory from it. -.. cfunction:: Py_ssize_t PyBuffer_SizeFromFormat(const char *) +.. c:function:: Py_ssize_t PyBuffer_SizeFromFormat(const char *) - Return the implied :cdata:`~Py_buffer.itemsize` from the struct-stype - :cdata:`~Py_buffer.format`. + Return the implied :c:data:`~Py_buffer.itemsize` from the struct-stype + :c:data:`~Py_buffer.format`. -.. cfunction:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran) +.. c:function:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran) Return 1 if the memory defined by the *view* is C-style (*fortran* is ``'C'``) or Fortran-style (*fortran* is ``'F'``) contiguous or either one (*fortran* is ``'A'``). Return 0 otherwise. -.. cfunction:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran) +.. c:function:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran) Fill the *strides* array with byte-strides of a contiguous (C-style if *fortran* is ``'C'`` or Fortran-style if *fortran* is ``'F'``) array of the given shape with the given number of bytes per element. -.. cfunction:: int PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, int readonly, int infoflags) +.. c:function:: int PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, int readonly, int infoflags) Fill in a buffer-info structure, *view*, correctly for an exporter that can only share a contiguous chunk of memory of "unsigned bytes" of the given @@ -295,13 +295,13 @@ MemoryView objects A :class:`memoryview` object exposes the new C level buffer interface as a Python object which can then be passed around like any other object. -.. cfunction:: PyObject *PyMemoryView_FromObject(PyObject *obj) +.. c:function:: PyObject *PyMemoryView_FromObject(PyObject *obj) Create a memoryview object from an object that defines the new buffer interface. -.. cfunction:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view) +.. c:function:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view) Create a memoryview object wrapping the given buffer-info structure *view*. The memoryview object then owns the buffer, which means you shouldn't @@ -309,7 +309,7 @@ Python object which can then be passed around like any other object. memoryview object. -.. cfunction:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order) +.. c:function:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order) Create a memoryview object to a contiguous chunk of memory (in either 'C' or 'F'ortran *order*) from an object that defines the buffer @@ -318,13 +318,13 @@ Python object which can then be passed around like any other object. new bytes object. -.. cfunction:: int PyMemoryView_Check(PyObject *obj) +.. c:function:: int PyMemoryView_Check(PyObject *obj) Return true if the object *obj* is a memoryview object. It is not currently allowed to create subclasses of :class:`memoryview`. -.. cfunction:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj) +.. c:function:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj) Return a pointer to the buffer-info structure wrapped by the given object. The object **must** be a memoryview instance; this macro doesn't @@ -337,7 +337,7 @@ Old-style buffer objects .. index:: single: PyBufferProcs More information on the old buffer interface is provided in the section -:ref:`buffer-structs`, under the description for :ctype:`PyBufferProcs`. +:ref:`buffer-structs`, under the description for :c:type:`PyBufferProcs`. A "buffer object" is defined in the :file:`bufferobject.h` header (included by :file:`Python.h`). These objects look very similar to string objects at the @@ -356,36 +356,36 @@ system library, or it could be used to pass around structured data in its native, in-memory format. -.. ctype:: PyBufferObject +.. c:type:: PyBufferObject - This subtype of :ctype:`PyObject` represents a buffer object. + This subtype of :c:type:`PyObject` represents a buffer object. -.. cvar:: PyTypeObject PyBuffer_Type +.. c:var:: PyTypeObject PyBuffer_Type .. index:: single: BufferType (in module types) - The instance of :ctype:`PyTypeObject` which represents the Python buffer type; + The instance of :c:type:`PyTypeObject` which represents the Python buffer type; it is the same object as ``buffer`` and ``types.BufferType`` in the Python layer. . -.. cvar:: int Py_END_OF_BUFFER +.. c:var:: int Py_END_OF_BUFFER This constant may be passed as the *size* parameter to - :cfunc:`PyBuffer_FromObject` or :cfunc:`PyBuffer_FromReadWriteObject`. It - indicates that the new :ctype:`PyBufferObject` should refer to *base* + :c:func:`PyBuffer_FromObject` or :c:func:`PyBuffer_FromReadWriteObject`. It + indicates that the new :c:type:`PyBufferObject` should refer to *base* object from the specified *offset* to the end of its exported buffer. Using this enables the caller to avoid querying the *base* object for its length. -.. cfunction:: int PyBuffer_Check(PyObject *p) +.. c:function:: int PyBuffer_Check(PyObject *p) - Return true if the argument has type :cdata:`PyBuffer_Type`. + Return true if the argument has type :c:data:`PyBuffer_Type`. -.. cfunction:: PyObject* PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size) +.. c:function:: PyObject* PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size) Return a new read-only buffer object. This raises :exc:`TypeError` if *base* doesn't support the read-only buffer protocol or doesn't provide @@ -397,24 +397,24 @@ native, in-memory format. length of the *base* object's exported buffer data. .. versionchanged:: 2.5 - This function used an :ctype:`int` type for *offset* and *size*. This + This function used an :c:type:`int` type for *offset* and *size*. This might require changes in your code for properly supporting 64-bit systems. -.. cfunction:: PyObject* PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size) +.. c:function:: PyObject* PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size) Return a new writable buffer object. Parameters and exceptions are similar - to those for :cfunc:`PyBuffer_FromObject`. If the *base* object does not + to those for :c:func:`PyBuffer_FromObject`. If the *base* object does not export the writeable buffer protocol, then :exc:`TypeError` is raised. .. versionchanged:: 2.5 - This function used an :ctype:`int` type for *offset* and *size*. This + This function used an :c:type:`int` type for *offset* and *size*. This might require changes in your code for properly supporting 64-bit systems. -.. cfunction:: PyObject* PyBuffer_FromMemory(void *ptr, Py_ssize_t size) +.. c:function:: PyObject* PyBuffer_FromMemory(void *ptr, Py_ssize_t size) Return a new read-only buffer object that reads from a specified location in memory, with a specified size. The caller is responsible for ensuring @@ -424,27 +424,27 @@ native, in-memory format. *size* parameter; :exc:`ValueError` will be raised in that case. .. versionchanged:: 2.5 - This function used an :ctype:`int` type for *size*. This might require + This function used an :c:type:`int` type for *size*. This might require changes in your code for properly supporting 64-bit systems. -.. cfunction:: PyObject* PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size) +.. c:function:: PyObject* PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size) - Similar to :cfunc:`PyBuffer_FromMemory`, but the returned buffer is + Similar to :c:func:`PyBuffer_FromMemory`, but the returned buffer is writable. .. versionchanged:: 2.5 - This function used an :ctype:`int` type for *size*. This might require + This function used an :c:type:`int` type for *size*. This might require changes in your code for properly supporting 64-bit systems. -.. cfunction:: PyObject* PyBuffer_New(Py_ssize_t size) +.. c:function:: PyObject* PyBuffer_New(Py_ssize_t size) Return a new writable buffer object that maintains its own memory buffer of *size* bytes. :exc:`ValueError` is returned if *size* is not zero or positive. Note that the memory buffer (as returned by - :cfunc:`PyObject_AsWriteBuffer`) is not specifically aligned. + :c:func:`PyObject_AsWriteBuffer`) is not specifically aligned. .. versionchanged:: 2.5 - This function used an :ctype:`int` type for *size*. This might require + This function used an :c:type:`int` type for *size*. This might require changes in your code for properly supporting 64-bit systems. diff --git a/Doc/c-api/bytearray.rst b/Doc/c-api/bytearray.rst index a605091..858c8db 100644 --- a/Doc/c-api/bytearray.rst +++ b/Doc/c-api/bytearray.rst @@ -10,26 +10,26 @@ Byte Array Objects .. versionadded:: 2.6 -.. ctype:: PyByteArrayObject +.. c:type:: PyByteArrayObject - This subtype of :ctype:`PyObject` represents a Python bytearray object. + This subtype of :c:type:`PyObject` represents a Python bytearray object. -.. cvar:: PyTypeObject PyByteArray_Type +.. c:var:: PyTypeObject PyByteArray_Type - This instance of :ctype:`PyTypeObject` represents the Python bytearray type; + This instance of :c:type:`PyTypeObject` represents the Python bytearray type; it is the same object as ``bytearray`` in the Python layer. Type check macros ^^^^^^^^^^^^^^^^^ -.. cfunction:: int PyByteArray_Check(PyObject *o) +.. c:function:: int PyByteArray_Check(PyObject *o) Return true if the object *o* is a bytearray object or an instance of a subtype of the bytearray type. -.. cfunction:: int PyByteArray_CheckExact(PyObject *o) +.. c:function:: int PyByteArray_CheckExact(PyObject *o) Return true if the object *o* is a bytearray object, but not an instance of a subtype of the bytearray type. @@ -38,7 +38,7 @@ Type check macros Direct API functions ^^^^^^^^^^^^^^^^^^^^ -.. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o) +.. c:function:: PyObject* PyByteArray_FromObject(PyObject *o) Return a new bytearray object from any object, *o*, that implements the buffer protocol. @@ -46,29 +46,29 @@ Direct API functions .. XXX expand about the buffer protocol, at least somewhere -.. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len) +.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len) Create a new bytearray object from *string* and its length, *len*. On failure, *NULL* is returned. -.. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b) +.. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b) Concat bytearrays *a* and *b* and return a new bytearray with the result. -.. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray) +.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray) Return the size of *bytearray* after checking for a *NULL* pointer. -.. cfunction:: char* PyByteArray_AsString(PyObject *bytearray) +.. c:function:: char* PyByteArray_AsString(PyObject *bytearray) Return the contents of *bytearray* as a char array after checking for a *NULL* pointer. -.. cfunction:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len) +.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len) Resize the internal buffer of *bytearray* to *len*. @@ -77,11 +77,11 @@ Macros These macros trade safety for speed and they don't check pointers. -.. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray) +.. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray) - Macro version of :cfunc:`PyByteArray_AsString`. + Macro version of :c:func:`PyByteArray_AsString`. -.. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray) +.. c:function:: Py_ssize_t PyB