Skip to content

Commit 1db361b

Browse files
committed
[GR-9984] Support buffer protocol for arbitrary Python sequences.
PullRequest: graalpython/74
2 parents f42a14f + 88e0fa6 commit 1db361b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1980
-510
lines changed

graalpython/com.oracle.graal.python.cext/include/Python.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ extern int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, c
179179
#ifdef PyArg_ParseTuple
180180
#undef PyArg_ParseTuple
181181
#endif
182-
#define PyArg_ParseTuple(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, (char*[]) { NULL }, ##__VA_ARGS__)
182+
#define PyArg_ParseTuple(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, NULL, ##__VA_ARGS__)
183183

184184
#ifdef _PyArg_ParseTupleAndKeywordsFast
185185
#undef _PyArg_ParseTupleAndKeywordsFast
@@ -189,7 +189,7 @@ extern int PyTruffle_Arg_ParseTupleAndKeywords(PyObject *argv, PyObject *kwds, c
189189
#ifdef PyArg_Parse
190190
#undef PyArg_Parse
191191
#endif
192-
#define PyArg_Parse(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, (char*[]) { NULL }, __VA_ARGS__)
192+
#define PyArg_Parse(ARGV, FORMAT, ...) PyArg_ParseTupleAndKeywords(ARGV, PyDict_New(), FORMAT, NULL, __VA_ARGS__)
193193

194194
extern PyObject * PyTruffle_Unicode_FromFormat(const char *fmt, int s, void* v0, void* v1, void* v2, void* v3, void* v4, void* v5, void* v6, void* v7, void* v8, void* v9, void* v10, void* v11, void* v12, void* v13, void* v14, void* v15, void* v16, void* v17, void* v18, void* v19);
195195
#define PyTruffle_Unicode_FromFormat_0(F1) PyTruffle_Unicode_FromFormat(F1, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

graalpython/com.oracle.graal.python.cext/src/abstract.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,66 @@ PyObject * PyMapping_GetItemString(PyObject *o, const char *key) {
263263
return to_sulong(result);
264264
}
265265

266+
// taken from CPython "Objects/abstract.c"
267+
int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
268+
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
269+
270+
if (pb == NULL || pb->bf_getbuffer == NULL) {
271+
PyErr_Format(PyExc_TypeError,
272+
"a bytes-like object is required, not '%.100s'",
273+
Py_TYPE(obj)->tp_name);
274+
return -1;
275+
}
276+
return (*pb->bf_getbuffer)(obj, view, flags);
277+
}
278+
279+
// taken from CPython "Objects/abstract.c"
280+
void PyBuffer_Release(Py_buffer *view) {
281+
PyObject *obj = view->obj;
282+
PyBufferProcs *pb;
283+
if (obj == NULL)
284+
return;
285+
pb = Py_TYPE(obj)->tp_as_buffer;
286+
if (pb && pb->bf_releasebuffer)
287+
pb->bf_releasebuffer(obj, view);
288+
view->obj = NULL;
289+
Py_DECREF(obj);
290+
}
291+
292+
// taken from CPython "Objects/abstract.c"
293+
/* we do this in native code since we need to fill in the values in a given 'Py_buffer' struct */
294+
int PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, int readonly, int flags) {
295+
if (view == NULL) {
296+
PyErr_SetString(PyExc_BufferError,
297+
"PyBuffer_FillInfo: view==NULL argument is obsolete");
298+
return -1;
299+
}
300+
301+
if (((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) &&
302+
(readonly == 1)) {
303+
PyErr_SetString(PyExc_BufferError,
304+
"Object is not writable.");
305+
return -1;
306+
}
307+
308+
view->obj = obj;
309+
if (obj)
310+
Py_INCREF(obj);
311+
view->buf = buf;
312+
view->len = len;
313+
view->readonly = readonly;
314+
view->itemsize = 1;
315+
view->format = NULL;
316+
if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT)
317+
view->format = "B";
318+
view->ndim = 1;
319+
view->shape = NULL;
320+
if ((flags & PyBUF_ND) == PyBUF_ND)
321+
view->shape = &(view->len);
322+
view->strides = NULL;
323+
if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES)
324+
view->strides = &(view->itemsize);
325+
view->suboffsets = NULL;
326+
view->internal = NULL;
327+
return 0;
328+
}

graalpython/com.oracle.graal.python.cext/src/boolobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#include <stdarg.h>
4242

