[Python-checkins] python/dist/src/Objects typeobject.c,2.254,2.255
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sat Dec 13 10:21:57 EST 2003
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv13787
Modified Files:
typeobject.c
Log Message:
Improve argument checking speed.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.254
retrieving revision 2.255
diff -C2 -d -r2.254 -r2.255
*** typeobject.c 13 Dec 2003 11:26:12 -0000 2.254
--- typeobject.c 13 Dec 2003 15:21:55 -0000 2.255
***************
*** 3321,3324 ****
--- 3321,3340 ----
}
+ static int
+ check_num_args(PyObject *ob, int n)
+ {
+ if (!PyTuple_CheckExact(ob)) {
+ PyErr_SetString(PyExc_SystemError,
+ "PyArg_UnpackTuple() argument list is not a tuple");
+ return 0;
+ }
+ if (n == PyTuple_GET_SIZE(ob))
+ return 1;
+ PyErr_Format(
+ PyExc_TypeError,
+ "expected %d arguments, got %d", n, PyTuple_GET_SIZE(ob));
+ return 0;
+ }
+
/* Generic wrappers for overloadable 'operators' such as __getitem__ */
***************
*** 3335,3339 ****
int res;
! if (!PyArg_UnpackTuple(args, "", 0, 0))
return NULL;
res = (*func)(self);
--- 3351,3355 ----
int res;
! if (!check_num_args(args, 0))
return NULL;
res = (*func)(self);
***************
*** 3349,3353 ****
int res;
! if (!PyArg_UnpackTuple(args, "", 0, 0))
return NULL;
res = (*func)(self);
--- 3365,3369 ----
int res;
! if (!check_num_args(args, 0))
return NULL;
res = (*func)(self);
***************
*** 3363,3368 ****
PyObject *other;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &other))
return NULL;
return (*func)(self, other);
}
--- 3379,3385 ----
PyObject *other;
! if (!check_num_args(args, 1))
return NULL;
+ other = PyTuple_GET_ITEM(args, 0);
return (*func)(self, other);
}
***************
*** 3374,3379 ****
PyObject *other;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &other))
return NULL;
if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
!PyType_IsSubtype(other->ob_type, self->ob_type)) {
--- 3391,3397 ----
PyObject *other;
! if (!check_num_args(args, 1))
return NULL;
+ other = PyTuple_GET_ITEM(args, 0);
if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
!PyType_IsSubtype(other->ob_type, self->ob_type)) {
***************
*** 3390,3395 ****
PyObject *other;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &other))
return NULL;
if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
!PyType_IsSubtype(other->ob_type, self->ob_type)) {
--- 3408,3414 ----
PyObject *other;
! if (!check_num_args(args, 1))
return NULL;
+ other = PyTuple_GET_ITEM(args, 0);
if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
!PyType_IsSubtype(other->ob_type, self->ob_type)) {
***************
*** 3407,3412 ****
int ok;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &other))
return NULL;
ok = func(&self, &other);
if (ok < 0)
--- 3426,3432 ----
int ok;
! if (!check_num_args(args, 1))
return NULL;
+ other = PyTuple_GET_ITEM(args, 0);
ok = func(&self, &other);
if (ok < 0)
***************
*** 3460,3464 ****
unaryfunc func = (unaryfunc)wrapped;
! if (!PyArg_UnpackTuple(args, "", 0, 0))
return NULL;
return (*func)(self);
--- 3480,3484 ----
unaryfunc func = (unaryfunc)wrapped;
! if (!check_num_args(args, 0))
return NULL;
return (*func)(self);
***************
*** 3510,3514 ****
return (*func)(self, i);
}
! PyArg_UnpackTuple(args, "", 1, 1, &arg);
assert(PyErr_Occurred());
return NULL;
--- 3530,3534 ----
return (*func)(self, i);
}
! check_num_args(args, 1);
assert(PyErr_Occurred());
return NULL;
***************
*** 3552,3557 ****
PyObject *arg;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &arg))
return NULL;
i = getindex(self, arg);
if (i == -1 && PyErr_Occurred())
--- 3572,3578 ----
PyObject *arg;
! if (!check_num_args(args, 1))
return NULL;
+ arg = PyTuple_GET_ITEM(args, 0);
i = getindex(self, arg);
if (i == -1 && PyErr_Occurred())
***************
*** 3603,3608 ****
PyObject *value;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &value))
return NULL;
res = (*func)(self, value);
if (res == -1 && PyErr_Occurred())
--- 3624,3630 ----
PyObject *value;
! if (!check_num_args(args, 1))
return NULL;
+ value = PyTuple_GET_ITEM(args, 0);
res = (*func)(self, value);
if (res == -1 && PyErr_Occurred())
***************
*** 3635,3640 ****
PyObject *key;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &key))
return NULL;
res = (*func)(self, key, NULL);
if (res == -1 && PyErr_Occurred())
--- 3657,3663 ----
PyObject *key;
! if (!check_num_args(args, 1))
return NULL;
+ key = PyTuple_GET_ITEM(args, 0);
res = (*func)(self, key, NULL);
if (res == -1 && PyErr_Occurred())
***************
*** 3651,3656 ****
PyObject *other;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &other))
return NULL;
if (other->ob_type->tp_compare != func &&
!PyType_IsSubtype(other->ob_type, self->ob_type)) {
--- 3674,3680 ----
PyObject *other;
! if (!check_num_args(args, 1))
return NULL;
+ other = PyTuple_GET_ITEM(args, 0);
if (other->ob_type->tp_compare != func &&
!PyType_IsSubtype(other->ob_type, self->ob_type)) {
***************
*** 3712,3717 ****
PyObject *name;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &name))
return NULL;
if (!hackcheck(self, func, "__delattr__"))
return NULL;
--- 3736,3742 ----
PyObject *name;
! if (!check_num_args(args, 1))
return NULL;
+ name = PyTuple_GET_ITEM(args, 0);
if (!hackcheck(self, func, "__delattr__"))
return NULL;
***************
*** 3729,3733 ****
long res;
! if (!PyArg_UnpackTuple(args, "", 0, 0))
return NULL;
res = (*func)(self);
--- 3754,3758 ----
long res;
! if (!check_num_args(args, 0))
return NULL;
res = (*func)(self);
***************
*** 3751,3756 ****
PyObject *other;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &other))
return NULL;
return (*func)(self, other, op);
}
--- 3776,3782 ----
PyObject *other;
! if (!check_num_args(args, 1))
return NULL;
+ other = PyTuple_GET_ITEM(args, 0);
return (*func)(self, other, op);
}
***************
*** 3777,3781 ****
PyObject *res;
! if (!PyArg_UnpackTuple(args, "", 0, 0))
return NULL;
res = (*func)(self);
--- 3803,3807 ----
PyObject *res;
! if (!check_num_args(args, 0))
return NULL;
res = (*func)(self);
***************
*** 3829,3834 ****
int ret;
! if (!PyArg_UnpackTuple(args, "", 1, 1, &obj))
return NULL;
ret = (*func)(self, obj, NULL);
if (ret < 0)
--- 3855,3861 ----
int ret;
! if (!check_num_args(args, 1))
return NULL;
+ obj = PyTuple_GET_ITEM(args, 0);
ret = (*func)(self, obj, NULL);
if (ret < 0)
More information about the Python-checkins
mailing list