[Zope-CVS] CVS: Packages/ContextWrapper - wrapper.c:1.6 wrapper.h:1.3
Fred Drake Jr
fdrake@acm.org
Wed, 14 Nov 2001 15:06:07 -0500
Update of /cvs-repository/Packages/ContextWrapper
In directory cvs.zope.org:/tmp/cvs-serv15660
Modified Files:
wrapper.c wrapper.h
Log Message:
Add the "inner object" and "inner context" functions to the importable C API.
=== Packages/ContextWrapper/wrapper.c 1.5 => 1.6 ===
static PyObject *
+api_getinnerobject(PyObject *obj)
+{
+ if (obj == NULL)
+ return NULL;
+ while (Wrapper_Check(obj)) {
+ obj = ((WrapperObject *)obj)->wrap_object;
+ }
+ return obj;
+}
+
+static PyObject *
api_getcontext(PyObject *wrapper)
{
if (wrapper == NULL)
@@ -213,6 +224,24 @@
}
static PyObject *
+api_getinnercontext(PyObject *obj)
+{
+ if (obj == NULL)
+ return NULL;
+ if (Wrapper_Check(obj)) {
+ WrapperObject *wrapper = (WrapperObject *)obj;
+ obj = wrapper->wrap_object;
+ while (Wrapper_Check(obj)) {
+ wrapper = (WrapperObject *)obj;
+ obj = wrapper->wrap_object;
+ }
+ return wrapper->wrap_context;
+ }
+ else
+ return NULL;
+}
+
+static PyObject *
api_getdict(PyObject *wrapper)
{
if (wrapper == NULL)
@@ -280,7 +309,9 @@
api_check,
api_create,
api_getobject,
+ api_getinnerobject,
api_getcontext,
+ api_getinnercontext,
api_getdict,
api_getdictcreate,
api_setobject,
@@ -317,9 +348,9 @@
static PyObject *
getinnerobject(PyObject *unused, PyObject *obj)
{
- while (Wrapper_Check(obj)) {
- obj = ((WrapperObject *)obj)->wrap_object;
- }
+ obj = api_getinnerobject(obj);
+ if (obj == NULL)
+ obj = Py_None;
Py_INCREF(obj);
return obj;
}
@@ -358,22 +389,9 @@
static PyObject *
getinnercontext(PyObject *unused, PyObject *obj)
{
- PyObject *result;
-
- if (Wrapper_Check(obj)) {
- WrapperObject *wrapper = (WrapperObject *)obj;
- obj = wrapper->wrap_object;
- while (Wrapper_Check(obj)) {
- wrapper = (WrapperObject *)obj;
- obj = wrapper->wrap_object;
- }
- result = wrapper->wrap_context;
- if (result == NULL)
- result = Py_None;
- }
- else {
+ PyObject *result = api_getinnercontext(obj);
+ if (result == NULL)
result = Py_None;
- }
Py_INCREF(result);
return result;
}
=== Packages/ContextWrapper/wrapper.h 1.2 => 1.3 ===
PyObject *(*create)(PyObject *object, PyObject *context);
PyObject *(*getobject)(PyObject *wrapper);
+ PyObject *(*getinnerobject)(PyObject *wrapper);
PyObject *(*getcontext)(PyObject *wrapper);
+ PyObject *(*getinnercontext)(PyObject *wrapper);
PyObject *(*getdict)(PyObject *wrapper);
PyObject *(*getdictcreate)(PyObject *wrapper);
int (*setobject)(PyObject *wrapper, PyObject *object);
@@ -61,8 +63,12 @@
(_wrapper_api->create((object), (context)))
#define Wrapper_GetObject(wrapper) \
(_wrapper_api->getobject((wrapper)))
+#define Wrapper_GetInnerObject(wrapper) \
+ (_wrapper_api->getinnerobject((wrapper)))
#define Wrapper_GetContext(wrapper) \
(_wrapper_api->getcontext((wrapper)))
+#define Wrapper_GetInnerContext(wrapper) \
+ (_wrapper_api->getinnercontext((wrapper)))
#define Wrapper_GetDict(wrapper) \
(_wrapper_api->getdict((wrapper)))
#define Wrapper_GetDictCreate(wrapper) \