[Zope-Checkins] CVS: Zope3/lib/python/Persistence - cPersistence.c:1.1.2.1 cPersistence.h:1.1.2.1

Jeremy Hylton jeremy@zope.com
Mon, 11 Feb 2002 23:48:19 -0500


Update of /cvs-repository/Zope3/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv2628

Added Files:
      Tag: Zope-3x-branch
	cPersistence.c cPersistence.h 
Log Message:
Initial effort on Persistent mixin using Python 2.2 new-style classes.

The code compiles without warning, but doesn't do anything yet.


=== Added File Zope3/lib/python/Persistence/cPersistence.c === (429/529 lines abridged)
#include "Python.h"
#include "structmember.h"
#include "cPersistence.h"

static char PyPersist_doc_string[] =
"Defines Persistent mixin class for persistent objects.\n"
"\n"
"$Id: cPersistence.c,v 1.1.2.1 2002/02/12 04:48:18 jeremy Exp $\n";

staticforward PyTypeObject persist_type;

/* A helper for setstate that is more efficient than PyMapping_Keys().
 */

PyObject *_PyPersist_MappingKeys(PyObject *map)
{
    static PyObject *s_keys = NULL;
    PyObject *meth, *args, *keys;
    if (s_keys == NULL) 
	s_keys = PyString_InternFromString("keys");
    meth = PyObject_GetAttr(map, s_keys);
    if (meth == NULL)
	return NULL;
    args = PyTuple_New(0);
    if (args == NULL) {
	Py_DECREF(meth);
	return NULL;
    }
    keys = PyObject_Call(meth, args, NULL);
    Py_DECREF(args);
    Py_DECREF(meth);
    return keys;
}

/* A helper function that registers a persistent object with its data
   manager.
*/

PyObject *_PyPersist_Register(PyPersistObject *self) 
{
    static PyObject *s_register = NULL;
    PyObject *meth, *arg, *result;

    if (s_register == NULL) 
	s_register = PyString_InternFromString("register");
    meth = PyObject_GetAttr((PyObject *)self, s_register);
    if (meth == NULL)
	return NULL;
    arg = PyTuple_New(1);
    if (arg == NULL) {

[-=- -=- -=- 429 lines omitted -=- -=- -=-]

   DEFERRED_ADDRESS macro is used to tag the slots where such addresses
   appear; the module init function must fill in the tagged slots at runtime.
   The argument is for documentation -- the macro ignores it.
*/
#define DEFERRED_ADDRESS(ADDR) 0

static PyTypeObject persist_type = {
	PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
	0,					/* ob_size */
	"Persistent",				/* tp_name */
	sizeof(PyPersistObject),		/* tp_basicsize */
	0,					/* tp_itemsize */
	(destructor)persist_dealloc,		/* tp_dealloc */
	0,					/* tp_print */
	0,					/* tp_getattr */
	0,					/* tp_setattr */
	0,					/* tp_compare */
	0,					/* tp_repr */
	0,					/* tp_as_number */
	0,					/* tp_as_sequence */
	0,					/* tp_as_mapping */
	0,					/* tp_hash */
	0,					/* tp_call */
	0,					/* tp_str */
	(getattrofunc)persist_getattro,		/* tp_getattro */
	(setattrofunc)persist_setattro,		/* tp_setattro */
	0,					/* tp_as_buffer */
	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
		Py_TPFLAGS_BASETYPE, 		/* tp_flags */
	0,					/* tp_doc */
	(traverseproc)persist_traverse,		/* tp_traverse */
	(inquiry)persist_clear,			/* tp_clear */
	0,					/* tp_richcompare */
	0,					/* tp_weaklistoffset */
	0,					/* tp_iter */
	0,					/* tp_iternext */
	persist_methods,			/* tp_methods */
	persist_members,			/* tp_members */
	persist_getsets,			/* tp_getset */
	0,					/* tp_base */
	0,					/* tp_dict */
	0,					/* tp_descr_get */
	0,					/* tp_descr_set */
	0,					/* tp_dictoffset */
	0,					/* tp_init */
	0,					/* tp_alloc */
	0,					/* tp_new */
};




=== Added File Zope3/lib/python/Persistence/cPersistence.h ===
#include <time.h>

enum PyPersist_State { GHOST, UPTODATE, CHANGED, STICKY };

#define PyPersist_HEAD \
    PyObject_HEAD \
    PyObject *po_dm; \
    /* XXX oid and serial could be hard-coded as 8-byte strings */ \
    PyObject *po_oid; \
    PyObject *po_serial; \
    time_t po_atime; \
    enum PyPersist_State po_state;

typedef struct {
    PyPersist_HEAD
} PyPersistObject;