[Zope-Checkins] CVS: StandaloneZODB/ZODB - cPersistence.c:1.43.68.1
Jeremy Hylton
jeremy@zope.com
Tue, 6 Nov 2001 11:29:09 -0500
Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv30355/ZODB
Modified Files:
Tag: jeremy-Standby-branch
cPersistence.c
Log Message:
Two small performance-related changes and some code cleanups.
Add checknoargs() function to use in place of PyArg_ParseTuple(args, "").
After an explicit PyString_Check() call is made, use
PyString_AS_STRING() instead of PyString_AsString().
=== StandaloneZODB/ZODB/cPersistence.c 1.43 => 1.43.68.1 ===
}
+static int
+checknoargs(PyObject *args)
+{
+ if (!PyTuple_Check(args))
+ return 0;
+ if (PyTuple_GET_SIZE(args) != 0) {
+ PyErr_Format(PyExc_TypeError,
+ "function takes exactly 0 arguments (%d given)",
+ PyTuple_GET_SIZE(args));
+ return 0;
+ }
+ return 1;
+}
+
static PyObject *
callmethod(PyObject *self, PyObject *name)
{
@@ -243,7 +257,8 @@
if (idebug_log < 0) call_debug("reinit",self);
#endif
- if (args && ! PyArg_ParseTuple(args,"")) return NULL;
+ if (args && !checknoargs(args))
+ return NULL;
if (self->state==cPersistent_UPTODATE_STATE && self->jar &&
HasInstDict(self) && (dict=INSTANCE_DICT(self)))
@@ -273,7 +288,7 @@
{
PyObject *__dict__, *d=0;
- UNLESS(PyArg_ParseTuple(args, "")) return NULL;
+ if (!checknoargs(args)) return NULL;
#ifdef DEBUG_LOG
if(idebug_log < 0) call_debug("get",self);
@@ -289,12 +304,12 @@
for(pos=0; PyDict_Next(__dict__, &pos, &k, &v); )
{
- if(PyString_Check(k) && (ck=PyString_AsString(k)) &&
+ if(PyString_Check(k) && (ck=PyString_AS_STRING(k)) &&
(*ck=='_' && ck[1]=='v' && ck[2]=='_'))
{
UNLESS(d=PyDict_New()) goto err;
for(pos=0; PyDict_Next(__dict__, &pos, &k, &v); )
- UNLESS(PyString_Check(k) && (ck=PyString_AsString(k)) &&
+ UNLESS(PyString_Check(k) && (ck=PyString_AS_STRING(k)) &&
(*ck=='_' && ck[1]=='v' && ck[2]=='_'))
if(PyDict_SetItem(d,k,v) < 0) goto err;
return d;
@@ -331,8 +346,8 @@
if(PyDict_Check(v))
{
- for(i=0; PyDict_Next(v,&i,&key,&e);)
- if(PyObject_SetItem(__dict__,key,e) < 0)
+ for(i=0; PyDict_Next(v, &i, &key, &e);)
+ if(PyDict_SetItem(__dict__, key, e) < 0)
return NULL;
}
else
@@ -483,7 +498,7 @@
PyObject *r;
if (PyString_Check(name))
- UNLESS(s=PyString_AsString(name)) return NULL;
+ UNLESS(s=PyString_AS_STRING(name)) return NULL;
r = Per_getattr(self, name, s, PyExtensionClassCAPI->getattro);
if (! r && self->state != cPersistent_GHOST_STATE &&
@@ -492,6 +507,7 @@
)
{
PyErr_Clear();
+
r=PyObject_GetAttr(OBJECT(self), py___getattr__);
if (r)
{
@@ -510,7 +526,7 @@
char *name="";
UNLESS(oname) return -1;
- if(PyString_Check(oname)) UNLESS(name=PyString_AsString(oname)) return -1;
+ if(PyString_Check(oname)) UNLESS(name=PyString_AS_STRING(oname)) return -1;
if(*name=='_' && name[1]=='p' && name[2]=='_')
{