43-
PyTypeObject PyBool_Type = PY_TRUFFLE_TYPE("bool", &PyType_Type, Py_TPFLAGS_DEFAULT);
43+
PyTypeObject PyBool_Type = PY_TRUFFLE_TYPE("bool", &PyType_Type, Py_TPFLAGS_DEFAULT, sizeof(struct _longobject));
4444

4545
// taken from CPython "Python/Objects/boolobject.c"
4646
PyObject *PyBool_FromLong(long ok) {

graalpython/com.oracle.graal.python.cext/src/bytearrayobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@
3838
*/
3939
#include "capi.h"
4040

41-
PyTypeObject PyByteArray_Type = PY_TRUFFLE_TYPE("bytearray", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
41+
PyTypeObject PyByteArray_Type = PY_TRUFFLE_TYPE("bytearray", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, sizeof(PyByteArrayObject));
4242
char _PyByteArray_empty_string[] = "";

graalpython/com.oracle.graal.python.cext/src/bytesobject.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@
3939
#include "capi.h"
4040

4141
#include <stdarg.h>
42+
#include <stddef.h>
4243

43-
PyTypeObject PyBytes_Type = PY_TRUFFLE_TYPE("bytes", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_BYTES_SUBCLASS);
44+
// taken from CPython "Objects/bytesobject.c"
45+
#define PyBytesObject_SIZE (offsetof(PyBytesObject, ob_sval) + 1)
46+
47+
PyTypeObject PyBytes_Type = PY_TRUFFLE_TYPE("bytes", &PyType_Type, Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_BYTES_SUBCLASS, PyBytesObject_SIZE);
4448

4549
PyObject* PyBytes_FromStringAndSize(const char* str, Py_ssize_t sz) {
4650
setlocale(LC_ALL, NULL);
@@ -269,3 +273,7 @@ void PyBytes_ConcatAndDel(PyObject **bytes, PyObject *newpart) {
269273
Py_ssize_t PyBytes_Size(PyObject *bytes) {
270274
return truffle_invoke_i(PY_TRUFFLE_CEXT, "PyBytes_Size", to_java(bytes));
271275
}
276+
277+
int bytes_buffer_getbuffer(PyBytesObject *self, Py_buffer *view, int flags) {
278+
return PyBuffer_FillInfo(view, (PyObject*)self, (void *)self->ob_sval, Py_SIZE(self), 1, flags);
279+
}

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ static void initialize_type_structure(PyTypeObject* structure, const char* typna
4848
truffle_invoke(PY_TRUFFLE_CEXT, "PyTruffle_Set_Ptr", ptype, nativePointer);
4949

5050
unsigned long original_flags = structure->tp_flags;
51+
Py_ssize_t basicsize = structure->tp_basicsize;
5152
PyTypeObject* type_handle = truffle_assign_managed(structure, polyglot_as__typeobject(ptype));
5253
// write flags as specified in the dummy to the PythonClass object
5354
type_handle->tp_flags = original_flags | Py_TPFLAGS_READY;
55+
type_handle->tp_basicsize = basicsize;
5456
}
5557

5658
static void initialize_globals() {
@@ -77,6 +79,12 @@ static void initialize_globals() {
7779
truffle_assign_managed(&marker_struct, jerrormarker);
7880
}
7981

82+
static void initialize_bufferprocs() {
83+
polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_SetBufferProcs", to_java((PyObject*)&PyBytes_Type), (getbufferproc)bytes_buffer_getbuffer, (releasebufferproc)NULL);
84+
polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_SetBufferProcs", to_java((PyObject*)&PyByteArray_Type), (getbufferproc)NULL, (releasebufferproc)NULL);
85+
polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_SetBufferProcs", to_java((PyObject*)&PyBuffer_Type), (getbufferproc)bufferdecorator_getbuffer, (releasebufferproc)NULL);
86+
}
87+
8088
__attribute__((constructor))
8189
static void initialize_capi() {
8290
// initialize base types
@@ -104,12 +112,14 @@ static void initialize_capi() {
104112
initialize_type_structure(&PyFrozenSet_Type, "frozenset");
105113
initialize_type_structure(&PySet_Type, "set");
106114
initialize_type_structure(&PyEllipsis_Type, "ellipsis");
115+
initialize_type_structure(&PyBuffer_Type, "buffer");
107116

108117
// initialize global variables like '_Py_NoneStruct', etc.
109118
initialize_globals();
110119

111120
initialize_exceptions();
112121
initialize_hashes();
122+
initialize_bufferprocs();
113123
}
114124

115125
void* native_to_java(PyObject* obj) {
@@ -148,7 +158,9 @@ void* to_java_type(PyTypeObject* cls) {
148158

149159
__attribute__((always_inline))
150160
static inline PyObject* PyTruffle_Explicit_Cast(PyObject* cobj, unsigned long flags) {
151-
if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_TUPLE_SUBCLASS)) {
161+
if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_TYPE_SUBCLASS)) {
162+
return (PyObject*)polyglot_as__typeobject(cobj);
163+
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_TUPLE_SUBCLASS)) {
152164
return (PyObject*)polyglot_as_PyTupleObject(cobj);
153165
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_LIST_SUBCLASS)) {
154166
return (PyObject*)polyglot_as_PyListObject(cobj);
@@ -158,13 +170,17 @@ static inline PyObject* PyTruffle_Explicit_Cast(PyObject* cobj, unsigned long fl
158170
return (PyObject*)polyglot_as_PyUnicodeObject(cobj);
159171
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_BYTES_SUBCLASS)) {
160172
return (PyObject*)polyglot_as_PyBytesObject(cobj);
173+
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_LONG_SUBCLASS)) {
174+
return (PyObject*)polyglot_as__longobject(cobj);
175+
} else if (PyTruffle_FastSubclass(flags, Py_TPFLAGS_BASE_EXC_SUBCLASS)) {
176+
return (PyObject*)polyglot_as_PyBaseExceptionObject(cobj);
161177
}
162178
return (PyObject*)polyglot_as_PyVarObject(cobj);
163179
}
164180

165181

166182
__attribute__((always_inline))
167-
static inline PyObject* _explicit_cast(PyObject* cobj) {
183+
inline PyObject* explicit_cast(PyObject* cobj) {
168184
if(polyglot_is_value(cobj)) {
169185
unsigned long flags = polyglot_as_i64(polyglot_invoke(PY_TRUFFLE_CEXT, "PyTruffle_GetTpFlags", cobj));
170186
return PyTruffle_Explicit_Cast(cobj, flags);
@@ -173,7 +189,7 @@ static inline PyObject* _explicit_cast(PyObject* cobj) {
173189
}
174190

175191
PyObject* to_sulong(void *o) {
176-
return _explicit_cast(truffle_invoke(PY_TRUFFLE_CEXT, "to_sulong", o));
192+
return explicit_cast(truffle_invoke(PY_TRUFFLE_CEXT, "to_sulong", o));
177193
}
178194

179195
void* get_ob_type(PyObject* obj) {
@@ -209,6 +225,12 @@ PyTypeObject* PyObjectHandle_ForJavaType(void* jobj) {
209225
return jobj;
210226
}
211227

228+
/** to be used from Java code only; creates the deref handle for a sequence wrapper */
229+
void* NativeHandle_ForArray(void* jobj, ssize_t element_size) {
230+
// TODO do polyglot typecast depending on element_size
231+
return truffle_deref_handle_for_managed(jobj);
232+
}
233+
212234
const char* PyTruffle_StringToCstr(void* jlString) {
213235
return truffle_string_to_cstr(jlString);
214236
}
@@ -437,78 +459,101 @@ typedef PyObject* (*f20)(PyObject*, PyObject*, PyObject*, PyObject*, PyObject*,
437459

438460
#define _PICK_FUN_CAST(DUMMY, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, NAME, ...) NAME
439461
#define _CALL_ARITY(FUN, ...) ( (_PICK_FUN_CAST(NULL, ##__VA_ARGS__, f20, f19, f18, f17, f16, f15, f14, f13, f12, f11, f10, f9, f8, f7, f6, f5, f4, f3, f2, f1, f0))(FUN))(__VA_ARGS__)
440-
#define ARG(__n) _explicit_cast((PyObject*)polyglot_get_arg((__n)))
462+
#define ARG(__n) explicit_cast((PyObject*)polyglot_get_arg((__n)))
441463

442-
PyObject *wrap_direct(PyCFunction fun, ...) {
464+
void* wrap_direct(PyCFunction fun, ...) {
443465
PyObject *res = NULL;
444466
switch(polyglot_get_arg_count()-1) {
445467
case 0:
446-
return _CALL_ARITY(fun);
468+
res = _CALL_ARITY(fun);
469+
break;
447470
case 1:
448-
return _CALL_ARITY(fun, ARG(1));
471+
res = _CALL_ARITY(fun, ARG(1));
472+
break;
449473
case 2:
450-
return _CALL_ARITY(fun, ARG(1), ARG(2));
474+
res = _CALL_ARITY(fun, ARG(1), ARG(2));
475+
break;
451476
case 3:
452-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3));
477+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3));
478+
break;
453479
case 4:
454-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4));
480+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4));
481+
break;
455482
case 5:
456-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5));
483+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5));
484+
break;
457485
case 6:
458-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6));
486+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6));
487+
break;
459488
case 7:
460-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7));
489+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7));
490+
break;
461491
case 8:
462-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8));
492+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8));
493+
break;
463494
case 9:
464-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9));
495+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9));
496+
break;
465497
case 10:
466-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10));
498+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10));
499+
break;
467500
case 11:
468-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11));
501+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11));
502+
break;
469503
case 12:
470-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12));
504+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12));
505+
break;
471506
case 13:
472-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13));
507+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13));
508+
break;
473509
case 14:
474-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14));
510+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14));
511+
break;
475512
case 15:
476-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15));
513+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15));
514+
break;
477515
case 16:
478-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16));
516+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16));
517+
break;
479518
case 17:
480-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17));
519+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17));
520+
break;
481521
case 18:
482-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17), ARG(18));
522+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17), ARG(18));
523+
break;
483524
case 19:
484-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17), ARG(18), ARG(19));
525+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17), ARG(18), ARG(19));
526+
break;
485527
case 20:
486-
return _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17), ARG(18), ARG(19), ARG(20));
528+
res = _CALL_ARITY(fun, ARG(1), ARG(2), ARG(3), ARG(4), ARG(5), ARG(6), ARG(7), ARG(8), ARG(9), ARG(10), ARG(11), ARG(12), ARG(13), ARG(14), ARG(15), ARG(16), ARG(17), ARG(18), ARG(19), ARG(20));
529+
break;
530+
default:
531+
_PyErr_BadInternalCall(__FILE__, __LINE__);
532+
res = NULL;
487533
}
488-
_PyErr_BadInternalCall(__FILE__, __LINE__);
489-
return NULL;
534+
return native_to_java(res);
490535
}
491536

