@@ -475,6 +475,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
475
475
This is the equivalent of the Python statement: del o[key].
476
476
*/
477
477
478
+ /* old buffer API
479
+ FIXME: usage of these should all be replaced in Python itself
480
+ but for backwards compatibility we will implement them.
481
+ Their usage without a corresponding "unlock" mechansim
482
+ may create issues (but they would already be there). */
483
+
478
484
PyAPI_FUNC (int ) PyObject_AsCharBuffer(PyObject *obj,
479
485
const char **buffer,
480
486
Py_ssize_t *buffer_len);
@@ -527,6 +533,110 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
527
533
an exception set.
528
534
*/
529
535
536
+ /* new buffer API */
537
+
538
+ #define PyObject_CheckBuffer (obj ) \
539
+ (((obj)->ob_type->tp_as_buffer != NULL ) && \
540
+ ((obj)->ob_type->tp_as_buffer->bf_getbuffer != NULL ))
541
+
542
+ /* Return 1 if the getbuffer function is available, otherwise
543
+ return 0 */
544
+
545
+ PyAPI_FUNC (int ) PyObject_GetBuffer(PyObject *obj, PyBuffer *view,
546
+ int flags);
547
+
548
+ /* This is a C-API version of the getbuffer function call. It checks
549
+ to make sure object has the required function pointer and issues the
550
+ call. Returns -1 and raises an error on failure and returns 0 on
551
+ success
552
+ */
553
+
554
+
555
+ PyAPI_FUNC (void ) PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view);
556
+
557
+
558
+ /* C-API version of the releasebuffer function call. It
559
+ checks to make sure the object has the required function
560
+ pointer and issues the call. The obj must have the buffer
561
+ interface or this function will cause a segfault (i.e. it
562
+ is assumed to be called only after a corresponding
563
+ getbuffer which already verified the existence of the
564
+ tp_as_buffer pointer).
565
+
566
+ Returns 0 on success and -1 (with an error raised) on
567
+ failure. This function always succeeds (as a NO-OP) if
568
+ there is no releasebuffer function for the object so that
569
+ it can always be called when the consumer is done with the
570
+ buffer
571
+ */
572
+
573
+ PyAPI_FUNC (void *) PyBuffer_GetPointer(PyBuffer *view, Py_ssize_t *indices);
574
+
575
+ /* Get the memory area pointed to by the indices for the buffer given.
576
+ Note that view->ndim is the assumed size of indices
577
+ */
578
+
579
+ PyAPI_FUNC (int ) PyBuffer_SizeFromFormat(const char *);
580
+
581
+ /* Return the implied itemsize of the data-format area from a
582
+ struct-style description */
583
+
584
+
585
+
586
+ PyAPI_FUNC (int ) PyBuffer_ToContiguous(void *buf, PyBuffer *view,
587
+ Py_ssize_t len, char fort);
588
+
589
+ PyAPI_FUNC (int ) PyBuffer_FromContiguous(PyBuffer *view, void *buf,
590
+ Py_ssize_t len, char fort);
591
+
592
+
593
+ /* Copy len bytes of data from the contiguous chunk of memory
594
+ pointed to by buf into the buffer exported by obj. Return
595
+ 0 on success and return -1 and raise a PyBuffer_Error on
596
+ error (i.e. the object does not have a buffer interface or
597
+ it is not working).
598
+
599
+ If fortran is 'F', then if the object is multi-dimensional,
600
+ then the data will be copied into the array in
601
+ Fortran-style (first dimension varies the fastest). If
602
+ fortran is 'C', then the data will be copied into the array
603
+ in C-style (last dimension varies the fastest). If fortran
604
+ is 'A', then it does not matter and the copy will be made
605
+ in whatever way is more efficient.
606
+
607
+ */
608
+
609
+ PyAPI_FUNC (int ) PyObject_CopyData(PyObject *dest, PyObject *src);
610
+
611
+ /* Copy the data from the src buffer to the buffer of destination
612
+ */
613
+
614
+ PyAPI_FUNC (int ) PyBuffer_IsContiguous(PyBuffer *view, char fortran);
615
+
616
+
617
+ PyAPI_FUNC (void ) PyBuffer_FillContiguousStrides(int ndims,
618
+ Py_ssize_t *shape,
619
+ Py_ssize_t *strides,
620
+ int itemsize,
621
+ char fort);
622
+
623
+ /* Fill the strides array with byte-strides of a contiguous
624
+ (Fortran-style if fortran is 'F' or C-style otherwise)
625
+ array of the given shape with the given number of bytes
626
+ per element.
627
+ */
628
+
629
+ PyAPI_FUNC (int ) PyBuffer_FillInfo(PyBuffer *view, void *buf,
630
+ Py_ssize_t len, int readonly,
631
+ int flags);
632
+
633
+ /* Fills in a buffer-info structure correctly for an exporter
634
+ that can only share a contiguous chunk of memory of
635
+ "unsigned bytes" of the given length. Returns 0 on success
636
+ and -1 (with raising an error) on error.
637
+ */
638
+
639
+
530
640
/* Iterators */
531
641
532
642
PyAPI_FUNC (PyObject *) PyObject_GetIter(PyObject *);
0 commit comments