Overview
| Artifact ID: | 1289b627665400b327bf23d119a6536e11bf52cdcb135217f622d10ae80becfb |
|---|---|
| Ticket: | e5691de2eb49302428e77726a057449a06f499da
Tcl_ObjPrintf() - 'Unable to format "%p" with supplied arguments: ' |
| User & Date: | zakhmak on 2018-01-23 19:54:00 |
Changes
- comment changed to:
Hello, I posted this ticket at https://core.tcl.tk/tcllib/tktview?name=d94018f4763cde00c8e8976da8a4cf86d8509de4 I was told to post my ticket here instead since it should be more relevant. You will find at the end a C code example of a simplify case that nevertheless show the point I discuss below. --------- I am working to wrap by myself some C functions to Tcl commands. I use for this purpose handles as command as suggested on wiki.tcl.tk/1089 - First part of the handle string is a short text telling the kind of struct tranfered as ClientData. - Second part consists in the pointer value concerning the ClientData struct so that I can also retrieve the pointer of other structs and not only the one of the current called command. I just discover the Tcl_ObjPrintf() function and I tried to used it for this prupose but the format specifier %p seems not to be supported. I get following message returned: 'Unable to format "%p" with supplied arguments: ' I check my pointer before calling ObjPrintf("%p",ptr) and it's valid. Since the function name is related to printf() that supports "%p" format specifier, it looks like a bug for me. Could anyone maybe explain me wether I am right or wrong and why concerning that point? Thanks in advance for any reply and regards --------- #include <tcl.h> int Test_ObjPrintfObjCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { Tcl_DString dynstr; Tcl_Obj *obj = NULL; char *text = NULL, buftxt[128] = ""; static const char *modes[] = {"without_ObjPrintf","with_ObjPrintf",NULL}; static const char formatstr[] = "answer is at %p and its value is %d"; int ok, imode = 0, answer = 42; Tcl_DStringInit(&dynstr); if (objc != 2) { sprintf(buftxt, "Usage : Test_ObjPrintf mode"); Tcl_WrongNumArgs(interp,0,objv,buftxt); return TCL_ERROR; } ok = Tcl_GetIndexFromObj(interp, objv[1], modes, "unknown mode", TCL_EXACT, &imode); if (ok == TCL_ERROR) return TCL_ERROR; switch (imode) { case 0: /* without_ObjPrintf */ sprintf(buftxt, formatstr,&answer, answer); obj = Tcl_NewStringObj(buftxt,-1); break; case 1: /* with_ObjPrintf */ obj = Tcl_ObjPrintf(formatstr,&answer, answer); break; } if (obj == NULL) return TCL_ERROR; text = Tcl_GetStringFromObj(obj,NULL); if (text == NULL) return TCL_ERROR; Tcl_DStringAppend(&dynstr,text,-1); Tcl_DStringResult(interp,&dynstr); return TCL_OK; } int Pb_objprintf_Init(Tcl_Interp *interp) { Tcl_Command cmd; cmd = Tcl_CreateObjCommand(interp, "Test_ObjPrintf", Test_ObjPrintfObjCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); if (cmd == NULL) return TCL_ERROR; return TCL_OK; } - login: "zakhmak"
- mimetype: "text/plain"