Pickle buffer objects

在 3.8 版被加入.

Apickle.PickleBuffer object wraps abuffer-providing object for out-of-band data transfer with thepickle module.

PyTypeObjectPyPickleBuffer_Type

This instance ofPyTypeObject represents the Python pickle buffer type.This is the same object aspickle.PickleBuffer in the Python layer.

intPyPickleBuffer_Check(PyObject*op)

Return true ifop is a pickle buffer instance.This function always succeeds.

PyObject*PyPickleBuffer_FromObject(PyObject*obj)

Create a pickle buffer from the objectobj.

This function will fail ifobj doesn't support thebuffer protocol.

On success, return a new pickle buffer instance.On failure, set an exception and returnNULL.

Analogous to callingpickle.PickleBuffer withobj in Python.

constPy_buffer*PyPickleBuffer_GetBuffer(PyObject*picklebuf)

Get a pointer to the underlyingPy_buffer that the pickle buffer wraps.

The returned pointer is valid as long aspicklebuf is alive and has not beenreleased. The caller must not modify or free the returnedPy_buffer.If the pickle buffer has been released, raiseValueError.

On success, return a pointer to the buffer view.On failure, set an exception and returnNULL.

intPyPickleBuffer_Release(PyObject*picklebuf)

Release the underlying buffer held by the pickle buffer.

Return0 on success. On failure, set an exception and return-1.

Analogous to callingpickle.PickleBuffer.release() in Python.