gisle / tcl.pm

Tcl extension module for Perl
http://search.cpan.org/dist/Tcl
9 stars 8 forks source link

Improve Tcl 8.7/9.0 readiness, `const` usage #42

Closed chrstphrchvz closed 1 year ago

chrstphrchvz commented 2 years ago

Tcl_GetObjType() returns const as of Tcl 8.6, and Tcl.xs never modifies these structs

chrstphrchvz commented 2 years ago

In order to test changes in Tcl::pTk for supporting Tk 8.7, I would like get Tcl.pm to build and run with Tcl 8.7/9.0. I am going to repurpose this pull request to include other changes which I believe will be needed:

vadrer commented 2 years ago

ok, nice. thanks!

chrstphrchvz commented 2 years ago

I am trying to figure out how to properly deal with various types (int, wideInt, boolean, bytearray) no longer being registered in Tcl 9.0. This causes Tcl_GetObjType() to return NULL, which breaks SvFromTclObj() since it assumes cached type pointers are not NULL so that values with objPtr->typePtr == NULL fall through to the string case. Example: in disposal-subs-b.t, flush_afters() waits for after info to be empty, but SvFromTclObj() returns a garbage integer value instead of an empty list, and the test never exits. I wonder if SvFromTclObj() should more resemble Tkinter’s approach which checks for objPtr->typePtr == NULL first (see FromObj() in _tkinter.c; I am not aware of Tkinter having already prepared for Tcl 8.7/9.0, though).

I am also considering how to deal with Tcl TIP 484 which removes the wideInt type, meaning the int type is used for 64-bit values even on 32-bit platforms. I am not aware of a good approach for use in XS libraries to support 64-bit integer SVs. Currently I would be inclined to return a Tcl integer as a string unless it is within [IVMIN,UVMAX] (or maybe as an NV if within the range of double which can represent odd integers).

It sounds like upstream Tcl may be willing to help C API users migrate, as there are not very many which are still actively maintained (edit: see https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b).

chrstphrchvz commented 1 year ago

I am satisfied enough with the work in this pull request for it to be merged.

There is at least one remaining issue where Tcl.pm built to use stubs will not load with Tcl 9.0 (Tcl_InitStubs() cannot be called with a differing major version), but I am currently not interested in fixing this.