Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

tclobj default return

This is a biggie. Many Tohil functions accept a to= argument where you can specify a Python data type to convert a tcl object returned from doing a call or accessing tcl data. You can set a return type of str, int, bool, float, list, set, dict, tuple, tohil.tclobj or tohil.tcldict.

...

If, though, for instance, you didn’t specify a default return and then knowing you would get a str invoked string methods on the str that was returned, you’ll probably get an error because the tclobj doesn’t implement all of the str datatype’s methods. In this case, adding a to=str to the Tohil call will be sufficient to get your code working under Tohil 4.

Python Subinterpreter Support

Full Python subinterpreter support!

...

Implementation Note: This was pretty tricky, because we previously had global variables, in particular one pointing to the Tcl interpreter. We had to figure out ways to stash the pointer to the Tcl interpreter in Python using C such that we could find it later when we didn’t have control over how we were called, for example we are being called from Python with to do some Python thing, you only get what it calls you with. So we stashed the interpreter pointer in a capsule in Tohil’s Python data types’ dictionaries and in __main__’s dictionary. It turned out really nice.

Support for Separate Virtual Interpreters in Rivet

A nice bit of fallout from the above, if you’re running the Apache webserver with the Apache Rivet module installed and running in the mode where different virtual hosts run in separate Tcl interpreters, known as separate virtual interpreters, each vhost that does a package require tohil will get its own Python subinterpreter, isolating Python between the vhosts just as Tcl is.

A function can now be specified in a to= arg

The to= argument to a Tohil function such as tohil.eval, tohil.call, etc, has until now been required to specify a Python data type such as int, float, str, tohil.tclobj, etc. It can now also be specified as a callable function.

...

This provides an additional way for a Tohil developer to customize the return of some Tcl activity in order to make it more standard and readily useful to the Python caller.

User-Facing Behavior Changes

  • When Tcl is the parent, package require tohil will, in addition to initializing Python, automatically import tohil on the Python side.

Internal Changes

  • When Tcl is the parent and Tohil initializes Python from scratch, we use PyInitializeEx(0) instead of Py_Initialize to prevent Python from registering signal handlers. (Signal handling probably ought to be Tcl’s business under this circumstance.)

  • Internal code refactoring and cleanup.

Documentation Improvements

  • Greatly improved documentation in Python-standard format.

  • Makefile and docs for building the docs.

  • make serve target to serve the docs via http (for devs)