Index: TODO =================================================================== diff -u -r2767762e5ef68bee6e82cbff0d69f54b01c37a13 -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- TODO (.../TODO) (revision 2767762e5ef68bee6e82cbff0d69f54b01c37a13) +++ TODO (.../TODO) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -2003,6 +2003,11 @@ - xotcl2.tcl: fix the default init handler - nsf.c: provide warnings when unchecked parameter values might conflict with nonpos args +- provide a generic logging interface + * predefined for plain Tcl and aolserver/naviserver + * C-level: NsfLog() + * Tcl-level: ::nsf::log + TODO: - "-returns" Index: generic/nsf.c =================================================================== diff -u -r2767762e5ef68bee6e82cbff0d69f54b01c37a13 -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/nsf.c (.../nsf.c) (revision 2767762e5ef68bee6e82cbff0d69f54b01c37a13) +++ generic/nsf.c (.../nsf.c) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -274,7 +274,55 @@ static int NextSearchAndInvoke(Tcl_Interp *interp, CONST char *methodName, int objc, Tcl_Obj *CONST objv[], NsfCallStackContent *cscPtr, int freeArgumentVector); + /* + *---------------------------------------------------------------------- + * + * NsfLog -- + * + * Produce a formatted warning by calling an external function + * ::nsf::log. It is defined static to allow for inlining. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static void +NsfLog(Tcl_Interp *interp, int requiredLevel, CONST char *fmt, ...) { + va_list ap; + + if (RUNTIME_STATE(interp)->debugLevel >= requiredLevel) { + CONST char *level = requiredLevel == NSF_LOG_WARN ? "Warning" : "Inform"; + Tcl_DString cmdString, ds; + + Tcl_DStringInit(&ds); + va_start(ap, fmt); + NsfDStringPrintf(&ds, fmt, ap); + va_end(ap); + + Tcl_DStringInit(&cmdString); + Tcl_DStringAppendElement(&cmdString, "nsf::log"); + Tcl_DStringAppendElement(&cmdString, level); + Tcl_DStringAppendElement(&cmdString, Tcl_DStringValue(&ds)); + + int result = Tcl_EvalEx(interp, Tcl_DStringValue(&cmdString), Tcl_DStringLength(&cmdString), 0); + if (result == TCL_ERROR) { + static char cmdString[] = + "puts stderr \"Error in logger\n\ + $::errorCode $::errorInfo\""; + Tcl_EvalEx(interp, cmdString, -1, 0); + } + Tcl_DStringFree(&cmdString); + Tcl_DStringFree(&ds); + } +} + +/* * argv parsing */ @@ -2832,16 +2880,16 @@ } else { if (object->teardown && !(object->flags & NSF_DESTROY_CALLED)) { int result = DispatchDestroyMethod(interp, object, 0); + if (result != TCL_OK) { - if (RUNTIME_STATE(interp)->debugLevel > 1) { - fprintf(stderr, "Warning: destroy failed for object %s, perform low level deletion\n", - ObjectName(object)); - } /* * The destroy method failed. However, we have to remove * the command anyway, since its parent is currently being * deleted. */ + NsfLog(interp, NSF_LOG_INFORM, "Destroy failed for object %s, perform low level deletion", + ObjectName(object)); + if (object->teardown) { CallStackDestroyObject(interp, object); } @@ -4529,19 +4577,15 @@ int new; if (inst->flags & NSF_TCL_DELETE) { - if (RUNTIME_STATE(interp)->debugLevel > 1) { - fprintf(stderr, "Warning: Object %s is apparently deleted\n", ObjectName(inst)); - } + NsfLog(interp, NSF_LOG_INFORM, "Object %s is apparently deleted", ObjectName(inst)); continue; } cmdPtr = (Command *)inst->id; assert(cmdPtr); if (cmdPtr && (cmdPtr->nsPtr->flags & NS_DYING)) { - if (RUNTIME_STATE(interp)->debugLevel > 0) { - fprintf(stderr, "Warning: Namespace of %s is apparently deleted\n", ObjectName(inst)); - } + NsfLog(interp, NSF_LOG_WARN, "Namespace of %s is apparently deleted", ObjectName(inst)); continue; } @@ -7531,9 +7575,7 @@ * {1} Class ::State * {2} Class ::State -parameter x */ - if (RUNTIME_STATE(interp)->debugLevel > 1) { - fprintf(stderr, "Warning: don't invoke object %s this way. Register object via alias...\n", methodName); - } + NsfLog(interp, NSF_LOG_INFORM, "Don't invoke object %s this way. Register object via alias...", methodName); cmd = NULL; } else if (IsClassNsName(methodName)) { @@ -7579,11 +7621,9 @@ NsfObject *lastSelf = GetSelfObj(interp); if (object != lastSelf) { - if (RUNTIME_STATE(interp)->debugLevel > 0) { - fprintf(stderr, "Warning: '%s %s' fails since method %s.%s is protected.\n", - ObjectName(object), methodName, - cl ? ClassName(cl) : ObjectName(object), methodName); - } + NsfLog(interp, NSF_LOG_WARN, "'%s %s' fails since method %s.%s is protected", + ObjectName(object), methodName, + cl ? ClassName(cl) : ObjectName(object), methodName); /* reset cmd, since it is still unknown */ cmd = NULL; } @@ -7947,8 +7987,8 @@ && (pPtr->flags & NSF_ARG_CHECK_NONPOS) && isalpha(*(value+1)) && strchr(value+1, ' ') == 0) { - fprintf(stderr, "Warning: value '%s' of parameter %s could be a non-positional argument\n", - value, pPtr->name); + NsfLog(interp, NSF_LOG_WARN, "Value '%s' of parameter %s could be a non-positional argument", + value, pPtr->name); } } @@ -8457,21 +8497,18 @@ if (cmd == NULL) { if (paramPtr->converter == ConvertViaCmd) { - if (RUNTIME_STATE(interp)->debugLevel > 0) { - fprintf(stderr, "Warning: could not find value checker %s defined on %s\n", - converterNameString, ObjectName(paramObj)); - } + NsfLog(interp, NSF_LOG_WARN, "Could not find value checker %s defined on %s", + converterNameString, ObjectName(paramObj)); + paramPtr->flags |= NSF_ARG_CURRENTLY_UNKNOWN; /* TODO: for the time being, we do not return an error here */ } } else if (paramPtr->converter != ConvertViaCmd && strcmp(ObjStr(paramPtr->slotObj), NsfGlobalStrings[NSF_METHOD_PARAMETER_SLOT_OBJ]) != 0) { - if (RUNTIME_STATE(interp)->debugLevel > 0) { - fprintf(stderr, "Warning: checker method %s defined on %s shadows built-in converter\n", - converterNameString, ObjectName(paramObj)); - } + NsfLog(interp, NSF_LOG_WARN, "Checker method %s defined on %s shadows built-in converter", + converterNameString, ObjectName(paramObj)); if (paramPtr->converterName == NULL) { paramPtr->converterName = converterNameObj; @@ -12499,12 +12536,9 @@ } } else { /* should never happen */ - if (RUNTIME_STATE(interp)->debugLevel > 0) { - fprintf(stderr, "Warning: Could not obtain alias definition for %s. " - "Maybe someone deleted the alias %s for object %s?\n", - methodName, - methodName, ObjectName(regObject)); - } + NsfLog(interp, NSF_LOG_WARN, "Could not obtain alias definition for %s. " + "Maybe someone deleted the alias %s for object %s?", + methodName, methodName, ObjectName(regObject)); Tcl_ResetResult(interp); } } @@ -13329,14 +13363,12 @@ GetClassFromObj(interp, object, &theobj, NULL); GetClassFromObj(interp, class, &thecls, NULL); + if (theobj || thecls) { - ObjectSystemFree(interp, osPtr); - if (RUNTIME_STATE(interp)->debugLevel > 0) { - fprintf(stderr, "Warning: Base class exists already; ignoring definition.\n"); - } + NsfLog(interp, NSF_LOG_WARN, "Base %s class exists already; ignoring definition", + theobj ? object : class); return TCL_OK; - /* fprintf(stderr, "CreateObjectSystem created base classes \n"); */ } if (systemMethodsObj) { @@ -17291,12 +17323,12 @@ * value to ensure deletion. */ if (object->refCount != 1) { - if (RUNTIME_STATE(interp)->debugLevel > 0) { - fprintf(stderr, "Warning: have to fix refcount for obj %p refcount %d",object, object->refCount); - if (object->refCount > 1) { - fprintf(stderr, " (name %s)", ObjectName(object)); - } - fprintf(stderr, "\n"); + if (object->refCount > 1) { + NsfLog(interp, NSF_LOG_WARN, "Have to fix refcount for obj %p refcount %d (name %s)", + object, object->refCount, ObjectName(object)); + } else { + NsfLog(interp, NSF_LOG_WARN, "Have to fix refcount for obj %p refcount %d", + object, object->refCount); } object->refCount = 1; } Index: generic/nsf.decls =================================================================== diff -u -r14965323980c2235c37b67ddbb19343ddbdaa41c -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/nsf.decls (.../nsf.decls) (revision 14965323980c2235c37b67ddbb19343ddbdaa41c) +++ generic/nsf.decls (.../nsf.decls) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -43,7 +43,7 @@ int NsfDeleteObject(Tcl_Interp *interp, struct Nsf_Object *obj) } declare 7 generic { - int NsfRemoveObjectMethod(Tcl_Interp *interp,struct Nsf_Object *obj, CONST char *nm) + int NsfRemoveObjectMethod(Tcl_Interp *interp, struct Nsf_Object *obj, CONST char *nm) } declare 8 generic { int NsfRemoveClassMethod(Tcl_Interp *interp, struct Nsf_Class *cl, CONST char *nm) @@ -58,12 +58,12 @@ } declare 11 generic { Tcl_Obj *Nsf_ObjSetVar2(struct Nsf_Object *obj, - Tcl_Interp *interp,Tcl_Obj *name1,Tcl_Obj *name2, - Tcl_Obj *value,int flgs) + Tcl_Interp *interp, Tcl_Obj *name1, Tcl_Obj *name2, + Tcl_Obj *value, int flgs) } declare 12 generic { Tcl_Obj *Nsf_ObjGetVar2(struct Nsf_Object *obj, - Tcl_Interp *interp,Tcl_Obj *name1,Tcl_Obj *name2, + Tcl_Interp *interp, Tcl_Obj *name1, Tcl_Obj *name2, int flgs) } declare 13 generic { @@ -78,59 +78,62 @@ int NsfVarErrMsg(Tcl_Interp *interp, ...) } declare 16 generic { + void NsfDStringPrintf(Tcl_DString *dsPtr, CONST char *fmt, va_list apSrc) +} +declare 17 generic { int NsfErrInProc (Tcl_Interp *interp, Tcl_Obj *objName, Tcl_Obj *clName, CONST char *procName) } -declare 17 generic { +declare 18 generic { int NsfErrBadVal_(Tcl_Interp *interp, char *expected, char *value) } -declare 18 generic { +declare 19 generic { int NsfObjErrType(Tcl_Interp *interp, Tcl_Obj *nm, char *wt, char *parameterName) } -declare 19 generic { +declare 20 generic { void NsfStackDump (Tcl_Interp *interp) } -declare 20 generic { +declare 21 generic { void NsfSetObjClientData(Nsf_Object *obj, ClientData data) } -declare 21 generic { +declare 22 generic { ClientData NsfGetObjClientData(Nsf_Object *obj) } -declare 22 generic { +declare 23 generic { void NsfSetClassClientData(Nsf_Class *cl, ClientData data) } -declare 23 generic { +declare 24 generic { ClientData NsfGetClassClientData(Nsf_Class *cl) } -declare 24 generic { +declare 25 generic { void NsfRequireObjNamespace(Tcl_Interp *interp, Nsf_Object *obj) } -declare 25 generic { +declare 26 generic { int NsfErrBadVal(Tcl_Interp *interp, char *context, char *expected, CONST char *value) } -declare 26 generic { +declare 27 generic { int NsfNextObjCmd(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) } -declare 27 generic { +declare 28 generic { int NsfCallMethodWithArgs(ClientData cd, Tcl_Interp *interp, Tcl_Obj *method, Tcl_Obj *arg, int objc, Tcl_Obj *CONST objv[], int flags) } -declare 28 generic { +declare 29 generic { int NsfObjErrArgCnt(Tcl_Interp *interp, Tcl_Obj *cmdName, Tcl_Obj *methodName, char *arglist) } -declare 29 generic { +declare 30 generic { int NsfAddObjectMethod(Tcl_Interp *interp, struct Nsf_Object *obj, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags) } -declare 30 generic { +declare 31 generic { int NsfAddClassMethod(Tcl_Interp *interp, struct Nsf_Class *cl, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags) } -declare 31 generic { +declare 32 generic { int NsfCreate(Tcl_Interp *in, Nsf_Class *class, Tcl_Obj *name, ClientData data, int objc, Tcl_Obj *CONST objv[]) } Index: generic/nsf.tcl =================================================================== diff -u -r6c2e8f94be1ba335ff90d4b6b5132c98a9f5c242 -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/nsf.tcl (.../nsf.tcl) (revision 6c2e8f94be1ba335ff90d4b6b5132c98a9f5c242) +++ generic/nsf.tcl (.../nsf.tcl) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -77,6 +77,19 @@ } # initialize exit handler ::nsf::exithandler unset + + # + # logger + # + if {[info command ::ns_log] ne ""} { + proc ::nsf::log {level msg} { + ns_log $level "nsf: $msg" + } + } else { + proc ::nsf::log {level msg} { + puts stderr "$level: $msg" + } + } # # determine platform aware temp directory Index: generic/nsfDecls.h =================================================================== diff -u -r9b7a590f8f91f52d2d5934b7509eac5fcd7fb91e -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/nsfDecls.h (.../nsfDecls.h) (revision 9b7a590f8f91f52d2d5934b7509eac5fcd7fb91e) +++ generic/nsfDecls.h (.../nsfDecls.h) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -115,100 +115,106 @@ /* 15 */ EXTERN int NsfVarErrMsg(Tcl_Interp *interp, ...); #endif +#ifndef NsfDStringPrintf_TCL_DECLARED +#define NsfDStringPrintf_TCL_DECLARED +/* 16 */ +EXTERN void NsfDStringPrintf(Tcl_DString *dsPtr, CONST char *fmt, + va_list apSrc); +#endif #ifndef NsfErrInProc_TCL_DECLARED #define NsfErrInProc_TCL_DECLARED -/* 16 */ +/* 17 */ EXTERN int NsfErrInProc(Tcl_Interp *interp, Tcl_Obj *objName, Tcl_Obj *clName, CONST char *procName); #endif #ifndef NsfErrBadVal__TCL_DECLARED #define NsfErrBadVal__TCL_DECLARED -/* 17 */ +/* 18 */ EXTERN int NsfErrBadVal_(Tcl_Interp *interp, char *expected, char *value); #endif #ifndef NsfObjErrType_TCL_DECLARED #define NsfObjErrType_TCL_DECLARED -/* 18 */ +/* 19 */ EXTERN int NsfObjErrType(Tcl_Interp *interp, Tcl_Obj *nm, char *wt, char *parameterName); #endif #ifndef NsfStackDump_TCL_DECLARED #define NsfStackDump_TCL_DECLARED -/* 19 */ +/* 20 */ EXTERN void NsfStackDump(Tcl_Interp *interp); #endif #ifndef NsfSetObjClientData_TCL_DECLARED #define NsfSetObjClientData_TCL_DECLARED -/* 20 */ +/* 21 */ EXTERN void NsfSetObjClientData(Nsf_Object *obj, ClientData data); #endif #ifndef NsfGetObjClientData_TCL_DECLARED #define NsfGetObjClientData_TCL_DECLARED -/* 21 */ +/* 22 */ EXTERN ClientData NsfGetObjClientData(Nsf_Object *obj); #endif #ifndef NsfSetClassClientData_TCL_DECLARED #define NsfSetClassClientData_TCL_DECLARED -/* 22 */ +/* 23 */ EXTERN void NsfSetClassClientData(Nsf_Class *cl, ClientData data); #endif #ifndef NsfGetClassClientData_TCL_DECLARED #define NsfGetClassClientData_TCL_DECLARED -/* 23 */ +/* 24 */ EXTERN ClientData NsfGetClassClientData(Nsf_Class *cl); #endif #ifndef NsfRequireObjNamespace_TCL_DECLARED #define NsfRequireObjNamespace_TCL_DECLARED -/* 24 */ +/* 25 */ EXTERN void NsfRequireObjNamespace(Tcl_Interp *interp, Nsf_Object *obj); #endif #ifndef NsfErrBadVal_TCL_DECLARED #define NsfErrBadVal_TCL_DECLARED -/* 25 */ +/* 26 */ EXTERN int NsfErrBadVal(Tcl_Interp *interp, char *context, char *expected, CONST char *value); #endif #ifndef NsfNextObjCmd_TCL_DECLARED #define NsfNextObjCmd_TCL_DECLARED -/* 26 */ +/* 27 */ EXTERN int NsfNextObjCmd(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); #endif #ifndef NsfCallMethodWithArgs_TCL_DECLARED #define NsfCallMethodWithArgs_TCL_DECLARED -/* 27 */ +/* 28 */ EXTERN int NsfCallMethodWithArgs(ClientData cd, Tcl_Interp *interp, Tcl_Obj *method, Tcl_Obj *arg, int objc, Tcl_Obj *CONST objv[], int flags); #endif #ifndef NsfObjErrArgCnt_TCL_DECLARED #define NsfObjErrArgCnt_TCL_DECLARED -/* 28 */ +/* 29 */ EXTERN int NsfObjErrArgCnt(Tcl_Interp *interp, Tcl_Obj *cmdName, Tcl_Obj *methodName, char *arglist); #endif #ifndef NsfAddObjectMethod_TCL_DECLARED #define NsfAddObjectMethod_TCL_DECLARED -/* 29 */ +/* 30 */ EXTERN int NsfAddObjectMethod(Tcl_Interp *interp, struct Nsf_Object *obj, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags); #endif #ifndef NsfAddClassMethod_TCL_DECLARED #define NsfAddClassMethod_TCL_DECLARED -/* 30 */ +/* 31 */ EXTERN int NsfAddClassMethod(Tcl_Interp *interp, struct Nsf_Class *cl, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags); #endif #ifndef NsfCreate_TCL_DECLARED #define NsfCreate_TCL_DECLARED -/* 31 */ +/* 32 */ EXTERN int NsfCreate(Tcl_Interp *in, Nsf_Class *class, Tcl_Obj *name, ClientData data, int objc, Tcl_Obj *CONST objv[]); @@ -238,22 +244,23 @@ int (*nsfUnsetInstVar2) (struct Nsf_Object *obj, Tcl_Interp *interp, CONST char *name1, CONST char *name2, int flgs); /* 13 */ int (*nsfErrMsg) (Tcl_Interp *interp, char *msg, Tcl_FreeProc *type); /* 14 */ int (*nsfVarErrMsg) (Tcl_Interp *interp, ...); /* 15 */ - int (*nsfErrInProc) (Tcl_Interp *interp, Tcl_Obj *objName, Tcl_Obj *clName, CONST char *procName); /* 16 */ - int (*nsfErrBadVal_) (Tcl_Interp *interp, char *expected, char *value); /* 17 */ - int (*nsfObjErrType) (Tcl_Interp *interp, Tcl_Obj *nm, char *wt, char *parameterName); /* 18 */ - void (*nsfStackDump) (Tcl_Interp *interp); /* 19 */ - void (*nsfSetObjClientData) (Nsf_Object *obj, ClientData data); /* 20 */ - ClientData (*nsfGetObjClientData) (Nsf_Object *obj); /* 21 */ - void (*nsfSetClassClientData) (Nsf_Class *cl, ClientData data); /* 22 */ - ClientData (*nsfGetClassClientData) (Nsf_Class *cl); /* 23 */ - void (*nsfRequireObjNamespace) (Tcl_Interp *interp, Nsf_Object *obj); /* 24 */ - int (*nsfErrBadVal) (Tcl_Interp *interp, char *context, char *expected, CONST char *value); /* 25 */ - int (*nsfNextObjCmd) (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); /* 26 */ - int (*nsfCallMethodWithArgs) (ClientData cd, Tcl_Interp *interp, Tcl_Obj *method, Tcl_Obj *arg, int objc, Tcl_Obj *CONST objv[], int flags); /* 27 */ - int (*nsfObjErrArgCnt) (Tcl_Interp *interp, Tcl_Obj *cmdName, Tcl_Obj *methodName, char *arglist); /* 28 */ - int (*nsfAddObjectMethod) (Tcl_Interp *interp, struct Nsf_Object *obj, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags); /* 29 */ - int (*nsfAddClassMethod) (Tcl_Interp *interp, struct Nsf_Class *cl, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags); /* 30 */ - int (*nsfCreate) (Tcl_Interp *in, Nsf_Class *class, Tcl_Obj *name, ClientData data, int objc, Tcl_Obj *CONST objv[]); /* 31 */ + void (*nsfDStringPrintf) (Tcl_DString *dsPtr, CONST char *fmt, va_list apSrc); /* 16 */ + int (*nsfErrInProc) (Tcl_Interp *interp, Tcl_Obj *objName, Tcl_Obj *clName, CONST char *procName); /* 17 */ + int (*nsfErrBadVal_) (Tcl_Interp *interp, char *expected, char *value); /* 18 */ + int (*nsfObjErrType) (Tcl_Interp *interp, Tcl_Obj *nm, char *wt, char *parameterName); /* 19 */ + void (*nsfStackDump) (Tcl_Interp *interp); /* 20 */ + void (*nsfSetObjClientData) (Nsf_Object *obj, ClientData data); /* 21 */ + ClientData (*nsfGetObjClientData) (Nsf_Object *obj); /* 22 */ + void (*nsfSetClassClientData) (Nsf_Class *cl, ClientData data); /* 23 */ + ClientData (*nsfGetClassClientData) (Nsf_Class *cl); /* 24 */ + void (*nsfRequireObjNamespace) (Tcl_Interp *interp, Nsf_Object *obj); /* 25 */ + int (*nsfErrBadVal) (Tcl_Interp *interp, char *context, char *expected, CONST char *value); /* 26 */ + int (*nsfNextObjCmd) (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); /* 27 */ + int (*nsfCallMethodWithArgs) (ClientData cd, Tcl_Interp *interp, Tcl_Obj *method, Tcl_Obj *arg, int objc, Tcl_Obj *CONST objv[], int flags); /* 28 */ + int (*nsfObjErrArgCnt) (Tcl_Interp *interp, Tcl_Obj *cmdName, Tcl_Obj *methodName, char *arglist); /* 29 */ + int (*nsfAddObjectMethod) (Tcl_Interp *interp, struct Nsf_Object *obj, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags); /* 30 */ + int (*nsfAddClassMethod) (Tcl_Interp *interp, struct Nsf_Class *cl, CONST char *nm, Tcl_ObjCmdProc *proc, ClientData cd, Tcl_CmdDeleteProc *dp, int flags); /* 31 */ + int (*nsfCreate) (Tcl_Interp *in, Nsf_Class *class, Tcl_Obj *name, ClientData data, int objc, Tcl_Obj *CONST objv[]); /* 32 */ } NsfStubs; #ifdef __cplusplus @@ -331,69 +338,73 @@ #define NsfVarErrMsg \ (nsfStubsPtr->nsfVarErrMsg) /* 15 */ #endif +#ifndef NsfDStringPrintf +#define NsfDStringPrintf \ + (nsfStubsPtr->nsfDStringPrintf) /* 16 */ +#endif #ifndef NsfErrInProc #define NsfErrInProc \ - (nsfStubsPtr->nsfErrInProc) /* 16 */ + (nsfStubsPtr->nsfErrInProc) /* 17 */ #endif #ifndef NsfErrBadVal_ #define NsfErrBadVal_ \ - (nsfStubsPtr->nsfErrBadVal_) /* 17 */ + (nsfStubsPtr->nsfErrBadVal_) /* 18 */ #endif #ifndef NsfObjErrType #define NsfObjErrType \ - (nsfStubsPtr->nsfObjErrType) /* 18 */ + (nsfStubsPtr->nsfObjErrType) /* 19 */ #endif #ifndef NsfStackDump #define NsfStackDump \ - (nsfStubsPtr->nsfStackDump) /* 19 */ + (nsfStubsPtr->nsfStackDump) /* 20 */ #endif #ifndef NsfSetObjClientData #define NsfSetObjClientData \ - (nsfStubsPtr->nsfSetObjClientData) /* 20 */ + (nsfStubsPtr->nsfSetObjClientData) /* 21 */ #endif #ifndef NsfGetObjClientData #define NsfGetObjClientData \ - (nsfStubsPtr->nsfGetObjClientData) /* 21 */ + (nsfStubsPtr->nsfGetObjClientData) /* 22 */ #endif #ifndef NsfSetClassClientData #define NsfSetClassClientData \ - (nsfStubsPtr->nsfSetClassClientData) /* 22 */ + (nsfStubsPtr->nsfSetClassClientData) /* 23 */ #endif #ifndef NsfGetClassClientData #define NsfGetClassClientData \ - (nsfStubsPtr->nsfGetClassClientData) /* 23 */ + (nsfStubsPtr->nsfGetClassClientData) /* 24 */ #endif #ifndef NsfRequireObjNamespace #define NsfRequireObjNamespace \ - (nsfStubsPtr->nsfRequireObjNamespace) /* 24 */ + (nsfStubsPtr->nsfRequireObjNamespace) /* 25 */ #endif #ifndef NsfErrBadVal #define NsfErrBadVal \ - (nsfStubsPtr->nsfErrBadVal) /* 25 */ + (nsfStubsPtr->nsfErrBadVal) /* 26 */ #endif #ifndef NsfNextObjCmd #define NsfNextObjCmd \ - (nsfStubsPtr->nsfNextObjCmd) /* 26 */ + (nsfStubsPtr->nsfNextObjCmd) /* 27 */ #endif #ifndef NsfCallMethodWithArgs #define NsfCallMethodWithArgs \ - (nsfStubsPtr->nsfCallMethodWithArgs) /* 27 */ + (nsfStubsPtr->nsfCallMethodWithArgs) /* 28 */ #endif #ifndef NsfObjErrArgCnt #define NsfObjErrArgCnt \ - (nsfStubsPtr->nsfObjErrArgCnt) /* 28 */ + (nsfStubsPtr->nsfObjErrArgCnt) /* 29 */ #endif #ifndef NsfAddObjectMethod #define NsfAddObjectMethod \ - (nsfStubsPtr->nsfAddObjectMethod) /* 29 */ + (nsfStubsPtr->nsfAddObjectMethod) /* 30 */ #endif #ifndef NsfAddClassMethod #define NsfAddClassMethod \ - (nsfStubsPtr->nsfAddClassMethod) /* 30 */ + (nsfStubsPtr->nsfAddClassMethod) /* 31 */ #endif #ifndef NsfCreate #define NsfCreate \ - (nsfStubsPtr->nsfCreate) /* 31 */ + (nsfStubsPtr->nsfCreate) /* 32 */ #endif #endif /* defined(USE_NSF_STUBS) && !defined(USE_NSF_STUB_PROCS) */ Index: generic/nsfError.c =================================================================== diff -u -rcb7e3a02c1964d38d85c7e129027fc1b3225d3e6 -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/nsfError.c (.../nsfError.c) (revision cb7e3a02c1964d38d85c7e129027fc1b3225d3e6) +++ generic/nsfError.c (.../nsfError.c) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -13,6 +13,39 @@ #include "nsfInt.h" + +/* + *---------------------------------------------------------------------- + * + * NsfDStringPrintf -- + * + * Set a Tcl_DString to a formatted value. This function + * currently copies at most TCL_DSTRING_STATIC_SIZE characters + * into the DString (this limit might be lifted in the future) + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +void +NsfDStringPrintf(Tcl_DString *dsPtr, CONST char *fmt, va_list apSrc) +{ + int result; + va_list ap; + + va_copy(ap, apSrc); + result = vsnprintf(Tcl_DStringValue(dsPtr), TCL_DSTRING_STATIC_SIZE, fmt, ap); + va_end(ap); + + Tcl_DStringSetLength(dsPtr, result < TCL_DSTRING_STATIC_SIZE ? result : TCL_DSTRING_STATIC_SIZE); +} + + int NsfErrMsg(Tcl_Interp *interp, char *msg, Tcl_FreeProc* type) { Tcl_SetResult(interp, msg, type); Index: generic/nsfInt.h =================================================================== diff -u -r2767762e5ef68bee6e82cbff0d69f54b01c37a13 -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/nsfInt.h (.../nsfInt.h) (revision 2767762e5ef68bee6e82cbff0d69f54b01c37a13) +++ generic/nsfInt.h (.../nsfInt.h) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -840,6 +840,9 @@ #define FRAME_IS_NSF_METHOD 0x20000 #define FRAME_IS_NSF_CMETHOD 0x40000 +#define NSF_LOG_INFORM 2 +#define NSF_LOG_WARN 1 + #if !defined(NDEBUG) /*# define NSF_INLINE*/ #endif Index: generic/nsfStubInit.c =================================================================== diff -u -r14965323980c2235c37b67ddbb19343ddbdaa41c -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/nsfStubInit.c (.../nsfStubInit.c) (revision 14965323980c2235c37b67ddbb19343ddbdaa41c) +++ generic/nsfStubInit.c (.../nsfStubInit.c) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -52,22 +52,23 @@ NsfUnsetInstVar2, /* 13 */ NsfErrMsg, /* 14 */ NsfVarErrMsg, /* 15 */ - NsfErrInProc, /* 16 */ - NsfErrBadVal_, /* 17 */ - NsfObjErrType, /* 18 */ - NsfStackDump, /* 19 */ - NsfSetObjClientData, /* 20 */ - NsfGetObjClientData, /* 21 */ - NsfSetClassClientData, /* 22 */ - NsfGetClassClientData, /* 23 */ - NsfRequireObjNamespace, /* 24 */ - NsfErrBadVal, /* 25 */ - NsfNextObjCmd, /* 26 */ - NsfCallMethodWithArgs, /* 27 */ - NsfObjErrArgCnt, /* 28 */ - NsfAddObjectMethod, /* 29 */ - NsfAddClassMethod, /* 30 */ - NsfCreate, /* 31 */ + NsfDStringPrintf, /* 16 */ + NsfErrInProc, /* 17 */ + NsfErrBadVal_, /* 18 */ + NsfObjErrType, /* 19 */ + NsfStackDump, /* 20 */ + NsfSetObjClientData, /* 21 */ + NsfGetObjClientData, /* 22 */ + NsfSetClassClientData, /* 23 */ + NsfGetClassClientData, /* 24 */ + NsfRequireObjNamespace, /* 25 */ + NsfErrBadVal, /* 26 */ + NsfNextObjCmd, /* 27 */ + NsfCallMethodWithArgs, /* 28 */ + NsfObjErrArgCnt, /* 29 */ + NsfAddObjectMethod, /* 30 */ + NsfAddClassMethod, /* 31 */ + NsfCreate, /* 32 */ }; /* !END!: Do not edit above this line. */ Index: generic/predefined.h =================================================================== diff -u -r6c2e8f94be1ba335ff90d4b6b5132c98a9f5c242 -rf2c0f8e055015e58f3fa7bd338c872a2b7d76113 --- generic/predefined.h (.../predefined.h) (revision 6c2e8f94be1ba335ff90d4b6b5132c98a9f5c242) +++ generic/predefined.h (.../predefined.h) (revision f2c0f8e055015e58f3fa7bd338c872a2b7d76113) @@ -33,6 +33,11 @@ "unset {proc ::nsf::__exithandler args {;}}\n" "default {error \"syntax: ::nsf::exithandler $::nsf::parametersyntax(::nsf::exithandler)\"}}}\n" "::nsf::exithandler unset\n" +"if {[info command ::ns_log] ne \"\"} {\n" +"proc ::nsf::log {level msg} {\n" +"ns_log $level \"nsf: $msg\"}} else {\n" +"proc ::nsf::log {level msg} {\n" +"puts stderr \"$level: $msg\"}}\n" "proc tmpdir {} {\n" "foreach e [list TMPDIR TEMP TMP] {\n" "if {[info exists ::env($e)] \\\n"