Skip to content

Commit 0fcef29

Browse files
committed
WIP testing in CI
Revert "fix: `_PyArg_UnpackKeywords` API is removed, use `PyArg_ParseTupleAndKeywords` instead" This reverts commit d3c0f85.
1 parent a2d9ce8 commit 0fcef29

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

include/JSArrayProxy.hh

+4-3
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,11 @@ public:
251251
*
252252
* @param self - The JSArrayProxy
253253
* @param args - arguments to the sort method (not used)
254-
* @param kwargs - keyword arguments to the sort method (reverse=True|False, key=keyfunction)
254+
* @param nargs - number of arguments to the sort method
255+
* @param kwnames - keyword arguments to the sort method (reverse=True|False, key=keyfunction)
255256
* @return PyObject* NULL on exception, None otherwise
256257
*/
257-
static PyObject *JSArrayProxy_sort(JSArrayProxy *self, PyObject *args, PyObject *kwargs);
258+
static PyObject *JSArrayProxy_sort(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames);
258259

259260
/**
260261
* @brief tp_traverse
@@ -403,7 +404,7 @@ static PyMethodDef JSArrayProxy_methods[] = {
403404
{"index", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_index, METH_FASTCALL, list_index__doc__},
404405
{"count", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_count, METH_O, list_count__doc__},
405406
{"reverse", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_reverse, METH_NOARGS, list_reverse__doc__},
406-
{"sort", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_sort, METH_VARARGS|METH_KEYWORDS, list_sort__doc__},
407+
{"sort", (PyCFunction)JSArrayProxyMethodDefinitions::JSArrayProxy_sort, METH_FASTCALL|METH_KEYWORDS, list_sort__doc__},
407408
{NULL, NULL} /* sentinel */
408409
};
409410

src/JSArrayProxy.cc

+29-3
Original file line numberDiff line numberDiff line change
@@ -1180,15 +1180,41 @@ static bool sort_compare_default(JSContext *cx, unsigned argc, JS::Value *vp) {
11801180
return true;
11811181
}
11821182

1183-
PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_sort(JSArrayProxy *self, PyObject *args, PyObject *kwargs) {
1183+
PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_sort(JSArrayProxy *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) {
11841184
static const char *const _keywords[] = {"key", "reverse", NULL};
1185-
1185+
static _PyArg_Parser _parser = {
1186+
.keywords = _keywords,
1187+
.fname = "sort",
1188+
.kwtuple = NULL,
1189+
};
1190+
1191+
PyObject *argsbuf[2];
1192+
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
11861193
PyObject *keyfunc = Py_None;
11871194
int reverse = 0;
1188-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|$Op:sort", (char **)_keywords, &keyfunc, &reverse)) {
1195+
1196+
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
1197+
if (!args) {
1198+
return NULL;
1199+
}
1200+
1201+
if (!noptargs) {
1202+
goto skip_optional_kwonly;
1203+
}
1204+
1205+
if (args[0]) {
1206+
keyfunc = args[0];
1207+
if (!--noptargs) {
1208+
goto skip_optional_kwonly;
1209+
}
1210+
}
1211+
1212+
reverse = PyObject_IsTrue(args[1]);
1213+
if (reverse < 0) {
11891214
return NULL;
11901215
}
11911216

1217+
skip_optional_kwonly:
11921218
if (JSArrayProxy_length(self) > 1) {
11931219
JS::RootedValue jReturnedArray(GLOBAL_CX);
11941220
if (keyfunc != Py_None) {

0 commit comments

Comments
 (0)