Overview
| Artifact ID: | 156b227115a7ec7a26541948e345baea05bb7f2a988edfcfd38bcbc30ce8ccf6 |
|---|---|
| Ticket: | e5691de2eb49302428e77726a057449a06f499da
Tcl_ObjPrintf() - 'Unable to format "%p" with supplied arguments: ' |
| User & Date: | zakhmak on 2018-01-23 19:39:35 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
Hello, I post this ticket at https://core.tcl.tk/tcllib/tktview?name=d94018f4763cde00c8e8976da8a4cf86d8509de4 I was told to post my ticket here instead. 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; } - foundin changed to: "Tcl 8.6.7"
- is_private changed to: "0"
- login: "zakhmak"
- priority changed to: "5 Medium"
- private_contact changed to: "a3cbfdb98acf5ab533a2e1324bab5c113eeb5754"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "zakhmak"
- subsystem changed to: "11. Conversions from String"
- title changed to:
Tcl_ObjPrintf() - 'Unable to format "%p" with supplied arguments: '
- type changed to: "Bug"