Skip to content

Commit 7b57c03

Browse files
jdemeyerencukou
authored andcommitted
bpo-37151: remove _PyMethodDef_RawFastCall* functions (GH-14603)
1 parent 8fbeb14 commit 7b57c03

File tree

2 files changed

+0
-273
lines changed

2 files changed

+0
-273
lines changed

Include/methodobject.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ typedef struct {
9595
PyObject *m_weakreflist; /* List of weak references */
9696
vectorcallfunc vectorcall;
9797
} PyCFunctionObject;
98-
99-
PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallDict(
100-
PyMethodDef *method,
101-
PyObject *self,
102-
PyObject *const *args,
103-
Py_ssize_t nargs,
104-
PyObject *kwargs);
105-
106-
PyAPI_FUNC(PyObject *) _PyMethodDef_RawFastCallKeywords(
107-
PyMethodDef *method,
108-
PyObject *self,
109-
PyObject *const *args,
110-
Py_ssize_t nargs,
111-
PyObject *kwnames);
11298
#endif
11399

114100
PyAPI_FUNC(int) PyCFunction_ClearFreeList(void);

Objects/call.c

Lines changed: 0 additions & 259 deletions
Original file line numberDiff line numberDiff line change
@@ -366,265 +366,6 @@ _PyFunction_Vectorcall(PyObject *func, PyObject* const* stack,
366366

367367
/* --- PyCFunction call functions --------------------------------- */
368368

369-
PyObject *
370-
_PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self,
371-
PyObject *const *args, Py_ssize_t nargs,
372-
PyObject *kwargs)
373-
{
374-
/* _PyMethodDef_RawFastCallDict() must not be called with an exception set,
375-
because it can clear it (directly or indirectly) and so the
376-
caller loses its exception */
377-
assert(!PyErr_Occurred());
378-
379-
assert(method != NULL);
380-
assert(nargs >= 0);
381-
assert(nargs == 0 || args != NULL);
382-
assert(kwargs == NULL || PyDict_Check(kwargs));
383-
384-
PyCFunction meth = method->ml_meth;
385-
int flags = method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
386-
PyObject *result = NULL;
387-
388-
if (Py_EnterRecursiveCall(" while calling a Python object")) {
389-
return NULL;
390-
}
391-
392-
switch (flags)
393-
{
394-
case METH_NOARGS:
395-
if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
396-
goto no_keyword_error;
397-
}
398-
399-
if (nargs != 0) {
400-
PyErr_Format(PyExc_TypeError,
401-
"%.200s() takes no arguments (%zd given)",
402-
method->ml_name, nargs);
403-
goto exit;
404-
}
405-
406-
result = (*meth) (self, NULL);
407-
break;
408-
409-
case METH_O:
410-
if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
411-
goto no_keyword_error;
412-
}
413-
414-
if (nargs != 1) {
415-
PyErr_Format(PyExc_TypeError,
416-
"%.200s() takes exactly one argument (%zd given)",
417-
method->ml_name, nargs);
418-
goto exit;
419-
}
420-
421-
result = (*meth) (self, args[0]);
422-
break;
423-
424-
case METH_VARARGS:
425-
if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
426-
goto no_keyword_error;
427-
}
428-
/* fall through */
429-
430-
case METH_VARARGS | METH_KEYWORDS:
431-
{
432-
/* Slow-path: create a temporary tuple for positional arguments */
433-
PyObject *argstuple = _PyTuple_FromArray(args, nargs);
434-
if (argstuple == NULL) {
435-
goto exit;
436-
}
437-
438-
if (flags & METH_KEYWORDS) {
439-
result = (*(PyCFunctionWithKeywords)(void(*)(void))meth) (self, argstuple, kwargs);
440-
}
441-
else {
442-
result = (*meth) (self, argstuple);
443-
}
444-
Py_DECREF(argstuple);
445-
break;
446-
}
447-
448-
case METH_FASTCALL:
449-
{
450-
if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
451-
goto no_keyword_error;
452-
}
453-
454-
result = (*(_PyCFunctionFast)(void(*)(void))meth) (self, args, nargs);
455-
break;
456-
}
457-
458-
case METH_FASTCALL | METH_KEYWORDS:
459-
{
460-
_PyCFunctionFastWithKeywords fastmeth = (_PyCFunctionFastWithKeywords)(void(*)(void))meth;
461-
462-
/* Fast path for no keywords */
463-
if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
464-
result = (*fastmeth) (self, args, nargs, NULL);
465-
break;
466-
}
467-
468-
PyObject *const *stack;
469-
PyObject *kwnames;
470-
stack = _PyStack_UnpackDict(args, nargs, kwargs, &kwnames);
471-
if (stack == NULL) {
472-
goto exit;
473-
}
474-
result = (*fastmeth) (self, stack, nargs, kwnames);
475-
_PyStack_UnpackDict_Free(stack, nargs, kwnames);
476-
break;
477-
}
478-
479-
default:
480-
PyErr_SetString(PyExc_SystemError,
481-
"Bad call flags in _PyMethodDef_RawFastCallDict. "
482-
"METH_OLDARGS is no longer supported!");
483-
goto exit;
484-
}
485-
486-
goto exit;
487-
488-
no_keyword_error:
489-
PyErr_Format(PyExc_TypeError,
490-
"%.200s() takes no keyword arguments",
491-
method->ml_name);
492-
493-
exit:
494-
Py_LeaveRecursiveCall();
495-
return result;
496-
}
497-
498-
499-
PyObject *
500-
_PyMethodDef_RawFastCallKeywords(PyMethodDef *method, PyObject *self,
501-
PyObject *const *args, Py_ssize_t nargs,
502-
PyObject *kwnames)
503-
{
504-
/* _PyMethodDef_RawFastCallKeywords() must not be called with an exception set,
505-
because it can clear it (directly or indirectly) and so the
506-
caller loses its exception */
507-
assert(!PyErr_Occurred());
508-
509-
assert(method != NULL);
510-
assert(nargs >= 0);
511-
assert(kwnames == NULL || PyTuple_CheckExact(kwnames));
512-
/* kwnames must only contains str strings, no subclass, and all keys must
513-
be unique */
514-
515-
PyCFunction meth = method->ml_meth;
516-
int flags = method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
517-
Py_ssize_t nkwargs = kwnames == NULL ? 0 : PyTuple_GET_SIZE(kwnames);
518-
PyObject *result = NULL;
519-
520-
if (Py_EnterRecursiveCall(" while calling a Python object")) {
521-
return NULL;
522-
}
523-
524-
switch (flags)
525-
{
526-
case METH_NOARGS:
527-
if (nkwargs) {
528-
goto no_keyword_error;
529-
}
530-
531-
if (nargs != 0) {
532-
PyErr_Format(PyExc_TypeError,
533-
"%.200s() takes no arguments (%zd given)",
534-
method->ml_name, nargs);
535-
goto exit;
536-
}
537-
538-
result = (*meth) (self, NULL);
539-
break;
540-
541-
case METH_O:
542-
if (nkwargs) {
543-
goto no_keyword_error;
544-
}
545-
546-
if (nargs != 1) {
547-
PyErr_Format(PyExc_TypeError,
548-
"%.200s() takes exactly one argument (%zd given)",
549-
method->ml_name, nargs);
550-
goto exit;
551-
}
552-
553-
result = (*meth) (self, args[0]);
554-
break;
555-
556-
case METH_FASTCALL:
557-
if (nkwargs) {
558-
goto no_keyword_error;
559-
}
560-
result = ((_PyCFunctionFast)(void(*)(void))meth) (self, args, nargs);
561-
break;
562-
563-
case METH_FASTCALL | METH_KEYWORDS:
564-
/* Fast-path: avoid temporary dict to pass keyword arguments */
565-
result = ((_PyCFunctionFastWithKeywords)(void(*)(void))meth) (self, args, nargs, kwnames);
566-
break;
567-
568-
case METH_VARARGS:
569-
if (nkwargs) {
570-
goto no_keyword_error;
571-
}
572-
/* fall through */
573-
574-
case METH_VARARGS | METH_KEYWORDS:
575-
{
576-
/* Slow-path: create a temporary tuple for positional arguments
577-
and a temporary dict for keyword arguments */
578-
PyObject *argtuple;
579-
580-
argtuple = _PyTuple_FromArray(args, nargs);
581-
if (argtuple == NULL) {
582-
goto exit;
583-
}
584-
585-
if (flags & METH_KEYWORDS) {
586-
PyObject *kwdict;
587-
588-
if (nkwargs > 0) {
589-
kwdict = _PyStack_AsDict(args + nargs, kwnames);
590-
if (kwdict == NULL) {
591-
Py_DECREF(argtuple);
592-
goto exit;
593-
}
594-
}
595-
else {
596-
kwdict = NULL;
597-
}
598-
599-
result = (*(PyCFunctionWithKeywords)(void(*)(void))meth) (self, argtuple, kwdict);
600-
Py_XDECREF(kwdict);
601-
}
602-
else {
603-
result = (*meth) (self, argtuple);
604-
}
605-
Py_DECREF(argtuple);
606-
break;
607-
}
608-
609-
default:
610-
PyErr_SetString(PyExc_SystemError,
611-
"Bad call flags in _PyMethodDef_RawFastCallKeywords. "
612-
"METH_OLDARGS is no longer supported!");
613-
goto exit;
614-
}
615-
616-
goto exit;
617-
618-
no_keyword_error:
619-
PyErr_Format(PyExc_TypeError,
620-
"%.200s() takes no keyword arguments",
621-
method->ml_name);
622-
623-
exit:
624-
Py_LeaveRecursiveCall();
625-
return result;
626-
}
627-
628369
static PyObject *
629370
cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs)
630371
{

0 commit comments

Comments
 (0)