++ed by:

6 PAUSE users
2 non-PAUSE users.

David Mertens
and 1 contributors


C::TinyCompiler::Perl::AV - Perl's array C-API


This code has not seen much attention and has neither been carefully reviewed nor tested. It may not even be useable. You have been warned.


 use C::TinyCompiler;
 # Declare the compiler context with the AV bindings:
 my $context= C::TinyCompiler->new(packages => '::Perl::AV');
 # Or add them afterwards:
 my $context = C::TinyCompiler->new;
 # Create a function that tells us how many arguments we sent:
 $context->code('Body') = q{
        void test_func(AV * inputs, AV * outputs) {
                printf("You sent %d arguments\n", av_len(inputs));
 # Compile and call:
 $context->call_function('test_func', 1, 2, 3);


This module provides various Perl array manipulate functions to the compiler context. Eventually it will contain options so that you can specify which parts of the API you want, but for now it comes in one big bunch (or as much of it as I have packaged thus far).

Like other C::TinyCompiler packages, you never use this module directly. Rather, you add it to your compiler context in the constructor or with the function "apply_packages" in C::TinyCompiler.

Documentation for all of these functions can be found at perlapi, so I will only give their names and signatures here for reference (and possibly a few notes if I deem them to be helpful).

 void av_clear (AV * array)
 int av_len (AV * array)
 SV ** av_fetch (AV * array, int key, int lval)

Fetches the requested item from the array, creating it if necessary. The usage is descriped in perlapi. I simply wish to point out that in my experience, the only time the returned pointer to the SV is only null is when I try to retrieve a non-existent array element not in lvalue context. (I suspect that it may also return null in lvalue context if Perl is unable to allocate the contiguous memory for key elements, but I have not confirmed that.) The point is that you ought to check that the returned pointer is non-null before dereferencing it.


David Mertens, <dcmertens.perl at gmail.com>


Please report any bugs or feature requests at the project's main github page: http://github.com/run4flat/perl-TCC/issues.


You can find documentation for this module with the perldoc command.

    perldoc C::TinyCompiler::Perl::AV

You can also look for information at:


Code Copyright 2011-2012 Northwestern University. Documentation copyright 2011-2013 David Mertens.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.