Chapter 10: Writing C Modules with Inline::C

Chapter 10 - Writing C Modules with Inline::C
by?Sam Tregar?
Apress ? 2002
has companion web siteCompanion Web Site

Overview

INLINE::C[1] PROVIDES a new way to write Perl modules with C. Instead of separating out the Perl and C parts of your module into different files, you can include them both in the same file. Instead of learning a new programming language (XS), you can create C functions in pure C. If this sounds pretty great, it is! My prediction is that the majority of new C modules will be written using Inline::C. It's easy, it works, and what more could you ask for?

Inline::C is essentially a compiler for XS. You give Inline::C some C code. Inline::C takes that code, parses it, and produces an XS wrapper to make that code callable from Perl. This XS code is written out to disk in a special temporary directory. Then Inline::C compiles the code using the normal XS tools: ExtUtils::MakeMaker, xsubpp, and your system's C compiler This compiled code is saved to disk and then loaded into memory.

Since the compiled code is saved to disk, it can be reused as long as the C code hasn't changed. This magic is accomplished by using Digest::MD5 to produce a fingerprint of your code. When that fingerprint is changed, the code is automatically recompiled the next time it's passed to Inline::C.

[1]Written by Brian Ingerson and available on a CPAN mirror near you



Writing Perl Modules for CPAN
Writing Perl Modules for CPAN
ISBN: 159059018X
EAN: 2147483647
Year: 2002
Pages: 110
Authors: Sam Tregar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net