PythonMonkey   v1.0.0 (dev)
Loading...
Searching...
No Matches
BufferType.hh
Go to the documentation of this file.
1
11#ifndef PythonMonkey_BufferType_
12#define PythonMonkey_BufferType_
13
14#include <jsapi.h>
15#include <js/ScalarType.h>
16
17#include <Python.h>
18
19struct BufferType {
20public:
29 static PyObject *getPyObject(JSContext *cx, JS::HandleObject bufObj);
30
38 static JSObject *toJsTypedArray(JSContext *cx, PyObject *pyObject);
39
43 static bool isSupportedJsTypes(JSObject *obj);
44
45protected:
46 static PyObject *fromJsTypedArray(JSContext *cx, JS::HandleObject typedArray);
47 static PyObject *fromJsArrayBuffer(JSContext *cx, JS::HandleObject arrayBuffer);
48
49private:
50 static void _releasePyBuffer(Py_buffer *bufView);
51 static void _releasePyBuffer(void *, void *bufView); // JS::BufferContentsFreeFunc callback for JS::NewExternalArrayBuffer
52
53 static JS::Scalar::Type _getPyBufferType(Py_buffer *bufView);
54 static const char *_toPyBufferFormatCode(JS::Scalar::Type subtype);
55
61 static JSObject *_newTypedArrayWithBuffer(JSContext *cx, JS::Scalar::Type subtype, JS::HandleObject arrayBuffer);
62};
63
64#endif
Definition BufferType.hh:19
static bool isSupportedJsTypes(JSObject *obj)
Definition BufferType.cc:59
static PyObject * fromJsArrayBuffer(JSContext *cx, JS::HandleObject arrayBuffer)
Definition BufferType.cc:111
static JSObject * toJsTypedArray(JSContext *cx, PyObject *pyObject)
Convert a Python object that provides the buffer interface to JS TypedArray. The subtype (Uint8Array,...
Definition BufferType.cc:137
static PyObject * getPyObject(JSContext *cx, JS::HandleObject bufObj)
Construct a new BufferType object from a JS TypedArray or ArrayBuffer, as a Python memoryview object.
Definition BufferType.cc:63
static PyObject * fromJsTypedArray(JSContext *cx, JS::HandleObject typedArray)
Definition BufferType.cc:79