Pandora's Box

Or, the internal Parrot C API. It is open, now. At least, parts of it anyway, and hopefully somewhat limited in scope.

When I set out to write mod_parrot it was my goal to use the 'new' embedding API - the one with all the Parrot_api_* calls. This is a limited API designed for loading and running the parrot interpreter and some scripts. It isn't perfect or even elegant but it works. Moreover, People have Promised it to be Stable. However, because it was designed to be used outside of the parrot runloop, these functions are not re-entrant in a rather subtle manner.

Specifically, they each set a jump buffer on entry, to which the parrot interpreter can return when it has an unhandled exception. However, upon (successful) return, they clear that very jump buffer again. This means that if I call a Parrot api function (Parrot_api_foo) which eventually calls another Parrot_api_bar function, then the interpreter can never return to the caller of Parrot_api_foo again when an error is thrown. Parrot, friendly as ever, takes the opportunity then to exit with an error code.

How does it happen, you ask, I call from one Parrot_api_ call to the next? Via the wonders of NCI, as a matter of fact. The input / output of apache headers relies heavily on manipulating parrot hashes and strings, and for that I used the parrot api. Thankfully, I had already taken the opportunity to isolate most of these uses in mod_parrot_util.c. Hence, I could rewrite these functions to use the internal parrot API. Also, the rest of mod_parrot is still nicely isolated from parrots' internals. Nevertheless, using the internal API somewhere opens quite a few possibilities that I did not have earlier, such as iterating over hashes and throwing exceptions. Which is nice, in a dangerous kind of way.

I would also like to give some karma to the nagging voice of everyone who told me to write tests and scripts. Although they are only simple functional tests, the small test suite that is pudding allows me to push commits with certainty that they work, and that is an incredible peace of mind. If I have convinced you this is interesting and you personally want to try it out, please checkout git:// and run the test suite (make test). And what is more, notify me of any and all errors you might find. I will be very grateful!