Skip to content

Commit c3c1e62

Browse files
committed
Implement 'y*' conversion.
1 parent f79367d commit c3c1e62

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@
4242

4343
#include <stdio.h>
4444

45+
static int getbuffer(PyObject *arg, Py_buffer *view, const char **errmsg) {
46+
if (PyObject_GetBuffer(arg, view, PyBUF_SIMPLE) != 0) {
47+
*errmsg = "bytes-like object";
48+
return -1;
49+
}
50+
// if (!PyBuffer_IsContiguous(view, 'C')) {
51+
// PyBuffer_Release(view);
52+
// *errmsg = "contiguous buffer";
53+
// return -1;
54+
// }
55+
return 0;
56+
}
57+
4558
typedef struct _positional_argstack {
4659
PyObject* argv;
4760
int argnum;
@@ -89,8 +102,14 @@ UPCALL_ID(__bool__);
89102
case 'y': \
90103
arg = PyTruffle_GetArg(v, kwds, kwdnames, rest_keywords_only); \
91104
if (format[format_idx + 1] == '*') { \
105+
void** p = (void**)PyTruffle_ArgN(output_idx); \
106+
const char* buf; \
92107
format_idx++; /* skip over '*' */ \
93-
PyErr_Format(PyExc_TypeError, "%c* not supported", c); \
108+
if (getbuffer(arg, (Py_buffer*)p, &buf) < 0) { \
109+
PyErr_Format(PyExc_TypeError, "expected bytes, got %R", Py_TYPE(arg)); \
110+
__return_code__; \
111+
return 0; \
112+
} \
94113
__return_code__; \
95114
return 0; \
96115
} else if (arg == Py_None) { \

0 commit comments

Comments
 (0)