Posted to tcl by xharx at Thu Nov 12 16:30:36 GMT 2020view raw

  1. int EPtkcreatepicdata(ClientData clientdata, Tcl_Interp *interp, int arc, const char **argv) {
  2. char *pto=malloc(100);
  3. sprintf(pto, "%s", "dings");
  4. Tcl_Obj *mobj=Tcl_NewObj();
  5. mobj->bytes=pto;
  6. mobj->length=10;
  7. Tcl_SetObjResult(interp, mobj);
  8. return TCL_OK;
  9. }
  10.  
  11. void registercommands(Tcl_Interp *tcl_interp) {
  12. Tcl_CreateCommand(tcl_interp, "epcreatepicdata", EPtkcreatepicdata, (ClientData) NULL, (Tcl_CmdDeleteProc *)NULL);
  13.  
  14. }
  15.  
  16. Now, in a tcl- script, when I say eg.
  17. puts [epcreatepicdata]
  18. I get a
  19. dings
  20. alloc: invalid block: 0x7f8f8c3dcf70: a5 0
  21. What do I do wrong?
  22.