Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

  (email not shown publicly)

Blog Information [] Profile for chr0matic []

Journal of chromatic (983)

Monday October 02, 2006
02:07 AM

C is not Perl

[ #31190 ]

Stevan asked me to write some XS code for Class::MOP, and it sounded like more fun than painting my deck or writing the non-fiction book, so I dodged segfaults for a couple of hours this afternoon.

The Perl XS API has its own kind of consistency. It's never really stuck in my brain, but it's just familiar enough that I sort of know what I want.

In theory, you can do anything from C that you can from Perl. In practice, try manipulating typeglobs from C. Though deleting an element from a typeglob is straightforward in Perl (once you realize that you can't really delete, you just have to create a new glob, copy in everything you don't want to delete--if it exists--, then assign the new glob in the old symbol table), that's really difficult in C. I don't just mean dealing with refcounts and garbage collection, though that's a little tedious. You can get some seriously complex code that goes seriously wrong in many weird ways.

Then I asked myself what I was doing and why I couldn't just delete the elements. It works that way, even with using the standard XS macros.

(I showed The GV and GP sections of PerlGuts Illustrated to a friend who said it looked like gibberish. Sadly, I know what it's talking about and it looks mostly gibberish to me too.)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • If XS could have been a bit more pre-processed than it is, it could have been so much better. Things like accessing hash values and references in XS is more painful than it could be with a little pre-filtering.