Skip to content
Tcl Source Code History Of Ticket e5691de2eb493024
Login

History Of Ticket e5691de2eb493024

Artifacts Associated With Ticket e5691de2eb493024

  1. Ticket change [156b227115] (rid 160430) by zakhmak on 2018-01-23 19:39:35:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized 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;
      }
      
    5. foundin initialized to: "Tcl 8.6.7"
    6. is_private initialized to: "0"
    7. login: "zakhmak"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "a3cbfdb98acf5ab533a2e1324bab5c113eeb5754"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "zakhmak"
    14. subsystem initialized to: "11. Conversions from String"
    15. title initialized to:
      Tcl_ObjPrintf() - 'Unable to format "%p" with supplied arguments: '
      
    16. type initialized to: "Bug"
  2. Ticket change [1289b62766] (rid 160431) by zakhmak on 2018-01-23 19:54:00:

    1. 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;
      }
      
    2. login: "zakhmak"
    3. mimetype: "text/plain"
  3. Ticket change [66d0a8f68a] (rid 160432) by zakhmak on 2018-01-23 19:56:14:

    1. 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 because here should be a more convenient place complying with problem topic.
      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;
      }
      
    2. login: "zakhmak"
    3. mimetype: "text/plain"
  4. Ticket change [e51d4a9ea7] (rid 160434) by dgp on 2018-01-23 20:18:51:

    1. icomment:
      
      Documentation for Tcl_ObjPrintf() is here
      
      http://www.tcl.tk/man/tcl8.6/TclLib/StringObj.htm
      
      Tcl_ObjPrintf() is a C routine providing access to the same
      formatting engine that drives the [format] command.
      
      http://www.tcl.tk/man/tcl8.6/TclCmd/format.htm
      
      The [format] command does not support a %p conversion
      specifier, so neither does Tcl_ObjPrintf().
      
      No bug here.
      
      It's conceivable that adding %p to both [format] and
      Tcl_ObjPrintf() could be a feature request, but it seems
      like a risky and ill-considered one. Exposing pointer values
      to scripts or messages for anything other than debugging
      purposes does not seem like a good idea to me at all.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  5. Ticket change [fb9773265f] (rid 160435) by oehhar on 2018-01-23 20:26:23:

    1. icomment:
      Thank you for the ticket.
      
      If you read the manpage of Tcl_ObjPrintf [http://www.tcl.tk/man/tcl8.6/TclLib/StringObj.htm] 
      
      It states:
      
      The formatting is done with the same core formatting engine used by Tcl_Format. This means the set of supported conversion specifiers is that of the *format* command and not that of the *sprintf* routine where the two sets differ.
      
      If you look on the *format* man page [http://www.tcl.tk/man/tcl8.6/TclCmd/format.htm], there is no "%p" as format.
      Pointers are not supported.
      
      Nevertheless, the provided error message might be missleading or even a bug.
      
      The format error message is:
      
      <verbatim>
      % format "%p" 12345
      bad field specifier "p"
      </verbatim>
      
      I have no experience here, just reading the man page...
      
      Hope this helps,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  6. Ticket change [3da7ec8a4b] (rid 160444) by zakhmak on 2018-01-24 05:58:13:

    1. icomment:
      Hello,
      
      Thanks for your explanations both of you. I understand better now. The documentation is huge and I hadn't the reflex to had a closer look on the sections you mentioned.
      
      Concerning my problem, I think, I have to develop this lookup bidirectional function to map Tcl representation with their C pointer and vice versa.
      
      I guess finally it is ok so and that you can close my ticket.
      
      Thanks for your support again
      
    2. login: "zakhmak"
    3. mimetype: "text/plain"
  7. Ticket change [5126c803ae] (rid 160445) by oehhar on 2018-01-24 07:45:39:

    1. closedate changed to: "2458142.82337153"
    2. closer changed to: "oehhar"
    3. login: "oehhar"
    4. mimetype: "text/plain"
    5. resolution changed to: "Rejected"
    6. status changed to: "Closed"
  8. Ticket change [2147c79722] (rid 160508) by jan.nijtmans on 2018-01-26 10:14:21:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2458144.92663234"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Actually, I don't think formatting a pointer value is dangerous at all: It just gives the hex representation of the memory address. What would be dangerous to - possibly at a later time - use this hex value to access this same memory again: The memory content could be different then (possibly freed), waiting for a disaster to happen.
      
      A proposal for adding %p is part of [http://core.tcl.tk/tips/doc/trunk/tip/476.md|TIP 476]. Therefore marking this ticket as RFE (Request for Extension) and as a duplicate for this TIP.
      
      Thanks for reporting it! You could try the [http://core.tcl.tk/tcl/info/afb68da53ed1658f|z_modifier] branch, to see if this approach works for you.
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/plain"
    7. resolution changed to: "Duplicate"
    8. type changed to: "RFE"
  9. Ticket change [40268316e5] (rid 160509) by jan.nijtmans on 2018-01-26 10:15:03:

    1. closedate changed to: "2458144.92712806"
    2. icomment:
      Actually, I don't think formatting a pointer value is dangerous at all: It just gives the hex representation of the memory address. What would be dangerous to - possibly at a later time - use this hex value to access this same memory again: The memory content could be different then (possibly freed), waiting for a disaster to happen.
      
      A proposal for adding %p is part of [http://core.tcl.tk/tips/doc/trunk/tip/476.md|TIP 476]. Therefore marking this ticket as RFE (Request for Extension) and as a duplicate for this TIP.
      
      Thanks for reporting it! You could try the [http://core.tcl.tk/tcl/info/afb68da53ed1658f|z_modifier] branch, to see if this approach works for you.
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"