[Zodb-checkins] CVS: StandaloneZODB/ZODB - cPickleCache.c:1.39
Jeremy Hylton
jeremy@zope.com
Mon, 11 Feb 2002 14:43:55 -0500
Update of /cvs-repository/StandaloneZODB/ZODB
In directory cvs.zope.org:/tmp/cvs-serv23509
Modified Files:
cPickleCache.c
Log Message:
Major reformatting of code along with a few sundry changes.
Summary of changes:
- Add function gc_all_items() to call gc_item() on everything in
dict. This factors out common code in all the gc methods.
- Add check_size() function that factors out code to check cache size
before starting a gc.
- Simplify argument processing in cc_invalidate(), avoiding a second
call to PyArg_ParseTuple() when argument is a sequence instead of a
dictionary.
- Chance code to reflect belief that NULL return from PyDict_GetItem()
does not set exception, except in cases that don't apply for the
pickle cache like comparing a string with high-order bit set to a
Unicode object.
- Use if (!expr) instead of UNLESS().
- Remove all statements from conditionals.
- Reformat to 4 spaces and Python-style brace placement.
- Put whitespace around operators and after commas.
=== StandaloneZODB/ZODB/cPickleCache.c 1.38 => 1.39 === (846/946 lines abridged)
"$Id$\n";
-#define ASSIGN(V,E) {PyObject *__e; __e=(E); Py_XDECREF(V); (V)=__e;}
-#define UNLESS(E) if(!(E))
-#define UNLESS_ASSIGN(V,E) ASSIGN(V,E) UNLESS(V)
-#define OBJECT(O) ((PyObject*)O)
-
/* Compute the current time in the units and range used for peristent
objects. */
#define PER_TIME() ((long)(time(NULL) / 3)) % 65536
@@ -33,23 +28,23 @@
static PyObject *py_reload, *py__p_jar, *py__p_changed;
typedef struct {
- PyObject_HEAD
- PyObject *data;
- PyObject *jar;
- PyObject *setklassstate;
- int position;
- int cache_size;
- int cache_age;
- /* Cache statistics */
- int sum_deal;
- int sum_deac;
- double sum_age;
- int n, na;
- time_t last_check; /* Time of last gc */
- double mean_age;
- double mean_deal;
- double mean_deac;
- double df, dfa; /* Degees of freedom for above stats */
+ PyObject_HEAD
+ PyObject *data;
+ PyObject *jar;
+ PyObject *setklassstate;
+ int position;
+ int cache_size;
+ int cache_age;
+ /* Cache statistics */
+ int sum_deal;
+ int sum_deac;
+ double sum_age;
+ int n, na;
+ time_t last_check; /* Time of last gc */
+ double mean_age;
+ double mean_deal;
+ double mean_deac;
+ double df, dfa; /* Degees of freedom for above stats */
} ccobject;
[-=- -=- -=- 846 lines omitted -=- -=- -=-]
(reprfunc)0, /*tp_str*/
-
- /* Space for future expansion */
- 0L,0L,0L,0L,
- ""
};
static PyObject *
@@ -641,9 +643,9 @@
int cache_size=100, cache_age=1000;
PyObject *jar;
- UNLESS(PyArg_ParseTuple(args, "O|ii", &jar, &cache_size, &cache_age))
+ if (!PyArg_ParseTuple(args, "O|ii", &jar, &cache_size, &cache_age))
return NULL;
- return (PyObject*)newccobject(jar, cache_size,cache_age);
+ return (PyObject *)newccobject(jar, cache_size, cache_age);
}
static struct PyMethodDef cCM_methods[] = {
@@ -654,22 +656,17 @@
void
initcPickleCache(void)
{
- PyObject *m, *d;
+ PyObject *m;
- Cctype.ob_type=&PyType_Type;
+ Cctype.ob_type = &PyType_Type;
- UNLESS(ExtensionClassImported) return;
+ if (!ExtensionClassImported)
+ return;
m = Py_InitModule4("cPickleCache", cCM_methods, cPickleCache_doc_string,
(PyObject*)NULL, PYTHON_API_VERSION);
- d = PyModule_GetDict(m);
-
- py_reload=PyString_FromString("reload");
- py__p_jar=PyString_FromString("_p_jar");
- py__p_changed=PyString_FromString("_p_changed");
-
- /* Check for errors */
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module cPickleCache");
+ py_reload = PyString_InternFromString("reload");
+ py__p_jar = PyString_InternFromString("_p_jar");
+ py__p_changed = PyString_InternFromString("_p_changed");
}