Tcl_CreateObjCommand(interp, "ulist", ulist, NULL, NULL);
...
static int
ulist(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) >{
Tcl_Obj *str_o;
if (objc != 2) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("Wrong number of arguments", -1));
return TCL_ERROR;
}
str_o = Tcl_NewObj();
Tcl_InvalidateStringRep(str_o);
str_o->typePtr = &ulist_type;
str_o->bytes = ckalloc(6);
strcat(str_o->bytes, "ulist");
str_o->length = 5;
fprintf(stderr, "mk: len=%d, bytes=%s\n", str_o->length, str_o->bytes);
Tcl_SetObjResult(interp, str_o);
return TCL_OK;
}
static int
ulist(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) >{
Tcl_Obj *str_o;
if (objc != 2) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("Wrong number of arguments", -1));
return TCL_ERROR;
}
str_o = Tcl_NewStringObj("ulist", 5);
str_o->typePtr = &ulist_type;
fprintf(stderr, "mk: len=%d, bytes=%s\n", str_o->length, str_o->bytes);
Tcl_SetObjResult(interp, str_o);
return TCL_OK;
}
Tcl_InvalidateStringRep(str_o);I believe a new object already has an empty string representation.
str_o->typePtr = &ulist_type;
It looks like you have defined a new Tcl type.
If so why not set a string value (as below) then use Tcl_ConvertToType instead of directly manipulating the Tcl_Obj structure?
str_o->bytes = ckalloc(6);using strcat on what looks like uninitalized memory looks unsafe, why not strcpy?
strcat(str_o->bytes, "ulist");
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 25:22:46 |
Calls: | 6,448 |
Files: | 12,050 |
Messages: | 5,254,338 |