Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit fb622c5

Browse files
author
Anselm Kruis
committed
Stackless issue #254: bpo-36127: Argument Clinic: inline parsing code
for keyword parameters. Adapt Stackless to upstream commit 3191391.
1 parent 5d73851 commit fb622c5

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

Stackless/module/clinic/stacklessmodule.c.h

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,43 @@ _stackless_pickle_flags_default(PyObject *module, PyObject *const *args, Py_ssiz
3030
{
3131
PyObject *return_value = NULL;
3232
static const char * const _keywords[] = {"new_default", "mask", NULL};
33-
static _PyArg_Parser _parser = {"|ll:pickle_flags_default", _keywords, 0};
33+
static _PyArg_Parser _parser = {NULL, _keywords, "pickle_flags_default", 0};
34+
PyObject *argsbuf[2];
35+
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
3436
long new_default = -1;
3537
long mask = -1;
3638

37-
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
38-
&new_default, &mask)) {
39+
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
40+
if (!args) {
3941
goto exit;
4042
}
43+
if (!noptargs) {
44+
goto skip_optional_pos;
45+
}
46+
if (args[0]) {
47+
if (PyFloat_Check(args[0])) {
48+
PyErr_SetString(PyExc_TypeError,
49+
"integer argument expected, got float" );
50+
goto exit;
51+
}
52+
new_default = PyLong_AsLong(args[0]);
53+
if (new_default == -1 && PyErr_Occurred()) {
54+
goto exit;
55+
}
56+
if (!--noptargs) {
57+
goto skip_optional_pos;
58+
}
59+
}
60+
if (PyFloat_Check(args[1])) {
61+
PyErr_SetString(PyExc_TypeError,
62+
"integer argument expected, got float" );
63+
goto exit;
64+
}
65+
mask = PyLong_AsLong(args[1]);
66+
if (mask == -1 && PyErr_Occurred()) {
67+
goto exit;
68+
}
69+
skip_optional_pos:
4170
return_value = _stackless_pickle_flags_default_impl(module, new_default, mask);
4271

4372
exit:
@@ -81,14 +110,43 @@ _stackless_pickle_flags(PyObject *module, PyObject *const *args, Py_ssize_t narg
81110
{
82111
PyObject *return_value = NULL;
83112
static const char * const _keywords[] = {"new_flags", "mask", NULL};
84-
static _PyArg_Parser _parser = {"|ll:pickle_flags", _keywords, 0};
113+
static _PyArg_Parser _parser = {NULL, _keywords, "pickle_flags", 0};
114+
PyObject *argsbuf[2];
115+
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
85116
long new_flags = -1;
86117
long mask = -1;
87118

88-
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
89-
&new_flags, &mask)) {
119+
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
120+
if (!args) {
121+
goto exit;
122+
}
123+
if (!noptargs) {
124+
goto skip_optional_pos;
125+
}
126+
if (args[0]) {
127+
if (PyFloat_Check(args[0])) {
128+
PyErr_SetString(PyExc_TypeError,
129+
"integer argument expected, got float" );
130+
goto exit;
131+
}
132+
new_flags = PyLong_AsLong(args[0]);
133+
if (new_flags == -1 && PyErr_Occurred()) {
134+
goto exit;
135+
}
136+
if (!--noptargs) {
137+
goto skip_optional_pos;
138+
}
139+
}
140+
if (PyFloat_Check(args[1])) {
141+
PyErr_SetString(PyExc_TypeError,
142+
"integer argument expected, got float" );
143+
goto exit;
144+
}
145+
mask = PyLong_AsLong(args[1]);
146+
if (mask == -1 && PyErr_Occurred()) {
90147
goto exit;
91148
}
149+
skip_optional_pos:
92150
return_value = _stackless_pickle_flags_impl(module, new_flags, mask);
93151

94152
exit:
@@ -104,4 +162,4 @@ _stackless_pickle_flags(PyObject *module, PyObject *const *args, Py_ssize_t narg
104162
#ifndef _STACKLESS_PICKLE_FLAGS_METHODDEF
105163
#define _STACKLESS_PICKLE_FLAGS_METHODDEF
106164
#endif /* !defined(_STACKLESS_PICKLE_FLAGS_METHODDEF) */
107-
/*[clinic end generated code: output=e59f426d5b04d0fe input=a9049054013a1b77]*/
165+
/*[clinic end generated code: output=25a1592662352a4a input=a9049054013a1b77]*/

Stackless/module/clinic/taskletobject.c.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ _stackless_tasklet_set_context(PyTaskletObject *self, PyObject *const *args, Py_
2828
{
2929
PyObject *return_value = NULL;
3030
static const char * const _keywords[] = {"context", NULL};
31-
static _PyArg_Parser _parser = {"O!:set_context", _keywords, 0};
31+
static _PyArg_Parser _parser = {NULL, _keywords, "set_context", 0};
32+
PyObject *argsbuf[1];
3233
PyObject *context;
3334

34-
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
35-
&PyContext_Type, &context)) {
35+
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
36+
if (!args) {
3637
goto exit;
3738
}
39+
if (!PyObject_TypeCheck(args[0], &PyContext_Type)) {
40+
_PyArg_BadArgument("set_context", 1, (&PyContext_Type)->tp_name, args[0]);
41+
goto exit;
42+
}
43+
context = args[0];
3844
return_value = _stackless_tasklet_set_context_impl(self, context);
3945

4046
exit:
@@ -46,4 +52,4 @@ _stackless_tasklet_set_context(PyTaskletObject *self, PyObject *const *args, Py_
4652
#ifndef _STACKLESS_TASKLET_SET_CONTEXT_METHODDEF
4753
#define _STACKLESS_TASKLET_SET_CONTEXT_METHODDEF
4854
#endif /* !defined(_STACKLESS_TASKLET_SET_CONTEXT_METHODDEF) */
49-
/*[clinic end generated code: output=d6d26cc0dd503a03 input=a9049054013a1b77]*/
55+
/*[clinic end generated code: output=f61ea97534fa8b7d input=a9049054013a1b77]*/

0 commit comments

Comments
 (0)