/* * Return an instance of the dialect type, given a Python instance or kwarg * description of the dialect */ static PyObject * _call_dialect(PyObject *dialect_inst, PyObject *kwargs) { PyObject *type = (PyObject *)&Dialect_Type; if (dialect_inst) { return _PyObject_FastCallDict(type, &dialect_inst, 1, kwargs); } else { return _PyObject_FastCallDict(type, NULL, 0, kwargs); } }
PyObject * PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, PyObject *name, PyObject *path) { int issubclass; PyObject *kwargs, *error; issubclass = PyObject_IsSubclass(exception, PyExc_ImportError); if (issubclass < 0) { return NULL; } else if (!issubclass) { PyErr_SetString(PyExc_TypeError, "expected a subclass of ImportError"); return NULL; } if (msg == NULL) { PyErr_SetString(PyExc_TypeError, "expected a message argument"); return NULL; } if (name == NULL) { name = Py_None; } if (path == NULL) { path = Py_None; } kwargs = PyDict_New(); if (kwargs == NULL) { return NULL; } if (PyDict_SetItemString(kwargs, "name", name) < 0) { goto done; } if (PyDict_SetItemString(kwargs, "path", path) < 0) { goto done; } error = _PyObject_FastCallDict(exception, &msg, 1, kwargs); if (error != NULL) { PyErr_SetObject((PyObject *)Py_TYPE(error), error); Py_DECREF(error); } done: Py_DECREF(kwargs); return NULL; }
static PyObject * partial_fastcall(partialobject *pto, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { PyObject *small_stack[_PY_FASTCALL_SMALL_STACK]; PyObject *ret; PyObject **stack, **stack_buf = NULL; Py_ssize_t nargs2, pto_nargs; pto_nargs = PyTuple_GET_SIZE(pto->args); nargs2 = pto_nargs + nargs; if (pto_nargs == 0) { stack = args; } else if (nargs == 0) { stack = &PyTuple_GET_ITEM(pto->args, 0); } else { if (nargs2 <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) { stack = small_stack; } else { stack_buf = PyMem_Malloc(nargs2 * sizeof(PyObject *)); if (stack_buf == NULL) { PyErr_NoMemory(); return NULL; } stack = stack_buf; } /* use borrowed references */ memcpy(stack, &PyTuple_GET_ITEM(pto->args, 0), pto_nargs * sizeof(PyObject*)); memcpy(&stack[pto_nargs], args, nargs * sizeof(PyObject*)); } ret = _PyObject_FastCallDict(pto->fn, stack, nargs2, kwargs); PyMem_Free(stack_buf); return ret; }
static PyObject * partial_call(partialobject *pto, PyObject *args, PyObject *kw) { PyObject *ret; PyObject *argappl, *kwappl; PyObject **stack; Py_ssize_t nargs; assert (PyCallable_Check(pto->fn)); assert (PyTuple_Check(pto->args)); assert (PyDict_Check(pto->kw)); if (PyTuple_GET_SIZE(pto->args) == 0) { stack = &PyTuple_GET_ITEM(args, 0); nargs = PyTuple_GET_SIZE(args); argappl = NULL; } else if (PyTuple_GET_SIZE(args) == 0) { stack = &PyTuple_GET_ITEM(pto->args, 0); nargs = PyTuple_GET_SIZE(pto->args); argappl = NULL; } else { stack = NULL; argappl = PySequence_Concat(pto->args, args); if (argappl == NULL) { return NULL; } assert(PyTuple_Check(argappl)); } if (PyDict_GET_SIZE(pto->kw) == 0) { kwappl = kw; Py_XINCREF(kwappl); } else { kwappl = PyDict_Copy(pto->kw); if (kwappl == NULL) { Py_XDECREF(argappl); return NULL; } if (kw != NULL) { if (PyDict_Merge(kwappl, kw, 1) != 0) { Py_XDECREF(argappl); Py_DECREF(kwappl); return NULL; } } } if (stack) { ret = _PyObject_FastCallDict(pto->fn, stack, nargs, kwappl); } else { ret = PyObject_Call(pto->fn, argappl, kwappl); Py_DECREF(argappl); } Py_XDECREF(kwappl); return ret; }