492-
PyObject *wrap_varargs(PyCFunction fun, PyObject *module, PyObject *varargs) {
493-
return fun(module, _explicit_cast(varargs));
537+
void* wrap_varargs(PyCFunction fun, PyObject *module, PyObject *varargs) {
538+
return native_to_java(fun(explicit_cast(module), explicit_cast(varargs)));
494539
}
495540

496-
PyObject *wrap_keywords(PyCFunctionWithKeywords fun, PyObject *module, PyObject *varargs, PyObject *kwargs) {
497-
return fun(module, _explicit_cast(varargs), _explicit_cast(kwargs));
541+
void* wrap_keywords(PyCFunctionWithKeywords fun, PyObject *module, PyObject *varargs, PyObject *kwargs) {
542+
return native_to_java(fun(explicit_cast(module), explicit_cast(varargs), explicit_cast(kwargs)));
498543
}
499544

500-
PyObject *wrap_noargs(PyCFunction fun, PyObject *module, PyObject *pnone) {
501-
return fun(module, pnone);
545+
void* wrap_noargs(PyCFunction fun, PyObject *module, PyObject *pnone) {
546+
return native_to_java(fun(explicit_cast(module), explicit_cast(pnone)));
502547
}
503548

504-
PyObject *wrap_fastcall(_PyCFunctionFast fun, PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) {
549+
void* wrap_fastcall(_PyCFunctionFast fun, PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) {
505550
Py_ssize_t i;
506551
for (i=0; i < nargs; i++) {
507-
args[i] = _explicit_cast(args[i]);
552+
args[i] = explicit_cast(args[i]);
508553
}
509-
return fun(self, args, nargs, _explicit_cast(kwnames));
554+
return native_to_java(fun(explicit_cast(self), args, nargs, explicit_cast(kwnames)));
510555
}
511556

512-
PyObject *wrap_unsupported(void *fun, ...) {
557+
void* wrap_unsupported(void *fun, ...) {
513558
return NULL;
514559
}

0 commit comments

Comments
 (0)