Posted to tcl by de at Sat Apr 01 00:02:10 GMT 2023view raw

  1. #include <tcl.h>
  2.  
  3. #if defined(Tcl_Size)
  4. # define domLength Tcl_Size
  5. # define STUB_VERSION "8.6"
  6. #else
  7. # define domLength int
  8. # define STUB_VERSION "9"
  9. #endif
  10.  
  11. static int rdeCmd(
  12. void *clientData,
  13. Tcl_Interp *interp,
  14. int objc,
  15. Tcl_Obj *const objv[]
  16. )
  17. {
  18. /* With:
  19. Tcl_Size len;
  20. or
  21. size_t len;
  22. this would work as expected. */
  23. domLength len;
  24.  
  25. if (objc != 2) {
  26. Tcl_WrongNumArgs (interp, 1, objv, "string");
  27. return TCL_ERROR;
  28. }
  29. Tcl_GetStringFromObj (objv[1], &len);
  30. Tcl_SetObjResult (interp, Tcl_NewWideIntObj(len));
  31. return TCL_OK;
  32. }
  33.  
  34. int Rde_Init(Tcl_Interp *interp) {
  35. if (Tcl_InitStubs(interp, STUB_VERSION, 0) == NULL) {
  36. return TCL_ERROR;
  37. }
  38. Tcl_CreateObjCommand(interp, "rde", rdeCmd, NULL, NULL);
  39. return TCL_OK;
  40. }
  41.  
  42. /*
  43.  
  44. Build with a sh script as:
  45.  
  46. TCL=/usr/local/tcl/9
  47.  
  48. rm -f rde.o rde.so
  49. gcc -DUSE_TCL_STUBS -I${TCL}/include -fPIC -o rde.o -c rde.c
  50. gcc -L${TCL}/lib -shared -o rde.so rde.o -ltclstub9.0
  51.  
  52. Test script:
  53.  
  54. load ./rde.so
  55. puts [rde [string repeat abc 1000000000]]
  56.  
  57. */
  58.