Tcl Source Code

Artifact [fb0f0d34f0]
Login

Artifact fb0f0d34f00a3fb61e46292cf166d3247ce87f80:

Attachment "objresult_example.c" to ticket [3202905fff] added by cjmcdonald 2011-03-08 18:43:46.
/*
    This example program demonstrates a problem with clearing
    the obj result for an Interp.

    The first printf output the number of unicode characters in
    an empty result (0).

    The second printf should output the number of unicode characters
    in result abcdefgh (8).  But the tclStringType internal rep
    of the obj result has not been cleared, and it still returns 0.
*/

#include <tcl.h>

int main(int argc, char* argv[])
{
    Tcl_Interp *interp;

    Tcl_FindExecutable(argv[0]);
    interp = Tcl_CreateInterp();

    Tcl_SetResult(interp, "", TCL_STATIC);
    printf( "Num chars %d (0 expected)\n",
		Tcl_GetCharLength(Tcl_GetObjResult(interp)) );

    Tcl_ResetResult(interp);
    Tcl_SetResult(interp, "abcdefgh", TCL_STATIC);
    printf( "Num chars %d (8 expected)\n",
		Tcl_GetCharLength(Tcl_GetObjResult(interp)) );

    return 0;
}