Brian Ingerson [26/09/02 11:27 -0700]:
> I sometimes wish that typemaps could be improved upon. They are not
> quite XS. They are just the little transformations that are so common
> that you want to factor them out of your code and into a common place.
> 
> For instance, if every Inline function you wrote looked like:
> 
>     SV* foo(SV* x, SV* y) {
> 
> You wouldn't need any typemaps. You'd just disassemble and reassemble
> all the SVs right in your function.

Gisle Aas, author of libwww-perl, actually prefers this even for quite large
projects :)

> I actually like this approach better for small to medium projects. Even
> if you start accumulating duplicate code, you can refactor the type
> mapping stuff into internal static functions. The C compiler may very
> well inline them anyway, so no performance worries. The nice thing about
> avoiding typemaps is that your code stays in the Perl source file. That
> is especially nice for CPAN modules, where any custom typemaps would be
> tossed after build/installation.

Would it be possible to extend Inline so this could work?

   use Inline C => <<'C_CODE', TYPEMAP => <<'TYPEMAP';

   /* some C code */

   C_CODE

   # Typemap!

   TYPEMAP

Perhaps the interface could be improved somewhat, but the idea is you keep
the typemap right there with your C code, and Inline writes it to a typemap
for you before compiling. Does that make sense?

Later,
Neil

Reply via email to