Commit 209d8292 authored by Jim Fulton's avatar Jim Fulton

Added special module variable, 'Acquired'. If the value of this

variable is assigned to an attribute, then the value of the attribute
will be acquired, even if it might not otherwize be acquired.
parent e1add391
/* /*
$Id: Acquisition.c,v 1.13 1997/11/19 13:51:14 jim Exp $ $Id: Acquisition.c,v 1.14 1998/01/05 13:38:31 jim Exp $
Acquisition Wrappers -- Implementation of acquisition through wrappers Acquisition Wrappers -- Implementation of acquisition through wrappers
...@@ -80,6 +80,8 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__, ...@@ -80,6 +80,8 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__,
*py__concat__, *py__repeat__, *py__len__, *py__of__, *py__call__, *py__concat__, *py__repeat__, *py__len__, *py__of__, *py__call__,
*py__repr__, *py__str__; *py__repr__, *py__str__;
static PyObject *Acquired=0;
static void static void
init_py_names() init_py_names()
{ {
...@@ -197,6 +199,8 @@ Wrapper_getattro(Wrapper *self, PyObject *oname) ...@@ -197,6 +199,8 @@ Wrapper_getattro(Wrapper *self, PyObject *oname)
char *name; char *name;
if(self->obj && (r=PyObject_GetAttr(self->obj,oname))) if(self->obj && (r=PyObject_GetAttr(self->obj,oname)))
{
if(r != Acquired)
{ {
if(r->ob_type==self->ob_type) if(r->ob_type==self->ob_type)
{ {
...@@ -215,6 +219,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname) ...@@ -215,6 +219,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname)
ASSIGN(r,CallMethodO(r,py__of__,Build("(O)", self), NULL)); ASSIGN(r,CallMethodO(r,py__of__,Build("(O)", self), NULL));
return r; return r;
} }
}
if(self->obj) PyErr_Clear(); if(self->obj) PyErr_Clear();
name=PyString_AsString(oname); name=PyString_AsString(oname);
...@@ -222,6 +227,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname) ...@@ -222,6 +227,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname)
#ifdef IMPLICIT_ACQUIRE___ROLES__ #ifdef IMPLICIT_ACQUIRE___ROLES__
|| strcmp(name,"__roles__")==0 || strcmp(name,"__roles__")==0
#endif #endif
|| r==Acquired
) )
{ {
if(*name++=='a' && *name++=='q' && *name++=='_') if(*name++=='a' && *name++=='q' && *name++=='_')
...@@ -269,6 +275,7 @@ Xaq_getattro(Wrapper *self, PyObject *oname) ...@@ -269,6 +275,7 @@ Xaq_getattro(Wrapper *self, PyObject *oname)
if(self->obj && (r=PyObject_GetAttr(self->obj,oname))) if(self->obj && (r=PyObject_GetAttr(self->obj,oname)))
{ {
if(r==Acquired) return Wrapper_getattro(self,oname);
if(r->ob_type==self->ob_type) if(r->ob_type==self->ob_type)
{ {
if(r->ob_refcnt==1) if(r->ob_refcnt==1)
...@@ -759,7 +766,7 @@ void ...@@ -759,7 +766,7 @@ void
initAcquisition() initAcquisition()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.13 $"; char *rev="$Revision: 1.14 $";
PURE_MIXIN_CLASS(Acquirer, PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly" "Base class for objects that implicitly"
" acquire attributes from containers\n" " acquire attributes from containers\n"
...@@ -771,10 +778,14 @@ initAcquisition() ...@@ -771,10 +778,14 @@ initAcquisition()
UNLESS(ExtensionClassImported) return; UNLESS(ExtensionClassImported) return;
UNLESS(Acquired=PyString_FromStringAndSize(NULL,42)) return;
strcpy(PyString_AsString(Acquired),
"<Special Object Used to Force Acquisition>");
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.13 1997/11/19 13:51:14 jim Exp $\n", "$Id: Acquisition.c,v 1.14 1998/01/05 13:38:31 jim Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
...@@ -790,12 +801,18 @@ initAcquisition() ...@@ -790,12 +801,18 @@ initAcquisition()
PyDict_SetItemString(d,"__version__", PyDict_SetItemString(d,"__version__",
PyString_FromStringAndSize(rev+11,strlen(rev+11)-2)); PyString_FromStringAndSize(rev+11,strlen(rev+11)-2));
PyDict_SetItemString(d,"Acquired",Acquired);
CHECK_FOR_ERRORS("can't initialize module Acquisition"); CHECK_FOR_ERRORS("can't initialize module Acquisition");
} }
/***************************************************************************** /*****************************************************************************
$Log: Acquisition.c,v $ $Log: Acquisition.c,v $
Revision 1.14 1998/01/05 13:38:31 jim
Added special module variable, 'Acquired'. If the value of this
variable is assigned to an attribute, then the value of the attribute
will be acquired, even if it might not otherwize be acquired.
Revision 1.13 1997/11/19 13:51:14 jim Revision 1.13 1997/11/19 13:51:14 jim
Extended compile option to implicitly acquire __roles__ to Extended compile option to implicitly acquire __roles__ to
implicitly acquire roles even for explicit acquirers. implicitly acquire roles even for explicit acquirers.
......
/* /*
$Id: Acquisition.c,v 1.13 1997/11/19 13:51:14 jim Exp $ $Id: Acquisition.c,v 1.14 1998/01/05 13:38:31 jim Exp $
Acquisition Wrappers -- Implementation of acquisition through wrappers Acquisition Wrappers -- Implementation of acquisition through wrappers
...@@ -80,6 +80,8 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__, ...@@ -80,6 +80,8 @@ static PyObject *py__add__, *py__sub__, *py__mul__, *py__div__,
*py__concat__, *py__repeat__, *py__len__, *py__of__, *py__call__, *py__concat__, *py__repeat__, *py__len__, *py__of__, *py__call__,
*py__repr__, *py__str__; *py__repr__, *py__str__;
static PyObject *Acquired=0;
static void static void
init_py_names() init_py_names()
{ {
...@@ -197,6 +199,8 @@ Wrapper_getattro(Wrapper *self, PyObject *oname) ...@@ -197,6 +199,8 @@ Wrapper_getattro(Wrapper *self, PyObject *oname)
char *name; char *name;
if(self->obj && (r=PyObject_GetAttr(self->obj,oname))) if(self->obj && (r=PyObject_GetAttr(self->obj,oname)))
{
if(r != Acquired)
{ {
if(r->ob_type==self->ob_type) if(r->ob_type==self->ob_type)
{ {
...@@ -215,6 +219,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname) ...@@ -215,6 +219,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname)
ASSIGN(r,CallMethodO(r,py__of__,Build("(O)", self), NULL)); ASSIGN(r,CallMethodO(r,py__of__,Build("(O)", self), NULL));
return r; return r;
} }
}
if(self->obj) PyErr_Clear(); if(self->obj) PyErr_Clear();
name=PyString_AsString(oname); name=PyString_AsString(oname);
...@@ -222,6 +227,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname) ...@@ -222,6 +227,7 @@ Wrapper_getattro(Wrapper *self, PyObject *oname)
#ifdef IMPLICIT_ACQUIRE___ROLES__ #ifdef IMPLICIT_ACQUIRE___ROLES__
|| strcmp(name,"__roles__")==0 || strcmp(name,"__roles__")==0
#endif #endif
|| r==Acquired
) )
{ {
if(*name++=='a' && *name++=='q' && *name++=='_') if(*name++=='a' && *name++=='q' && *name++=='_')
...@@ -269,6 +275,7 @@ Xaq_getattro(Wrapper *self, PyObject *oname) ...@@ -269,6 +275,7 @@ Xaq_getattro(Wrapper *self, PyObject *oname)
if(self->obj && (r=PyObject_GetAttr(self->obj,oname))) if(self->obj && (r=PyObject_GetAttr(self->obj,oname)))
{ {
if(r==Acquired) return Wrapper_getattro(self,oname);
if(r->ob_type==self->ob_type) if(r->ob_type==self->ob_type)
{ {
if(r->ob_refcnt==1) if(r->ob_refcnt==1)
...@@ -759,7 +766,7 @@ void ...@@ -759,7 +766,7 @@ void
initAcquisition() initAcquisition()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.13 $"; char *rev="$Revision: 1.14 $";
PURE_MIXIN_CLASS(Acquirer, PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly" "Base class for objects that implicitly"
" acquire attributes from containers\n" " acquire attributes from containers\n"
...@@ -771,10 +778,14 @@ initAcquisition() ...@@ -771,10 +778,14 @@ initAcquisition()
UNLESS(ExtensionClassImported) return; UNLESS(ExtensionClassImported) return;
UNLESS(Acquired=PyString_FromStringAndSize(NULL,42)) return;
strcpy(PyString_AsString(Acquired),
"<Special Object Used to Force Acquisition>");
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.13 1997/11/19 13:51:14 jim Exp $\n", "$Id: Acquisition.c,v 1.14 1998/01/05 13:38:31 jim Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
...@@ -790,12 +801,18 @@ initAcquisition() ...@@ -790,12 +801,18 @@ initAcquisition()
PyDict_SetItemString(d,"__version__", PyDict_SetItemString(d,"__version__",
PyString_FromStringAndSize(rev+11,strlen(rev+11)-2)); PyString_FromStringAndSize(rev+11,strlen(rev+11)-2));
PyDict_SetItemString(d,"Acquired",Acquired);
CHECK_FOR_ERRORS("can't initialize module Acquisition"); CHECK_FOR_ERRORS("can't initialize module Acquisition");
} }
/***************************************************************************** /*****************************************************************************
$Log: Acquisition.c,v $ $Log: Acquisition.c,v $
Revision 1.14 1998/01/05 13:38:31 jim
Added special module variable, 'Acquired'. If the value of this
variable is assigned to an attribute, then the value of the attribute
will be acquired, even if it might not otherwize be acquired.
Revision 1.13 1997/11/19 13:51:14 jim Revision 1.13 1997/11/19 13:51:14 jim
Extended compile option to implicitly acquire __roles__ to Extended compile option to implicitly acquire __roles__ to
implicitly acquire roles even for explicit acquirers. implicitly acquire roles even for explicit acquirers.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment