Index: TODO =================================================================== diff -u -rb3b35e7780dcdaf8c2d07aaba4b01128f9dd2683 -r76bdfab614f658464ee9e020d0275868cdd61026 --- TODO (.../TODO) (revision b3b35e7780dcdaf8c2d07aaba4b01128f9dd2683) +++ TODO (.../TODO) (revision 76bdfab614f658464ee9e020d0275868cdd61026) @@ -5338,6 +5338,10 @@ rootclasses like nx::Object / xotcl::Object), we are again on the same level as before (actually slightly faster). +- use functions IsRootClass(), IsRootMetaClass() and IsBaseClass() + to access object/class properties + + ======================================================================== TODO: Index: generic/nsf.c =================================================================== diff -u -rb3b35e7780dcdaf8c2d07aaba4b01128f9dd2683 -r76bdfab614f658464ee9e020d0275868cdd61026 --- generic/nsf.c (.../nsf.c) (revision b3b35e7780dcdaf8c2d07aaba4b01128f9dd2683) +++ generic/nsf.c (.../nsf.c) (revision 76bdfab614f658464ee9e020d0275868cdd61026) @@ -305,7 +305,9 @@ nonnull(1) nonnull(2) nonnull(11); /* properties of objects and classes */ -static int IsBaseClass(NsfObject *cl) nonnull(1); +static int IsRootClass(NsfClass *cl) nonnull(1) pure; +static int IsRootMetaClass(NsfClass *cl) nonnull(1) pure; +static int IsBaseClass(NsfObject *cl) nonnull(1) pure; static int IsMetaClass(Tcl_Interp *interp, NsfClass *cl, int withMixins) nonnull(1) nonnull(2); static int IsSubType(NsfClass *subcl, NsfClass *cl) nonnull(1) nonnull(2); static NsfClass *DefaultSuperClass(Tcl_Interp *interp, NsfClass *cl, NsfClass *mcl, int isMeta) @@ -7548,7 +7550,7 @@ if (mCl) { for (pl = PrecedenceOrder(mCl); pl; pl = pl->nextPtr) { - if ((pl->cl->object.flags & NSF_IS_ROOT_CLASS) == 0) { + if (IsRootClass(pl->cl) == 0) { NsfClassOpt *opt = pl->cl->opt; /* fprintf(stderr, "find %p %s in checklist 1 %p\n", @@ -8888,7 +8890,7 @@ pcl = PrecedenceOrder(object->cl); for (; pcl; pcl = pcl->nextPtr) { - if (withRootClass == 0 && pcl->cl->object.flags & NSF_IS_ROOT_CLASS) { + if (withRootClass == 0 && IsRootClass(pcl->cl)) { continue; } if (pattern && !Tcl_StringMatch(ClassName(pcl->cl), pattern)) { @@ -17823,8 +17825,7 @@ /* * Remove the instance, but not for ::Class/::Object */ - if ((object->flags & NSF_IS_ROOT_CLASS) == 0 && - (object->flags & NSF_IS_ROOT_META_CLASS) == 0 ) { + if (IsBaseClass(object) == 0) { if (!softrecreate) { RemoveInstance(object, object->cl); @@ -18357,7 +18358,7 @@ /* * Is this already the root metaclass ? */ - if (mcl->object.cl->object.flags & NSF_IS_ROOT_META_CLASS) { + if (IsRootMetaClass(mcl->object.cl)) { return mcl->object.cl; } } @@ -18371,11 +18372,11 @@ sc->cl->object.flags & NSF_IS_ROOT_META_CLASS, sc->cl->object.flags & NSF_IS_ROOT_CLASS); */ if (isMeta) { - if (sc->cl->object.flags & NSF_IS_ROOT_META_CLASS) { + if (IsRootMetaClass(sc->cl)) { return sc->cl; } } else { - if (sc->cl->object.flags & NSF_IS_ROOT_CLASS) { + if (IsRootClass(sc->cl)) { /* fprintf(stderr, "found root class %p %s\n", sc->cl, ClassName(sc->cl)); */ return sc->cl; } @@ -18501,7 +18502,7 @@ /* * We do not have to reclassing in case, cl is a root class */ - if ((cl->object.flags & NSF_IS_ROOT_CLASS) == 0) { + if (IsRootClass(cl) == 0) { Tcl_HashTable *instanceTablePtr = &cl->instances; Tcl_HashSearch hSrch; Tcl_HashEntry *hPtr; @@ -18552,7 +18553,7 @@ * class as superClasses * -> don't do that for Object itself! */ - if (subClass->super == 0 && (cl->object.flags & NSF_IS_ROOT_CLASS) == 0) { + if (subClass->super == 0 && IsRootClass(cl) == 0) { /* fprintf(stderr,"subClass %p %s baseClass %p %s\n", cl, ClassName(cl), baseClass, ClassName(baseClass)); */ AddSuper(subClass, baseClass); @@ -18989,7 +18990,7 @@ /* *---------------------------------------------------------------------- - * HasRootMetaFlag -- + * IsRootMetaClass -- * * Check, of the class has the Root meta class flag set. * @@ -19001,10 +19002,8 @@ * *---------------------------------------------------------------------- */ -static int HasRootMetaFlag(NsfClass *cl) nonnull(1); - static int -HasRootMetaFlag(NsfClass *cl) { +IsRootMetaClass(NsfClass *cl) { assert(cl); @@ -19030,11 +19029,34 @@ assert(object); - return object->flags & (NSF_IS_ROOT_META_CLASS|NSF_IS_ROOT_CLASS); + return object->flags & (NSF_IS_ROOT_CLASS|NSF_IS_ROOT_META_CLASS); } /* *---------------------------------------------------------------------- + * IsRootClass -- + * + * Check, whether the object is a root class. + * + * Results: + * Boolean + * + * Side effects: + * none + * + *---------------------------------------------------------------------- + */ +static int +IsRootClass(NsfClass *cls) { + + assert(cls); + + return cls->object.flags & (NSF_IS_ROOT_CLASS); +} + + +/* + *---------------------------------------------------------------------- * IsMetaClass -- * * Check, whether the object is a meta class. Optionally, mixins are @@ -19056,13 +19078,13 @@ assert(cl); /* is the class the most general meta-class? */ - if (HasRootMetaFlag(cl)) { + if (IsRootMetaClass(cl)) { return 1; } /* is the class a subclass of a meta-class? */ for (pl = PrecedenceOrder(cl); pl; pl = pl->nextPtr) { - if (HasRootMetaFlag(pl->cl)) { + if (IsRootMetaClass(pl->cl)) { return 1; } } @@ -25517,7 +25539,7 @@ */ if (likely(RUNTIME_STATE(interp)->exitHandlerDestroyRound == NSF_EXITHANDLER_OFF) && isMixinOf - && (cl->object.flags & NSF_IS_ROOT_CLASS) == 0) { + && (IsRootClass(cl)) == 0) { Tcl_HashTable objTable, *commandTable = &objTable; Tcl_HashSearch hSrch; Index: generic/nsfInt.h =================================================================== diff -u -rd9344280c05990c0254aa652a08a09da3e5822b1 -r76bdfab614f658464ee9e020d0275868cdd61026 --- generic/nsfInt.h (.../nsfInt.h) (revision d9344280c05990c0254aa652a08a09da3e5822b1) +++ generic/nsfInt.h (.../nsfInt.h) (revision 76bdfab614f658464ee9e020d0275868cdd61026) @@ -76,6 +76,12 @@ # define likely(x) (x) #endif +#if __GNUC_PREREQ(2, 96) +# define pure __attribute__((pure)) +#else +# define pure +#endif + #if __GNUC_PREREQ(3, 3) # define nonnull(ARGS) __attribute__((__nonnull__(ARGS))) #else @@ -88,6 +94,12 @@ # define returns_nonnull #endif +#if __GNUC_PREREQ(4, 9) +# define returns_nonnull __attribute__((returns_nonnull)) +#else +# define returns_nonnull +#endif + /* * Tries to use gcc __attribute__ unused and mangles the name, so the * attribute could not be used, if declared as unused.