[Zope-CVS] CVS: Packages/ContextWrapper - wrapper.c:1.1
Fred Drake Jr
fdrake@acm.org
Mon, 12 Nov 2001 19:36:51 -0500
Update of /cvs-repository/Packages/ContextWrapper
In directory cvs.zope.org:/tmp/cvs-serv10196
Added Files:
wrapper.c
Log Message:
Initial version of the wrapper object with the Python & importable C APIs in
place. The proxy behaviors and pickle-suppression have not been implemented.
=== Added File Packages/ContextWrapper/wrapper.c === (442/542 lines abridged)
#include <Python.h>
#include "modsupport.h"
#define WRAPPER_MODULE
#include "wrapper.h"
static PyObject *
empty_tuple = NULL;
static int
noncall_init(WrapperObject *self, PyObject *args, PyObject *kwds)
{
int result = -1;
PyObject *context = NULL;
PyObject *object;
if (PyArg_UnpackTuple(args, "__init__", 1, 2, &object, &context)) {
if (PyType_Type.tp_init((PyObject *)self, empty_tuple, NULL) < 0)
goto finally;
printf("initializing wrapper object...\n");
Py_INCREF(object);
self->wrap_object = object;
Py_XINCREF(context);
self->wrap_context = context;
self->wrap_dict = NULL;
result = 0;
}
finally:
return result;
}
static int
callable_init(WrapperObject *self, PyObject *args, PyObject *kwds)
{
puts("callable_init()");
if (PyTuple_GET_SIZE(args)) {
PyObject *object = PyTuple_GET_ITEM(args, 0);
if (!PyCallable_Check(object)) {
PyErr_SetString(PyExc_ValueError,
"expected callable object as arg1");
return -1;
}
}
return noncall_init(self, args, kwds);
}
static int
wrap_traverse(WrapperObject *self, visitproc visit, void *arg)
{
int err = visit(self->wrap_object, arg);
[-=- -=- -=- 442 lines omitted -=- -=- -=-]
{"getdictcreate", getdictcreate, METH_O, getdictcreate__doc__},
{"setobject", setobject, METH_VARARGS, setobject__doc__},
{"setcontext", setcontext, METH_VARARGS, setcontext__doc__},
{NULL, NULL, 0, NULL}
};
static char
module___doc__[] =
"Association between an object, a context object, and a dictionary.\n\
\n\
The context object and dictionary give additional context information\n\
associated with a reference to the basic object. The wrapper objects\n\
act as proxies for the original object.";
static PyObject *
api_object = NULL;
void
initwrapper(void)
{
PyObject *m = Py_InitModule3("wrapper",
module_functions,
module___doc__);
if (m == NULL)
return;
WrapperType.ob_type = &PyType_Type;
CallableWrapperType.ob_type = &PyType_Type;
if (PyType_Ready(&WrapperType) < 0)
return;
if (PyType_Ready(&CallableWrapperType) < 0)
return;
if (api_object == NULL)
api_object = PyCObject_FromVoidPtr(&wrapper_capi, NULL);
if (empty_tuple == NULL)
empty_tuple = PyDict_New();
Py_INCREF(&WrapperType);
PyModule_AddObject(m, "WrapperType",
(PyObject *)&WrapperType);
Py_INCREF(&CallableWrapperType);
PyModule_AddObject(m, "CallableWrapperType",
(PyObject *)&CallableWrapperType);
if (api_object != NULL) {
Py_INCREF(api_object);
PyModule_AddObject(m, "_CAPI", api_object);
}
}