Skip to content

Commit 6c17415

Browse files
committed
Revert "allocate the argparsing stacks managed"
This reverts commit d8a90aa.
1 parent d8a90aa commit 6c17415

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
typedef struct _positional_argstack {
4646
PyObject* argv;
47-
long argnum;
47+
int argnum;
4848
struct _positional_argstack* prev;
4949
} positional_argstack;
5050

@@ -93,10 +93,9 @@ int _PyArg_ParseTupleAndKeywords_SizeT(PyObject *argv, PyObject *kwds, const cha
9393
unsigned char rest_optional = 0;
9494
unsigned char rest_keywords_only = 0;
9595

96-
positional_argstack *v = (positional_argstack*)truffle_managed_malloc(sizeof(positional_argstack));
96+
positional_argstack *v = (positional_argstack*)calloc(1, sizeof(positional_argstack));
9797
v->argv = argv;
9898
v->argnum = 0;
99-
v->prev = NULL;
10099
positional_argstack *next;
101100

102101
char c = format[format_idx];
@@ -321,7 +320,7 @@ int _PyArg_ParseTupleAndKeywords_SizeT(PyObject *argv, PyObject *kwds, const cha
321320
PyErr_Format(PyExc_TypeError, "expected tuple, got %R", Py_TYPE(arg));
322321
return 0;
323322
}
324-
next = (positional_argstack*)truffle_managed_malloc(sizeof(positional_argstack));
323+
next = (positional_argstack*)calloc(1, sizeof(positional_argstack));
325324
next->argv = arg;
326325
next->argnum = 0;
327326
next->prev = v;
@@ -331,7 +330,9 @@ int _PyArg_ParseTupleAndKeywords_SizeT(PyObject *argv, PyObject *kwds, const cha
331330
if (v->prev == NULL) {
332331
PyErr_SetString(PyExc_SystemError, "')' without '(' in argument parsing");
333332
} else {
333+
next = v;
334334
v = v->prev;
335+
free(next);
335336
}
336337
break;
337338
case '|':
@@ -353,6 +354,7 @@ int _PyArg_ParseTupleAndKeywords_SizeT(PyObject *argv, PyObject *kwds, const cha
353354
}
354355

355356
end:
357+
free(v);
356358
return 1;
357359
}
358360

@@ -369,10 +371,9 @@ PyObject* _Py_BuildValue_SizeT(const char *format, ...) {
369371
char argchar[2] = {'\0'};
370372
unsigned int value_idx = 1;
371373
unsigned int format_idx = 0;
372-
build_stack *v = (build_stack*)truffle_managed_malloc(sizeof(build_stack));
374+
build_stack *v = (build_stack*)calloc(1, sizeof(build_stack));
373375
build_stack *next;
374376
v->list = PyList_New(0);
375-
v->prev = NULL;
376377

377378
char c = format[format_idx];
378379
while (c != '\0') {
@@ -483,7 +484,7 @@ PyObject* _Py_BuildValue_SizeT(const char *format, ...) {
483484
}
484485
break;
485486
case '(':
486-
next = (build_stack*)truffle_managed_malloc(sizeof(build_stack));
487+
next = (build_stack*)calloc(1, sizeof(build_stack));
487488
next->list = PyList_New(0);
488489
next->prev = v;
489490
v = next;
@@ -493,11 +494,13 @@ PyObject* _Py_BuildValue_SizeT(const char *format, ...) {
493494
PyErr_SetString(PyExc_SystemError, "')' without '(' in Py_BuildValue");
494495
} else {
495496
PyList_Append(v->prev->list, PyList_AsTuple(v->list));
497+
next = v;
496498
v = v->prev;
499+
free(next);
497500
}
498501
break;
499502
case '[':
500-
next = (build_stack*)truffle_managed_malloc(sizeof(build_stack));
503+
next = (build_stack*)calloc(1, sizeof(build_stack));
501504
next->list = PyList_New(0);
502505
next->prev = v;
503506
v = next;
@@ -507,11 +510,13 @@ PyObject* _Py_BuildValue_SizeT(const char *format, ...) {
507510
PyErr_SetString(PyExc_SystemError, "']' without '[' in Py_BuildValue");
508511
} else {
509512
PyList_Append(v->prev->list, v->list);
513+
next = v;
510514
v = v->prev;
515+
free(next);
511516
}
512517
break;
513518
case '{':
514-
next = (build_stack*)truffle_managed_malloc(sizeof(build_stack));
519+
next = (build_stack*)calloc(1, sizeof(build_stack));
515520
next->list = PyList_New(0);
516521
next->prev = v;
517522
v = next;
@@ -521,7 +526,9 @@ PyObject* _Py_BuildValue_SizeT(const char *format, ...) {
521526
PyErr_SetString(PyExc_SystemError, "'}' without '{' in Py_BuildValue");
522527
} else {
523528
PyList_Append(v->prev->list, to_sulong(polyglot_invoke(PY_TRUFFLE_CEXT, "dict_from_list", to_java(v->list))));
529+
next = v;
524530
v = v->prev;
531+
free(next);
525532
}
526533
break;
527534
case ':':

0 commit comments

Comments
 (0)