• it is allowed to manipulate the string output from Tcl_GetStringFromObj

    From aotto1968@21:1/5 to All on Thu May 12 11:13:50 2022
    Hi,

    the "char *Tcl_GetStringFromObj(objPtr, lengthPtr)" return an "char*"
    not an "const char*".

    question:

    1) it is possible to manipulate the string without extend the
    objPtr->length border?

    2) after manipulation (discard space and tokenize "|"→"\0") the new
    string is shorter and has additional '\0' values. It is allowed to
    modify the objPtr->length to the new (shorter) length ?


    mfg AO

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to All on Thu May 12 11:51:30 2022
    On 12/05/2022 11:13, aotto1968 wrote:
    the "char *Tcl_GetStringFromObj(objPtr, lengthPtr)" return an "char*"
    not an "const char*".

    question:

    1) it is possible to manipulate the string without extend the
    objPtr->length border?

    2) after manipulation (discard space and tokenize "|"→"\0") the new
    string is shorter and has additional '\0' values. It is allowed to
    modify the objPtr->length to the new (shorter) length ?


    The man page says: "The storage referenced by the returned byte pointer
    is owned by the value manager. It is passed back as a writable pointer
    so that extension author creating their own Tcl_ObjType will be able to
    modify the string representation within the Tcl_UpdateStringProc of
    their Tcl_ObjType. Except for that limited purpose, the pointer returned
    by Tcl_GetStringFromObj or Tcl_GetString should be treated as read-only.
    It is recommended that this pointer be assigned to a (const char *)
    variable."

    So the answer to your question would be no.


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)