mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-07 02:10:27 +00:00
parent
4802173eba
commit
a7bf3bda15
1 changed files with 45 additions and 31 deletions
76
third_party/python/Objects/methodobject.c
vendored
76
third_party/python/Objects/methodobject.c
vendored
|
@ -231,35 +231,29 @@ _PyCFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
|
_PyMethodDef_RawFastCallKeywords(PyMethodDef *method, PyObject *self, PyObject **args,
|
||||||
Py_ssize_t nargs, PyObject *kwnames)
|
Py_ssize_t nargs, PyObject *kwnames)
|
||||||
{
|
{
|
||||||
PyCFunctionObject *func;
|
/* _PyMethodDef_RawFastCallKeywords() must not be called with an exception set,
|
||||||
PyCFunction meth;
|
because it can clear it (directly or indirectly) and so the
|
||||||
PyObject *self, *result;
|
caller loses its exception */
|
||||||
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
|
assert(!PyErr_Occurred());
|
||||||
int flags;
|
|
||||||
|
|
||||||
assert(func_obj != NULL);
|
assert(method != NULL);
|
||||||
assert(PyCFunction_Check(func_obj));
|
|
||||||
assert(nargs >= 0);
|
assert(nargs >= 0);
|
||||||
assert(kwnames == NULL || PyTuple_CheckExact(kwnames));
|
assert(kwnames == NULL || PyTuple_CheckExact(kwnames));
|
||||||
assert((nargs == 0 && nkwargs == 0) || args != NULL);
|
|
||||||
/* kwnames must only contains str strings, no subclass, and all keys must
|
/* kwnames must only contains str strings, no subclass, and all keys must
|
||||||
be unique */
|
be unique */
|
||||||
|
|
||||||
/* _PyCFunction_FastCallKeywords() must not be called with an exception
|
PyCFunction meth = method->ml_meth;
|
||||||
set, because it can clear it (directly or indirectly) and so the caller
|
int flags = method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
|
||||||
loses its exception */
|
Py_ssize_t nkwargs = kwnames == NULL ? 0 : PyTuple_Size(kwnames);
|
||||||
assert(!PyErr_Occurred());
|
PyObject *result = NULL;
|
||||||
|
|
||||||
func = (PyCFunctionObject*)func_obj;
|
if (Py_EnterRecursiveCall(" while calling a Python object")) {
|
||||||
meth = PyCFunction_GET_FUNCTION(func);
|
return NULL;
|
||||||
self = PyCFunction_GET_SELF(func);
|
}
|
||||||
flags = PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
|
|
||||||
|
|
||||||
switch (flags)
|
switch (flags)
|
||||||
{
|
{
|
||||||
|
@ -267,8 +261,8 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
|
||||||
if (nargs != 0) {
|
if (nargs != 0) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%.200s() takes no arguments (%zd given)",
|
"%.200s() takes no arguments (%zd given)",
|
||||||
func->m_ml->ml_name, nargs);
|
method->ml_name, nargs);
|
||||||
return NULL;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nkwargs) {
|
if (nkwargs) {
|
||||||
|
@ -282,8 +276,8 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
|
||||||
if (nargs != 1) {
|
if (nargs != 1) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%.200s() takes exactly one argument (%zd given)",
|
"%.200s() takes exactly one argument (%zd given)",
|
||||||
func->m_ml->ml_name, nargs);
|
method->ml_name, nargs);
|
||||||
return NULL;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nkwargs) {
|
if (nkwargs) {
|
||||||
|
@ -311,7 +305,7 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
|
||||||
|
|
||||||
argtuple = _PyStack_AsTuple(args, nargs);
|
argtuple = _PyStack_AsTuple(args, nargs);
|
||||||
if (argtuple == NULL) {
|
if (argtuple == NULL) {
|
||||||
return NULL;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & METH_KEYWORDS) {
|
if (flags & METH_KEYWORDS) {
|
||||||
|
@ -321,7 +315,7 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
|
||||||
kwdict = _PyStack_AsDict(args + nargs, kwnames);
|
kwdict = _PyStack_AsDict(args + nargs, kwnames);
|
||||||
if (kwdict == NULL) {
|
if (kwdict == NULL) {
|
||||||
Py_DECREF(argtuple);
|
Py_DECREF(argtuple);
|
||||||
return NULL;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -342,19 +336,39 @@ _PyCFunction_FastCallKeywords(PyObject *func_obj, PyObject **args,
|
||||||
PyErr_SetString(PyExc_SystemError,
|
PyErr_SetString(PyExc_SystemError,
|
||||||
"Bad call flags in _PyCFunction_FastCallKeywords. "
|
"Bad call flags in _PyCFunction_FastCallKeywords. "
|
||||||
"METH_OLDARGS is no longer supported!");
|
"METH_OLDARGS is no longer supported!");
|
||||||
return NULL;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = _Py_CheckFunctionResult(func_obj, result, NULL);
|
goto exit;
|
||||||
return result;
|
|
||||||
|
|
||||||
no_keyword_error:
|
no_keyword_error:
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%.200s() takes no keyword arguments",
|
"%.200s() takes no keyword arguments",
|
||||||
func->m_ml->ml_name);
|
method->ml_name);
|
||||||
return NULL;
|
|
||||||
|
exit:
|
||||||
|
Py_LeaveRecursiveCall();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
_PyCFunction_FastCallKeywords(PyObject *func, PyObject **args,
|
||||||
|
Py_ssize_t nargs, PyObject *kwnames)
|
||||||
|
{
|
||||||
|
PyObject *result;
|
||||||
|
|
||||||
|
assert(func != NULL);
|
||||||
|
assert(PyCFunction_Check(func));
|
||||||
|
|
||||||
|
result = _PyMethodDef_RawFastCallKeywords(((PyCFunctionObject*)func)->m_ml,
|
||||||
|
PyCFunction_GET_SELF(func),
|
||||||
|
args, nargs, kwnames);
|
||||||
|
result = _Py_CheckFunctionResult(func, result, NULL);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Methods (the standard built-in methods, that is) */
|
/* Methods (the standard built-in methods, that is) */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue