From: <ti...@co...> - 2009-02-21 02:42:02
|
Author: tismer Date: Sat Feb 21 02:53:34 2009 New Revision: 62068 Modified: psyco/v2/dist/c/Objects/pcompactobject.c psyco/v2/dist/c/Objects/pcompactobject.h Log: added an internal interface to compact objects that avoids promotion Modified: psyco/v2/dist/c/Objects/pcompactobject.c ============================================================================== --- psyco/v2/dist/c/Objects/pcompactobject.c (original) +++ psyco/v2/dist/c/Objects/pcompactobject.c Sat Feb 21 02:53:34 2009 @@ -167,12 +167,14 @@ } } -static vinfo_t* pcompact_getattro(PsycoObject* po, vinfo_t* vk, vinfo_t* vattr) +/* pcompact_getattro with given impl (no promotion needed) */ + +static vinfo_t* pcompact_getattro_impl(PsycoObject* po, vinfo_t* vk, vinfo_t* vattr, + compact_impl_t* impl) { PyTypeObject* tp; PyObject* descr = NULL; descrgetfunc f = NULL; - compact_impl_t* impl; vinfo_t* vresult = NULL; PyObject* name; @@ -217,7 +219,7 @@ } /* read and temporarily promote the k_impl field of the object */ - impl = pcompact_getimpl(po, vk); + impl = impl ? impl : pcompact_getimpl(po, vk); if (impl == NULL) goto done; @@ -257,6 +259,10 @@ return vresult; } +static vinfo_t* pcompact_getattro(PsycoObject* po, vinfo_t* vk, vinfo_t* vattr) +{ + return pcompact_getattro_impl(po, vk, vattr, NULL); +} /***************************************************************/ /*** Meta-implementation of compact_setattro ***/ @@ -357,8 +363,11 @@ return true; } -static bool pcompact_setattro(PsycoObject* po, vinfo_t* vk, PyObject* attr, - vinfo_t* source_vi) +/* pcompact_setattro with given impl (no promotion needed) */ + +static bool pcompact_setattro_impl(PsycoObject* po, vinfo_t* vk, + PyObject* attr, vinfo_t* source_vi, + compact_impl_t** pimpl) { PyTypeObject* tp; PyObject* descr; @@ -414,7 +423,7 @@ } /* read and temporarily promote the k_impl field of the object */ - k_impl = pcompact_getimpl(po, vk); + k_impl = pimpl ? *pimpl : pcompact_getimpl(po, vk); if (k_impl == NULL) return false; @@ -500,9 +509,10 @@ if (source_vi == NULL) { /* deleting a non-existing attribute */ - return psyco_generic_call(po, PyObject_GenericSetAttr, - CfNoReturnValue|CfPyErrIfNonNull, - "vll", vk, attr, (long) NULL) != NULL; + PycException_SetFormat(po, PyExc_AttributeError, + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(attr)); + return false; } /* setting a new attribute */ @@ -557,6 +567,8 @@ vimpl = vinfo_new(CompileTime_New((long) impl)); ok = psyco_put_field(po, vk, COMPACT_impl, vimpl); vinfo_decref(vimpl, po); + if (pimpl) + *pimpl = impl; return ok; error: @@ -564,7 +576,11 @@ return false; } - +static bool pcompact_setattro(PsycoObject* po, vinfo_t* vk, PyObject* attr, + vinfo_t* source_vi) +{ + return pcompact_setattro_impl(po, vk, attr, source_vi, NULL); +} /***************************************************************/ /*** More meta-implementations ***/ @@ -590,6 +606,36 @@ /***************************************************************/ + /*** Interface functions for genstate ***/ + +DEFINEFN void* _pcompact_getimpl(PsycoObject* po, vinfo_t* vk) +{ + return pcompact_getimpl(po, vk); +} + +DEFINEFN bool _pcompact_hasattr(compact_impl_t *impl, PyObject *attr) +{ + for (; impl->attrname != NULL; impl = impl->parent) + if (impl->attrname == attr) + return true; + return false; +} + +DEFINEFN vinfo_t* _pcompact_getattr(PsycoObject* po, void *impl, + vinfo_t* vk, vinfo_t* vattr) +{ + return pcompact_getattro_impl(po, vk, vattr, impl); +} + +DEFINEFN bool _pcompact_setattr(PsycoObject* po, void **impl, vinfo_t* vk, + PyObject* attr, vinfo_t* source_vi) +{ + return pcompact_setattro_impl(po, vk, attr, source_vi, + (compact_impl_t **) impl); +} + + + /***************************************************************/ /*** Virtual-time compact objects ***/ /* A compact object allocated in the heap contains raw data and a pointer Modified: psyco/v2/dist/c/Objects/pcompactobject.h ============================================================================== --- psyco/v2/dist/c/Objects/pcompactobject.h (original) +++ psyco/v2/dist/c/Objects/pcompactobject.h Sat Feb 21 02:53:34 2009 @@ -9,6 +9,14 @@ #include "pobject.h" #include "pabstract.h" +/* interface for genstate handling */ + +EXTERNFN void* _pcompact_getimpl(PsycoObject* po, vinfo_t* vk); +EXTERNFN bool _pcompact_hasattr(void *impl, PyObject *attr); +EXTERNFN vinfo_t* _pcompact_getattr(PsycoObject* po, void *impl, + vinfo_t* vk, vinfo_t* vattr); +EXTERNFN bool _pcompact_setattr(PsycoObject* po, void **impl, vinfo_t* vk, + PyObject* attr, vinfo_t* source_vi); /***************************************************************/ /* virtual compact objects. */ |