[Zope-CVS] CVS: Packages/ContextWrapper - wrapper.h:1.1
Fred Drake Jr
fdrake@acm.org
Mon, 12 Nov 2001 13:26:54 -0500
Update of /cvs-repository/Packages/ContextWrapper
In directory cvs.zope.org:/tmp/cvs-serv15702
Added Files:
wrapper.h
Log Message:
Header for the context wrapper; this can be used by extension packages to
allow the use of the C API for wrapper objects.
=== Added File Packages/ContextWrapper/wrapper.h ===
/* Context Wrapper object; see "BasicContextWrapper" in the Zope 3 wiki:
* http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/
*
* This is intended for use with Python 2.2.
*
* Created by Fred Drake, 2001-Nov-09.
*/
#ifndef _wrapper_H_
#define _wrapper_H_
typedef struct {
PyObject_HEAD
PyObject *wrap_object;
PyObject *wrap_context;
PyObject *wrap_dict;
} WrapperObject;
typedef struct {
int (*check)(PyObject *obj);
PyObject *(*create)(PyObject *object, PyObject *context);
PyObject *(*getobject)(PyObject *wrapper);
PyObject *(*getcontext)(PyObject *wrapper);
PyObject *(*getdict)(PyObject *wrapper);
PyObject *(*getdictcreate)(PyObject *wrapper);
PyObject *(*setobject)(PyObject *wrapper, PyObject *object);
PyObject *(*setcontext)(PyObject *wrapper, PyObject *context);
} WrapperInterface;
#ifndef WRAPPER_MODULE
/* These are only defined in the public interface, and are not
* available within the module implementation. There we use the
* classic Python/C API only.
*/
static WrapperInterface *_wrapper_api = NULL;
static int
Wrapper_Import(void)
{
if (_wrapper_api == NULL) {
PyObject *m = PyImport_ImportModule("wrapper");
if (m != NULL) {
PyObject *tmp = PyObject_GetAttrString(m, "_CAPI");
if (tmp != NULL) {
if (PyCObject_Check(tmp))
_wrapper_api = (WrapperInterface *)
PyCObject_AsVoidPtr(tmp);
Py_DECREF(tmp);
}
}
}
return (_wrapper_api == NULL) ? -1 : 0;
}
#define Wrapper_Check(obj) \
(_wrapper_api->check((obj)))
#define Wrapper_New(object, context) \
(_wrapper_api->create((object), (context)))
#define Wrapper_GetObject(wrapper) \
(_wrapper_api->getobject((wrapper)))
#define Wrapper_GetContext(wrapper) \
(_wrapper_api->getcontext((wrapper)))
#define Wrapper_GetDict(wrapper) \
(_wrapper_api->getdict((wrapper)))
#define Wrapper_GetDictCreate(wrapper) \
(_wrapper_api->getdictcreate((wrapper)))
#define Wrapper_SetObject(wrapper, object) \
(_wrapper_api->setobject((wrapper), (object)))
#define Wrapper_SetContext(wrapper, context) \
(_wrapper_api->setcontext((wrapper), (context)))
#endif
#endif