GithubHelp home page GithubHelp logo

inline-c-pm's Introduction

Name

Inline::C - C Language Support for Inline

inline-c-pm

Version

This document describes Inline::C version 0.82_001.

Description

Inline::C is a module that allows you to write Perl subroutines in C. Since version 0.30 the Inline module supports multiple programming languages and each language has its own support module. This document describes how to use Inline with the C programming language. It also goes a bit into Perl C internals.

If you want to start working with programming examples right away, check out Inline::C::Cookbook. For more information on Inline in general, see Inline.

Usage

You never actually use Inline::C directly. It is just a support module for using Inline.pm with C. So the usage is always:

use Inline C => ...;

or

bind Inline C => ...;

Function Definitions

The Inline grammar for C recognizes certain function definitions (or signatures) in your C code. If a signature is recognized by Inline, then it will be available in Perl-space. That is, Inline will generate the "glue" necessary to call that function as if it were a Perl subroutine. If the signature is not recognized, Inline will simply ignore it, with no complaints. It will not be available from Perl-space, although it will be available from C-space.

Inline looks for ANSI/prototype style function definitions. They must be of the form:

return-type function-name ( type-name-pairs ) { ... }

The most common types are: int, long, double, char*, and SV*. But you can use any type for which Inline can find a typemap. Inline uses the typemap file distributed with Perl as the default. You can specify more typemaps with the typemaps configuration option.

A return type of void may also be used. The following are examples of valid function definitions.

int Foo(double num, char* str) {
void Foo(double num, char* str) {
void Foo(SV*, ...) {
long Foo(int i, int j, ...) {
SV* Foo(void) { # 'void' arg invalid with the ParseRecDescent parser.
                # Works only with the ParseRegExp parser.
                # See the section on `using` (below).
SV* Foo() {  # Alternative to specifying 'void' arg. Is valid with
             # both the ParseRecDescent and ParseRegExp parsers.

The following definitions would not be recognized:

Foo(int i) {               # no return type
int Foo(float f) {         # no (default) typemap for float
int Foo(num, str) double num; char* str; {

Notice that Inline only looks for function definitions, not function prototypes. Definitions are the syntax directly preceding a function body. Also Inline does not scan external files, like headers. Only the code passed to Inline is used to create bindings; although other libraries can linked in, and called from C-space.

C Configuration Options

For information on how to specify Inline configuration options, see Inline. This section describes each of the configuration options available for C. Most of the options correspond either to MakeMaker or XS options of the same name. See ExtUtils::MakeMaker and perlxs.

auto_include

Specifies extra statements to automatically included. They will be added onto the defaults. A newline char will be automatically added.

use Inline C => config => auto_include => '#include "yourheader.h"';
autowrap

If you enable => autowrap, Inline::C will parse function declarations (prototype statements) in your C code. For each declaration it can bind to, it will create a dummy wrapper that will call the real function which may be in an external library. This is a nice convenience for functions that would otherwise just require an empty wrapper function.

This is similar to the base functionality you get from h2xs. It can be very useful for binding to external libraries.

boot

Specifies C code to be executed in the XS BOOT section. Corresponds to the XS parameter.

cc

Specify which compiler to use.

ccflags

Specify compiler flags - same as ExtUtils::MakeMaker's CCFLAGS option. Whatever gets specified here replaces the default $Config{ccflags}. Often, you'll want to add an extra flag or two without clobbering the default flags in which case you could instead use ccflagsex (see below) or, if Config.pm has already been loaded:

use Inline C => Config => ccflags => $Config{ccflags} . " -DXTRA -DTOO";
ccflagsex

Extend compiler flags. Sets CCFLAGS to $Config{ccflags} followed by a space, followed by the specified value:

use Inline C => config => ccflagsex => "-DXTRA -DTOO";
cppflags

Specify preprocessor flags. Passed to cpp C preprocessor by Preprocess() in Inline::Filters.

use Inline C => <<'END',
    CPPFLAGS => ' -DPREPROCESSOR_DEFINE',
    FILTERS => 'Preprocess';
use Inline C => <<'END',
    CPPFLAGS => ' -DPREPROCESSOR_DEFINE=4321',
    FILTERS => 'Preprocess';
filters

Allows you to specify a list of source code filters. If more than one is requested, be sure to group them with an array ref. The filters can either be subroutine references or names of filters provided by the supplementary Inline::Filters module.

Your source code will be filtered just before it is parsed by Inline. The MD5 fingerprint is generated before filtering. Source code filters can be used to do things like stripping out POD documentation, pre-expanding #include statements or whatever else you please. For example:

use Inline C => DATA =>
           filters => [Strip_POD => \&MyFilter => Preprocess ];

Filters are invoked in the order specified. See Inline::Filters for more information.

If a filter is an array reference, it is assumed to be a usage of a filter plug- in named by the first element of that array reference. The rest of the elements of the array reference are used as arguments to the filter. For example, consider a filters parameter like this:

use Inline C => DATA => filters => [ [ Ragel => '-G2' ] ];

In order for Inline::C to process this filter, it will attempt to require the module Inline::Filters::Ragel and will then call the filter function in that package with the argument '-G2'. This function will return the actual filtering function.

inc

Specifies an include path to use. Corresponds to the MakeMaker parameter. Expects a fully qualified path.

use Inline C => config => inc => '-I/inc/path';
ld

Specify which linker to use.

lddlflags

Specify which linker flags to use.

NOTE: These flags will completely override the existing flags, instead of just adding to them. So if you need to use those too, you must respecify them here.

libs

Specifies external libraries that should be linked into your code. Corresponds to the MakeMaker parameter. Provide a fully qualified path with the -L switch if the library is in a location where it won't be found automatically.

use Inline C => config => libs => '-lyourlib';

or

use Inline C => config => libs => '-L/your/path -lyourlib';
make

Specify the name of the 'make' utility to use.

myextlib

Specifies a user compiled object that should be linked in. Corresponds to the MakeMaker parameter. Expects a fully qualified path.

use Inline C => config => myextlib => '/your/path/yourmodule.so';
optimize

This controls the MakeMaker OPTIMIZE setting. By setting this value to '-g', you can turn on debugging support for your Inline extensions. This will allow you to be able to set breakpoints in your C code using a debugger like gdb.

prefix

Specifies a prefix that will be automatically stripped from C functions when they are bound to Perl. Useful for creating wrappers for shared library API-s, and binding to the original names in Perl. Also useful when names conflict with Perl internals. Corresponds to the XS parameter.

use Inline C => config => prefix => 'ZLIB_';
pre_head

Specifies code that will precede the inclusion of all files specified in auto_include (ie EXTERN.h, perl.h, XSUB.h, INLINE.h and anything else that might have been added to auto_include by the user). If the specified value identifies a file, the contents of that file will be inserted, otherwise the specified value is inserted.

use Inline C => config => pre_head => $code_or_filename;
prototype

Corresponds to the XS keyword 'PROTOTYPE'. See the perlxs documentation for both 'PROTOTYPES' and 'PROTOTYPE'. As an example, the following will set the PROTOTYPE of the 'foo' function to '$', and disable prototyping for the 'bar' function.

use Inline C => config => prototype => {foo => '$', bar => 'DISABLE'}
prototypes

Corresponds to the XS keyword 'PROTOTYPES'. Can take only values of 'ENABLE' or 'DISABLE'. (Contrary to XS, default value is 'DISABLE'). See the perlxs documentation for both 'PROTOTYPES' and 'PROTOTYPE'.

use Inline C => config => prototypes => 'ENABLE';
typemaps

Specifies extra typemap files to use. These types will modify the behaviour of the C parsing. Corresponds to the MakeMaker parameter. Specify either a fully qualified path or a path relative to the cwd (ie relative to what the cwd is at the time the script is loaded).

use Inline C => config => typemaps => '/your/path/typemap';
using

Specifies which parser to use. The default is Inline::C::Parser::RecDescent, which uses the Parse::RecDescent module.

The other options are ::Parser::Pegex and ::Parser::RegExp, which uses the Inline::C::Parser::Pegex and Inline::C::Parser::RegExp modules that ship with Inline::C.

use Inline C => config => using => '::Parser::Pegex';

Note that the following old options are deprecated, but still work at this time:

  • ParseRecDescent

  • ParseRegExp

  • ParsePegex

C-Perl Bindings

This section describes how the Perl variables get mapped to C variables and back again.

First, you need to know how Perl passes arguments back and forth to subroutines. Basically it uses a stack (also known as the Stack). When a sub is called, all of the parenthesized arguments get expanded into a list of scalars and pushed onto the Stack. The subroutine then pops all of its parameters off of the Stack. When the sub is done, it pushes all of its return values back onto the Stack.

The Stack is an array of scalars known internally as SV's. The Stack is actually an array of pointers to SV or SV*; therefore every element of the Stack is natively a SV*. For FMTYEWTK about this, read perldoc perlguts.

So back to variable mapping. XS uses a thing known as "typemaps" to turn each SV* into a C type and back again. This is done through various XS macro calls, casts and the Perl API. See perldoc perlapi. XS allows you to define your own typemaps as well for fancier non-standard types such as typedef- ed structs.

Inline uses the default Perl typemap file for its default types. This file is called /usr/local/lib/perl5/5.6.1/ExtUtils/typemap, or something similar, depending on your Perl installation. It has definitions for over 40 types, which are automatically used by Inline. (You should probably browse this file at least once, just to get an idea of the possibilities.)

Inline parses your code for these types and generates the XS code to map them. The most commonly used types are:

  • int

  • long

  • double

  • char*

  • void

  • SV*

If you need to deal with a type that is not in the defaults, just use the generic SV* type in the function definition. Then inside your code, do the mapping yourself. Alternatively, you can create your own typemap files and specify them using the typemaps configuration option.

A return type of void has a special meaning to Inline. It means that you plan to push the values back onto the Stack yourself. This is what you need to do to return a list of values. If you really don't want to return anything (the traditional meaning of void) then simply don't push anything back.

If ellipsis or ... is used at the end of an argument list, it means that any number of SV*s may follow. Again you will need to pop the values off of the Stack yourself.

See "EXAMPLES" below.

The Inline Stack Macros

When you write Inline C, the following lines are automatically prepended to your code (by default):

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "INLINE.h"

The file INLINE.h defines a set of macros that are useful for handling the Perl Stack from your C functions.

Inline_Stack_Vars

You'll need to use this one, if you want to use the others. It sets up a few local variables: sp, items, ax and mark, for use by the other macros. It's not important to know what they do, but I mention them to avoid possible name conflicts.

NOTE: Since this macro declares variables, you'll need to put it with your other variable declarations at the top of your function. It must come before any executable statements and before any other Inline_Stack macros.

Inline_Stack_Items

Returns the number of arguments passed in on the Stack.

Inline_Stack_Item(i)

Refers to a particular SV* in the Stack, where i is an index number starting from zero. Can be used to get or set the value.

Inline_Stack_Reset

Use this before pushing anything back onto the Stack. It resets the internal Stack pointer to the beginning of the Stack.

Inline_Stack_Push(sv)

Push a return value back onto the Stack. The value must be of type SV*.

Inline_Stack_Done

After you have pushed all of your return values, you must call this macro.

Inline_Stack_Return(n)

Return n items on the Stack.

Inline_Stack_Void

A special macro to indicate that you really don't want to return anything. Same as:

Inline_Stack_Return(0);

Please note that this macro actually returns from your function.

Each of these macros is available in 3 different styles to suit your coding tastes. The following macros are equivalent.

Inline_Stack_Vars
inline_stack_vars
INLINE_STACK_VARS

All of this functionality is available through XS macro calls as well. So why duplicate the functionality? There are a few reasons why I decided to offer this set of macros. First, as a convenient way to access the Stack. Second, for consistent, self documenting, non-cryptic coding. Third, for future compatibility. It occurred to me that if a lot of people started using XS macros for their C code, the interface might break under Perl6. By using this set, hopefully I will be able to insure future compatibility of argument handling.

Of course, if you use the rest of the Perl API, your code will most likely break under Perl6. So this is not a 100% guarantee. But since argument handling is the most common interface you're likely to use, it seemed like a wise thing to do.

Writing C Subroutines

The definitions of your C functions will fall into one of the following four categories. For each category there are special considerations.

int Foo(int arg1, char* arg2, SV* arg3) {

This is the simplest case. You have a non void return type and a fixed length argument list. You don't need to worry about much. All the conversions will happen automatically.

void Foo(int arg1, char* arg2, SV* arg3) {

In this category you have a void return type. This means that either you want to return nothing, or that you want to return a list. In the latter case you'll need to push values onto the Stack yourself. There are a few Inline macros that make this easy. Code something like this:

int i, max; SV* my_sv[10];
Inline_Stack_Vars;
Inline_Stack_Reset;
for (i = 0; i < max; i++)
  Inline_Stack_Push(my_sv[i]);
Inline_Stack_Done;

After resetting the Stack pointer, this code pushes a series of return values. At the end it uses Inline_Stack_Done to mark the end of the return stack.

If you really want to return nothing, then don't use the Inline_Stack_ macros. If you must use them, then set use Inline_Stack_Void at the end of your function.

char* Foo(SV* arg1, ...) {

In this category you have an unfixed number of arguments. This means that you'll have to pop values off the Stack yourself. Do it like this:

int i;
Inline_Stack_Vars;
for (i = 0; i < Inline_Stack_Items; i++)
  handle_sv(Inline_Stack_Item(i));

The return type of Inline_Stack_Item(i) is SV*.

void* Foo(SV* arg1, ...) {

In this category you have both a void return type and an unfixed number of arguments. Just combine the techniques from Categories 3 and 4.

Examples

Here are a few examples. Each one is a complete program that you can try running yourself. For many more examples see Inline::C::Cookbook.

Example #1 - Greetings

This example will take one string argument (a name) and print a greeting. The function is called with a string and with a number. In the second case the number is forced to a string.

Notice that you do not need to #include <stdio.h>. The perl.h header file which gets included by default, automatically loads the standard C header files for you.

use Inline 'C';
greet('Ingy');
greet(42);
__END__
__C__
void greet(char* name) {
  printf("Hello %s!\n", name);
}

Example #2 - and Salutations

This is similar to the last example except that the name is passed in as a SV* (pointer to Scalar Value) rather than a string (char*). That means we need to convert the SV to a string ourselves. This is accomplished using the SvPVX function which is part of the Perl internal API. See perldocperlapi for more info.

One problem is that SvPVX doesn't automatically convert strings to numbers, so we get a little surprise when we try to greet 42. The program segfaults, a common occurrence when delving into the guts of Perl.

use Inline 'C';
greet('Ingy');
greet(42);
__END__
__C__
void greet(SV* sv_name) {
  printf("Hello %s!\n", SvPVX(sv_name));
}

Example #3 - Fixing the problem

We can fix the problem in Example #2 by using the SvPV function instead. This function will stringify the SV if it does not contain a string. SvPV returns the length of the string as it's second parameter. Since we don't care about the length, we can just put PL_na there, which is a special variable designed for that purpose.

use Inline 'C';
greet('Ingy');
greet(42);
__END__
__C__
void greet(SV* sv_name) {
  printf("Hello %s!\n", SvPV(sv_name, PL_na));
}

See Also

For general information about Inline see Inline.

For sample programs using Inline with C see Inline::C::Cookbook.

For information on supported languages and platforms see Inline-Support.

For information on writing your own Inline Language Support Module, see Inline-API.

Inline's mailing list is [email protected]

To subscribe, send email to [email protected]

Bugs and Deficiencies

If you use C function names that happen to be used internally by Perl, you will get a load error at run time. There is currently no functionality to prevent this or to warn you. For now, a list of Perl's internal symbols is packaged in the Inline module distribution under the filename 'symbols.perl'. Avoid using these in your code.

Authors

Ingy döt Net <[email protected]>

Sisyphus <[email protected]>

Copyright and License

Copyright 2000-2022. Ingy döt Net.

Copyright 2008, 2010-2014. Sisyphus.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

inline-c-pm's People

Contributors

akarelas-pt avatar bulk88 avatar contyk avatar daoswald avatar hoytech avatar ingydotnet avatar manwar avatar mohawk2 avatar oodler577 avatar perlpunk avatar ppisar avatar rongrw avatar sisyphus avatar wbraswell avatar wchristian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inline-c-pm's Issues

.lock files left behind in PERL_INLINE_DIRECTORY

After a perl script builds inline CPP, a .lock file is left over in the PERL_INLINE_DIRECTORY under the username of the running user. This prevents subsequent runs by other users who share the same PERL_INLINE_DIRECTORY and cannot delete the lock file left over. We are seeing this on Red hat linux with perl version 5.20.2, inline:CPP version 0.71, Inline::C 0.74. The Inline CPP folks are directing me to Inline and/or Inline::C. See daoswald/Inline-CPP#29 . The issue goes away after removing file locking code in Inline::CPP - CPP.pm lines 681,682 even though no lock file with a .lock signature is being created at that point (from David's investigation/understanding).

Inline-C-Cookbook might over-simplify passing strings.

While the example of passing a string to a C function in the Inline-C-Cookbook is not technically inaccurate, it doesn't mention two important gotchas. Certainly it's not our job to inform the user of every way he can get into trouble, I think in this case we could do a little more without becoming nannies.

First: Passing a string that is treated as a char* by C is not useful if the Perl string has been upgraded to Unicode semantics. It is wrong to treat a Unicode string as bytes, and that's exactly what would happen in a naive approach.

In such case that the string has code-points above 255, there could be a suggestion that passing an SV* and using Perl's API for handling the PV would be the safest way short of pulling in a UTF-8 library for C.

The other possible issue is, of course, returning a string. The naive approach from a Perl-user's standpoint is to just return a char*. And if the memory has been allocated for it dynamically, that would probably work, except that it would leak unless some explicit clean-up method is provided. Here, again, a better solution (imho) is to return an SV that has a proper ref count associated with it, and that has been generated using Perl API calls.

Should the Inline-C-Cookbook at least mention that char* strings are not Unicode friendly, and that returning a string should be done with caution?

New recipe for the Inline::C Cookbook

Hi all,

Following a recent discussion on the Inline mailing list about accessing Perl variables directly from a C function, I've put together some sample code that I think would be appropriate to add into the Inline::C Cookbook. I've attached a file in plain text format that contains the full recipe.

Would it be possible to add this new recipe into the Cookbook, perhaps under the "Meat & Potatoes" chapter?

Kind Regards,
Ron.

C-Cookbook-entry.txt

t/08taint.t fails kali linux perl 5.20.2

Below is the screen capture : not sure if it is my environement issue , it could be a problem in my configuration. I try to install PDL, and it is failing because of it.

t/08taint.t .............. 1/10 make[1]: chmod: Command not found (#1)
(A) You've accidentally run your script through csh or another shell
instead of Perl. Check the #! line, or manually feed your script
into Perl yourself. The #! line at the top of your file could look like

  #!/usr/bin/perl -w

BEGIN failed--compilation aborted at ./t/08taint_1.p line 6 (#2)
(F) An untrapped exception was raised while executing a BEGIN
subroutine. Compilation stops immediately and the interpreter is
exited.

Compilation failed in require at t/08taint.t line 33 (#3)
(F) Perl could not compile a file specified in a require statement.
Perl uses this generic message when none of the errors that it
encountered were severe enough to halt compilation immediately.

Uncaught exception from user code:
make[1]: Entering directory '/root/.local/share/.cpan/build/Inline-C-0.76-1/_Inline_08taint.14737/build/_08taint_1_p_0965'
make[1]: chmod: Command not found
Makefile:387: recipe for target 'blib/lib/.exists' failed
make[1]: *** [blib/lib/.exists] Error 127
make[1]: Leaving directory '/root/.local/share/.cpan/build/Inline-C-0.76-1/_Inline_08taint.14737/build/_08taint_1_p_0965'

A problem was encountered while attempting to compile and install your Inline
C code. The command that failed was:
  "make > out.make 2>&1" with error code 2

The build directory was:
/root/.local/share/.cpan/build/Inline-C-0.76-1/_Inline_08taint.14737/build/_08taint_1_p_0965

To debug the problem, cd to the build directory, and inspect the output files.

Environment MAKEFLAGS = ''
Environment MAKELEVEL = '1'
Environment PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin'
 at ./t/08taint_1.p line 6.
	...propagated at /root/.local/share/.cpan/build/Inline-C-0.76-1/blib/lib/Inline/C.pm line 869.
BEGIN failed--compilation aborted at ./t/08taint_1.p line 6.
Compilation failed in require at t/08taint.t line 33.
main::require_taint_1() called at t/08taint.t line 28
Test::Warn::warnings_like(CODE(0x9c9ec68), ARRAY(0x9d4dcfc), "warn_test 1") called at t/08taint.t line 28

Looks like your test exited with 2 just after 1.
t/08taint.t .............. Dubious, test returned 2 (wstat 512, 0x200)

Inline-C fails to handle context args pTHX and pTHX_ correctly

Hi,
The demo:


use strict;
use warnings;

use Inline C => Config =>
PRE_HEAD =>
"#define PERL_NO_GET_CONTEXT 1";

use Inline C => <<'EOC';

SV * foo (pTHX_ int x) {
return newSViv(x * 2);
}

int bar (int x) {
return (x * 2);
}

EOC

if(foo(17) == 34) {print "ok 1\n"}
if(bar(18) == 36) {print "ok 2\n"}


This script outputs:
Undefined subroutine &main::foo called at try.pl line 20.

Ok - so the "binding" for foo() is broken. That aspect can be fixed with a "$code =~ s/\b(pTHX_?|aTHX_?)\b//g;" (like has been done wrt the 'const' qualifier).
But there's more to fixing this than simply that.

The solution looks a bit tricky to me.
The fact that PERL_NO_GET_CONTEXT is defined necessitates only that functions that access Perl's API need to give/take the context args. This means that bar() is acceptable in the above script (even though no context arg is provided):

The XS code for that script would need to call foo(aTHX_ x), but bar(x).
That is, the need for the context args must be assessed on a per-function basis.
Of course, the user tells us which functions need the context args (by providing the pTHX/pTHX_ arg to those functions) - and the user also inserts any aTHX/aTHX_ args as needed into the C code.
The parser just needs to write the XS section acceptably ;-)

Cheers,
Rob

old versions

Please remove ETJ/Inline-C-0.62.tar.gz (and possibly earlier) from CPAN. This version is still indexed (probably because in newer versions some module was removed) and is tested by cpantesters smokers causing problems because it hangs.
CPAN mirrors disk space will be freed too.
In case removing is not possible, a new version can be released with empty modules that were removed in older versions.
You can check for other indexed old versions here: http://cpanold.chorny.net/

Why does Inline::C require an upgrade to ExtUtils::MakeMaker?

For the purpose of investigating https://rt.perl.org/Ticket/Display.html?id=123145, I had occasion today to install Inline::C on the laptop I have used since March and in which perl-5.20.1 is my default perl.

$ cpanm Inline::C
--> Working on Inline::C
Fetching http://www.cpan.org/authors/id/E/ET/ETJ/Inline-C-0.65.tar.gz ... OK
Configuring Inline-C-0.65 ... OK
==> Found dependencies: YAML::XS, ExtUtils::MakeMaker, Inline, Pegex
--> Working on YAML::XS
Fetching http://www.cpan.org/authors/id/I/IN/INGY/YAML-LibYAML-0.52.tar.gz ... OK
Configuring YAML-LibYAML-0.52 ... OK
Building and testing YAML-LibYAML-0.52 ... OK
Successfully installed YAML-LibYAML-0.52
--> Working on ExtUtils::MakeMaker
Fetching http://www.cpan.org/authors/id/B/BI/BINGOS/ExtUtils-MakeMaker-7.02.tar.gz ... OK
Configuring ExtUtils-MakeMaker-7.02 ... OK
Building and testing ExtUtils-MakeMaker-7.02 ... OK
Successfully installed ExtUtils-MakeMaker-7.02 (upgraded from 6.98)
--> Working on Inline
Fetching http://www.cpan.org/authors/id/I/IN/INGY/Inline-0.77.tar.gz ... OK
Configuring Inline-0.77 ... OK
Building and testing Inline-0.77 ... OK
Successfully installed Inline-0.77
--> Working on Pegex
Fetching http://www.cpan.org/authors/id/I/IN/INGY/Pegex-0.57.tar.gz ... OK
Configuring Pegex-0.57 ... OK
Building and testing Pegex-0.57 ... OK
Successfully installed Pegex-0.57
Building and testing Inline-C-0.65 ... OK
Successfully installed Inline-C-0.65
5 distributions installed

I was surprised to be forced to upgrade ExtUtils::MakeMaker from the version (6.98) which came with both perl-5.20.0 and perl-5.20.1. My belief is that if a CPAN distribution requires a module distributed with the core, it should not force an upgrade of that distribution at least until a new stable version of Perl is released on an annual basis. To do otherwise, at least without an explicit rationale for the forced upgrade, is basically, IMO, to force the author's or maintainer's eagerness for the "latest and therefore greatest" on the user.

So, can you tell me why I was forced to upgrade ExtUtils::MakeMaker in order to get Inline::C?

Thank you very much.
Jim Keenan

Failed to install via cpanm

I just tried to install Inline::C with cpanm (Perl 5.20.2) but failed.

Here is the error:

    323 #
324 # chmod 755 blib/arch/auto/Math/Simple/Simple.bundle
325 # /Users/leetom/perl5/perlbrew/perls/perl-5.20.2/bin/perl -MExtUtils::Command::MM -e 'cp_nonempty' -- Simple.bs blib/arch/auto/Math/Simple/Simple.bs 644
326 #   Finished "make" Stage
327 #
328 #   Starting "make install" Stage
329 # Running Mkbootstrap for Math::Simple ()
330 # chmod 644 Simple.bs
331 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
332 # ERROR: Can't create '/'
333 # Do not have write permissions on '/'
334 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
335 #  at -e line 1.
336 # make[2]: *** [pure_site_install] Error 13
337 #
338 # A problem was encountered while attempting to compile and install your Inline

test failure in 0.62

0.62 doesn't build on Debian/unstable. Test output:

   dh_auto_test
make[1]: Entering directory '/tmp/buildd/libinline-c-perl-0.62'
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/01syntax.t ............ ok
t/02config.t ............ ok
t/03typemap.t ........... ok
t/04perlapi.t ........... ok
t/05xsmode.t ............ ok
t/06parseregexp.t ....... ok
t/07typemap_multi.t ..... ok
Insecure dependency in chdir while running with -T switch at /usr/share/perl/5.18/File/Path.pm line 284.
END failed--call queue aborted (#1)
    (F) You tried to do something that the tainting mechanism didn't like.
    The tainting mechanism is turned on when you're running setuid or
    setgid, or when you specify -T to turn it on explicitly.  The
    tainting mechanism labels all data that's derived directly or indirectly
    from the user, who is considered to be unworthy of your trust.  If any
    such data is used in a "dangerous" operation, you get this error.  See
    perlsec for more information.

Uncaught exception from user code:
    Insecure dependency in chdir while running with -T switch at /usr/share/perl/5.18/File/Path.pm line 284.
    END failed--call queue aborted.
# Looks like your test exited with 22 just after 10.
t/08taint.t ............. 
Dubious, test returned 22 (wstat 5632, 0x1600)
All 10 subtests passed 
This test could take a couple of minutes to run
t/09parser.t ............ ok
t/10callback.t .......... ok
t/11default_readonly.t .. ok
t/14void_arg.t .......... ok
t/14void_arg_PRD.t ...... ok
t/15ccflags.t ........... ok
t/16ccflagsex.t ......... ok
t/17prehead.t ........... ok
t/18quote_space.t ....... ok
t/19INC.t ............... ok
t/20eval.t .............. ok
t/21read_DATA.t ......... ok
t/22read_DATA_2.t ....... ok
t/23validate.t .......... ok
t/24prefix.t ............ ok
t/25proto.t ............. ok
t/26fork.t .............. ok
t/27inline_maker.t ...... ok
t/release-pod-syntax.t .. skipped: these tests are for release candidate testing

Test Summary Report
-------------------
t/08taint.t           (Wstat: 5632 Tests: 10 Failed: 0)
  Non-zero exit status: 22
Files=27, Tests=121, 45 wallclock secs ( 0.11 usr  0.02 sys + 37.00 cusr  4.08 csys = 41.21 CPU)
Result: FAIL
Failed 1/27 test programs. 0/121 subtests failed.
Makefile:845: recipe for target 'test_dynamic' failed
make[1]: *** [test_dynamic] Error 255
make[1]: Leaving directory '/tmp/buildd/libinline-c-perl-0.62'

Cheers,
gregor, Debian Perl Group

t/27inline_maker.t fails on Windows (Inline-C-0.62)

Currently, this test script outputs a large amount of bewildering garbage on Windows - as can be seen by viewing any of the Windows cpan-testers FAIL reports.

The culprit for most of it seems to be the white space in the assignment (in t/27inline_maker.t):

my $src_dir = File::Spec->catdir($base_dir, 'src dir');

Changing that to a sane assignment such as:

my $src_dir = File::Spec->catdir($base_dir, 'src_dir');

fixes most of the problems with that test script. All tests except test 7 then pass without any noise.
Test 7 still fails with:

Failed test 'make install'
at t/27inline_maker.t line 51.
Can't open file C:\sisyphusion\Inline-C-0.62_Inline_27inline_maker.4256\instdir\lib\perl5\MSWin32-x86-multi-thread\auto\Math\Simple.packlist: Permission denied at C:/MinGW/perl512/lib/ExtUtils/Install.pm line 855
Files found in blib\arch: installing files in blib\lib into architecture dependent library tree
Installing C:\sisyphusion\Inline-C-0.62_Inline_27inline_maker.4256\instdir\lib\perl5\MSWin32-x86-multi-thread\auto\Math\Simple.packlist
Installing C:\sisyphusion\Inline-C-0.62_Inline_27inline_maker.4256\instdir\lib\perl5\MSWin32-x86-multi-thread\auto\Math\Simple\Simple.bs
Installing C:\sisyphusion\Inline-C-0.62_Inline_27inline_maker.4256\instdir\lib\perl5\MSWin32-x86-multi-thread\auto\Math\Simple\Simple.dll
Installing C:\sisyphusion\Inline-C-0.62_Inline_27inline_maker.4256\instdir\lib\perl5\MSWin32-x86-multi-thread\Math\Simple.pm
dmake.EXE: Error code 141, while making 'pure_site_install'

Coming after that is the warning:

cannot remove directory for C:\sisyphusion\Inline-C-0.62_Inline_27inline_maker.
4256\src_dir: Permission denied at t/27inline_maker.t line 43

I think the rmtree() failure is the source of the test 7 failure ... but I haven't yet got a handle on precisely what's going on, or what needs to be done wrt it.

Is it ok to remove the whitespace (as per the alteration given above) ? ... or does that then defeat some purpose ?
If I get "the go-ahead" on that change, I'll then try to sort out the problem with rmtree().

Cheers,
Rob

inline::C compilation with intel icc compiler

Hi,
I am trying to compile some inline::C program with icc, so I have added the following to the arguments of inline::C :

use Inline C => Config => CLEAN_AFTER_BUILD => 0,
CC => '/opt/intel/composer_xe_2015.1.133/bin/intel64/icc',
CCFLAGS => '-openmp',
BUILD_NOISY => 1,
LIBS => '-Wl,--start-group -L/opt/intel/mkl/lib/intel64 -Wl,--end-group -lmkl_core -liomp5 -lmkl_intel_thread -lpthread -ldl -lm';

Everything is fine except when it compiles the undefined symbol: __kmpc_global_thread_num appears. This is due to the lack of library libiomp5.so. However it is specified in the LIBS option.

I checked the Makefile.PL and it appears, but it does not appear in the Makefile generated by Makefile.PL. It seems Makefile.PL is removing it.

So my question is : what can I do to have -liomp5 appear in the Makefile ?

Regards,
JM

Installation Inline::C fails in Ubuntu 14.04.02

cpanm (App::cpanminus) 1.7006 on perl 5.020000 built for x86_64-linux
Work directory is /home/jmerelo/.cpanm/work/1441557932.21398
You have make /usr/bin/make
You have LWP 6.08
You have /bin/tar: tar (GNU tar) 1.27.1
Copyright © 2013 Free Software Foundation, Inc.
Licencia GPLv3+: GNU GPL versión 3 o superior <http://gnu.org/licenses/gpl.html>.
Esto es software libre: es libre de cambiarlo y redistribuirlo.
NO HAY NINGUNA GARANTÍA, en la medida que lo permita la ley.

Escrito por John Gilmore y Jay Fenlason.
You have /usr/bin/unzip
Searching Inline::C on cpanmetadb ...
--> Working on Inline::C
Fetching http://www.cpan.org/authors/id/I/IN/INGY/Inline-C-0.76.tar.gz
-> OK
Unpacking Inline-C-0.76.tar.gz
Entering Inline-C-0.76
Checking configure dependencies from META.json
Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.06)
Checking if you have File::ShareDir::Install 0.06 ... Yes (0.10)
Configuring Inline-C-0.76
Running Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Inline::C
Writing MYMETA.yml and MYMETA.json
-> OK
Checking dependencies from MYMETA.json ...
Checking if you have Pegex 0.58 ... Yes (0.60)
Checking if you have Inline 0.79 ... Yes (0.80)
Checking if you have Parse::RecDescent 1.967009 ... Yes (1.967009)
Checking if you have ExtUtils::MakeMaker 7.00 ... Yes (7.06)
Checking if you have File::Copy::Recursive 0 ... Yes (0.38)
Checking if you have File::Spec 0.8 ... Yes (3.47)
Checking if you have YAML::XS 0 ... Yes (0.59)
Checking if you have Test::More 0.88 ... Yes (1.001014)
Checking if you have version 0.77 ... Yes (0.9908)
Checking if you have IO::All 0 ... Yes (0.86)
Checking if you have Test::Warn 0.23 ... Yes (0.30)
Checking if you have autodie 0 ... Yes (2.23)
Building and testing Inline-C-0.76
cp share/inline-c.pgx blib/lib/auto/share/dist/Inline-C/inline-c.pgx
cp lib/Inline/C/Parser/Pegex/AST.pm blib/lib/Inline/C/Parser/Pegex/AST.pm
cp lib/Inline/C/Parser/RegExp.pm blib/lib/Inline/C/Parser/RegExp.pm
cp lib/Inline/C/Cookbook.pod blib/lib/Inline/C/Cookbook.pod
cp lib/Inline/C.pod blib/lib/Inline/C.pod
cp lib/Inline/C/Parser/Pegex.pm blib/lib/Inline/C/Parser/Pegex.pm
cp lib/Inline/C/ParsePegex.pod blib/lib/Inline/C/ParsePegex.pod
cp lib/Inline/C/ParseRegExp.pod blib/lib/Inline/C/ParseRegExp.pod
cp lib/Inline/C/Parser/Pegex/Grammar.pm blib/lib/Inline/C/Parser/Pegex/Grammar.pm
cp lib/Inline/C/Parser.pm blib/lib/Inline/C/Parser.pm
cp lib/Inline/C/ParseRecDescent.pod blib/lib/Inline/C/ParseRecDescent.pod
cp lib/Inline/C/Parser/RecDescent.pm blib/lib/Inline/C/Parser/RecDescent.pm
cp lib/Inline/C.pm blib/lib/Inline/C.pm
Manifying 5 pod documents
Skip blib/lib/auto/share/dist/Inline-C/inline-c.pgx (unchanged)
PERL_DL_NONLAZY=1 "/home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/000-require-modules.t .. ok
t/01syntax.t ............. ok
t/02config.t ............. ok
t/03typemap.t ............ ok
t/04perlapi.t ............ ok
t/05xsmode.t ............. ok
t/06parseregexp.t ........ ok
t/07typemap_multi.t ...... ok
t/08taint.t .............. ok
This test could take a couple of minutes to run
t/09parser.t ............. ok
t/10callback.t ........... ok
t/11default_readonly.t ... ok
t/14void_arg.t ........... ok
t/14void_arg_PRD.t ....... ok
t/15ccflags.t ............ ok
t/16ccflagsex.t .......... ok
t/17prehead.t ............ ok
t/18quote_space.t ........ ok
t/19INC.t ................ ok
t/20eval.t ............... ok
t/21read_DATA.t .......... ok
t/22read_DATA_2.t ........ ok
t/23validate.t ........... ok
t/24prefix.t ............. ok
t/25proto.t .............. ok
t/26fork.t ............... ok

#   Failed test 'make test'
#   at t/27inline_maker.t line 60.
# make[1]: se ingresa al directorio «/home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir»
# cp lib/Boo/Far/data.txt blib/lib/Boo/Far/data.txt
# cp lib/Boo/Far.pm blib/lib/Boo/Far.pm
# cp lib/Boo.pm blib/lib/Boo.pm
# cp lib/Boo/Far/Faz.pm blib/lib/Boo/Far/Faz.pm
# "/home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/bin/perl" -Mblib -MInline=NOISY,_INSTALL_ -MBoo -e"my %A = (modinlname => 'Boo.inl', module => 'Boo'); my %S = (API => \%A); Inline::satisfy_makefile_dep(\%S);" 2.01 blib/arch
# Can't locate Boo.pm in @INC (you may need to install the Boo module) (@INC contains: /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir/../../blib/arch /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir/../../blib/lib /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/blib/lib /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/blib/arch /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/x86_64-linux /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0 /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.0/x86_64-linux /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.0 .).
# BEGIN failed--compilation aborted.
# make[1]: *** [Boo.inl] Error 2
# make[1]: se sale del directorio «/home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir»

#   Failed test 'make test'
#   at t/27inline_maker.t line 60.
# make[1]: se ingresa al directorio «/home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir»
# cp Simple.pm blib/lib/Math/Simple.pm
# "/home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/bin/perl" -Mblib -MInline=NOISY,_INSTALL_ -MMath::Simple -e"my %A = (modinlname => 'Math-Simple.inl', module => 'Math::Simple'); my %S = (API => \%A); Inline::satisfy_makefile_dep(\%S);" 1.23 blib/arch
# Can't locate Math/Simple.pm in @INC (you may need to install the Math::Simple module) (@INC contains: /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir/../../blib/arch /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir/../../blib/lib /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/blib/lib /home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/blib/arch /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/x86_64-linux /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0 /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.0/x86_64-linux /home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/lib/5.20.0 .).
# BEGIN failed--compilation aborted.
# make[1]: *** [Math-Simple.inl] Error 2
# make[1]: se sale del directorio «/home/jmerelo/.cpanm/work/1441557932.21398/Inline-C-0.76/_Inline_27inline_maker.26217/src dir»
# Looks like you failed 2 tests of 8.
t/27inline_maker.t ....... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/8 subtests 
t/28autowrap.t ........... ok
t/30cppflags.t ........... ok
t/parse-pegex.t .......... ok
t/pegex-parser.t ......... skipped: $ENV{PERL_INLINE_DEVELOPER_TEST} not set
t/release-pod-syntax.t ... skipped: these tests are for release candidate testing

Test Summary Report
-------------------
t/27inline_maker.t     (Wstat: 512 Tests: 8 Failed: 2)
  Failed tests:  2, 6
  Non-zero exit status: 2
t/parse-pegex.t        (Wstat: 0 Tests: 24 Failed: 0)
  TODO passed:   4, 7-9
Files=32, Tests=154, 28 wallclock secs ( 0.08 usr  0.01 sys + 22.85 cusr  3.81 csys = 26.75 CPU)
Result: FAIL
Failed 1/32 test programs. 2/154 subtests failed.
make: *** [test_dynamic] Error 255
-> FAIL Installing Inline::C failed. See /home/jmerelo/.cpanm/work/1441557932.21398/build.log for details. Retry with --force to force install it.

After installing Math::Simple by hand, it fails with a different error

#   Failed test 'make test'
#   at t/27inline_maker.t line 60.
# make[1]: se ingresa al directorio «/home/jmerelo/.cpanm/work/1441558253.27493/Inline-C-0.76/_Inline_27inline_maker.32317/src dir»
# cp Simple.pm blib/lib/Math/Simple.pm
# "/home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/bin/perl" -Mblib -MInline=NOISY,_INSTALL_ -MMath::Simple -e"my %A = (modinlname => 'Math-Simple.inl', module => 'Math::Simple'); my %S = (API => \%A); Inline::satisfy_makefile_dep(\%S);" 1.23 blib/arch
# PERL_DL_NONLAZY=1 "/home/jmerelo/perl5/perlbrew/perls/perl-5.20.0/bin/perl" "-Iblib/lib" "-Iblib/arch" test.pl
#1..2
# The extension 'Math::Simple' is not properly installed in path:
#   'blib/arch'
# 
# If this is a CPAN/distributed module, you may need to reinstall it on your
# system.
# 
# To allow Inline to compile the module in a temporary cache, simply remove the
# Inline config option 'VERSION=' from the Math::Simple module.
# 
#  at test.pl line 0.
# INIT failed--call queue aborted, <DATA> line 1.
# # Looks like your test exited with 2 before it could output anything.
# make[1]: *** [test_dynamic] Error 2
# make[1]: se sale del directorio «/home/jmerelo/.cpanm/work/1441558253.27493/Inline-C-0.76/_Inline_27inline_maker.32317/src dir»
# Looks like you failed 2 tests of 8.

force recompile when linked shared library changes

When I upgraded my version of opencv from 2.4 to 3.0, my script failed with the following:

$ myprog.pl
Had problems bootstrapping Inline module 'MyMod::OpenCV_e076'

Can't load '/private/tmp/lib/auto/MyMod/OpenCV_e076/OpenCV_e076.bundle' for module MyMod::OpenCV_e076: dlopen(/private/tmp/lib/auto/MyMod/OpenCV_e076/OpenCV_e076.bundle, 1): Library not loaded: /opt/local/lib/libopencv_core.2.4.dylib
  Referenced from: /private/tmp/lib/auto/MyMod/OpenCV_e076/OpenCV_e076.bundle
  Reason: image not found at /home/perlbrew/perls/perl-5.22/lib/5.22.0/darwin-2level/DynaLoader.pm line 197.
 at /home/perlbrew/perls/perl-5.22/lib/site_perl/5.22.0/Inline.pm line 533.

 at /Users/y/perl5/lib/MyMod/OpenCV.pm line 25.
BEGIN failed--compilation aborted at /Users/y/perl5/lib/MyMod/OpenCV.pm line 25.
Compilation failed in require at /home/perlbrew/perls/perl-5.22/lib/site_perl/5.22.0/Module/Runtime.pm line 317.

I'm specifying the library like so: use Inline C => Config => LIBS => '-lopencv_core', so I was hoping that the symlink change for libopencv_core.dylib to libopencv_core.3.0.dylib instead of libopencv_core.2.4.dylib would trigger a recompile. Is it possibly for Inline::C to detect these types of changes and recompile instead of causing a failure and forcing a manual recompile?

prototypes and prototype config options don't work

Here's a gist demonstrating the issue:

https://gist.github.com/daoswald/7008cc27c3b8c4509a09

In short, specifying a prototype for an Inline function doesn't actually do anything useful.

Perl's built-in "prototype" function correctly reports the prototype. Unfortunately, since prototypes are compiletime checked, and Inline's work is completed too late, the prototype isn't set in time for compiletime checking.

This may be insurmountable with respect to Inline-dependent code. However, it might become resolved automatically in the future as Inline produces distributable XS code, albiet only for distributable XS code produced by Inline.

ellipsis syntax doesn't bind with default parser (0.62_03)

With 0.62_03 this script:

use warnings;
use strict;

use Inline C => <<'EOC';

void foo(SV * x, ...) {
dXSARGS;
int i;

for(i = 0; i < items; ++i) printf("hello\n");
}

EOC

foo(1, 2, 3);

Outputs:
Undefined subroutine &main::foo called at try.pl line 15.

Works fine if either ParseRecDescent or ParseRegExp are used.

Better error message when type not in typemap

If Inline::C tries to wrap a function where one of the argument types is not in the standard typemap, you get a build error like undefined reference to 'XS_unpack_charPtrPtr'. This is a bit perplexing. It would be better to check this earlier and produce a friendly message like function foo takes parameter x of type char ** but that type is not in the typemap file.

Way to request function not be wrapped

Sometimes when writing C code inline you want to make a 'private' function which will be called only from C code and not from Perl. You can stop Inline::C from seeing it by changing to K&R declaration style or other manoeuvres that stop the parser recognizing it. But it would be cleaner to have an explicit way:

/* no Inline */ void foo(int x) { ... }

Test suite failures with EU::MM 7.06

t/26fork.t ............... ok
 #   Failed test 'make test'
 #   at t/27inline_maker.t line 60.
 # make[1]: Entering directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir'
 # cp Simple.pm blib/lib/Math/Simple.pm
 # "/usr/bin/perl" -Mblib -MInline=NOISY,_INSTALL_ -MMath::Simple -e"my %A = (modinlname => 'Math-Simple.inl', module => 'Math::Simple'); my %S = (API => \%A); Inline::satisfy_makefile_dep(\%S);" 1.23 blib/arch
 # Can't locate Math/Simple.pm in @INC (you may need to install the Math::Simple module) (@INC contains: /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir/../../blib/arch /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir/../../blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/arch /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .).
 # BEGIN failed--compilation aborted.
 # Makefile:829: recipe for target 'Math-Simple.inl' failed
 # make[1]: Leaving directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir'
 # make[1]: **\* [Math-Simple.inl] Error 2
 #   Failed test 'make test'
 #   at t/27inline_maker.t line 60.
 # make[1]: Entering directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir'
 # cp lib/Boo/Far.pm blib/lib/Boo/Far.pm
 # cp lib/Boo/Far/Faz.pm blib/lib/Boo/Far/Faz.pm
 # cp lib/Boo.pm blib/lib/Boo.pm
 # cp lib/Boo/Far/data.txt blib/lib/Boo/Far/data.txt
 # "/usr/bin/perl" -Mblib -MInline=NOISY,_INSTALL_ -MBoo -e"my %A = (modinlname => 'Boo.inl', module => 'Boo'); my %S = (API => \%A); Inline::satisfy_makefile_dep(\%S);" 2.01 blib/arch
 # Can't locate Boo.pm in @INC (you may need to install the Boo module) (@INC contains: /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir/../../blib/arch /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir/../../blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/arch /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .).
 # BEGIN failed--compilation aborted.
 # Makefile:835: recipe for target 'Boo.inl' failed
 # make[1]: Leaving directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.13979/src dir'
 # make[1]: **\* [Boo.inl] Error 2
 # Looks like you failed 2 tests of 8.
t/27inline_maker.t ....... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/8 subtests 

edited by @mohawk2 for formatting

Inline::Struct buggy

I've asked the author of Inline::Struct for co-maint, which he's given me. It appears the I::S support code is buggy. From a 2006 bug report (on https://rt.cpan.org/Ticket/Display.html?id=19624):

Config for Inline C of LIB or INC parameters are ignored if the STRUCT config parameter is stated afterwards. If STRUCT is specified before then the STRUCT parameter is ignored. If stated in the same configuration section then LIB and INC are ignored.

The STRUCT is used and the structure methods are properly created, but the INC configuration is ignored:

use Inline C => Config =>
    BUILD_NOISY => 1,
    STRUCTS => ['Cstruct'],
    LIBS => '-L/src/libdir1 -L/src/libdir2 -L/src/libdir3 -llib1 -llib2 -llib3',
    INC => '-I/include/dir1 \ -I/include/dir2 \ -I/include/dir3';

while this apparently works:

use Inline C => Config =>
    BUILD_NOISY => 1,
    STRUCTS => ['Cstruct'],
    LIBS => '-L/src/libdir1 -L/src/libdir2 -L/src/libdir3 -llib1 -llib2 -llib3',
    CCFLAGS => '-I/include/dir1 \ -I/include/dir2 \ -I/include/dir3';

Inline::C and openmp

Hi everybody,
I am new to perl and inline::C, anyway I could write some program to compute Mandelbrot set using a C function called from perl.
I would like to know if it is possible to compile this code with OpenMP ? I have tried to add this to the config section like
use Inline C => config => CCFLAGSEX => '-fopenmp';

but it does not seem to be taken into account when compiling.
So my question : is it possible and how to do it ?

Thank you for your help.

Inline::C doesn't know when to sv_force_normal or to respect SvREADONLY

Found in Perl-GPU/OpenGL-Modern#16

This code does not work reliably: https://gist.github.com/wchristian/6df5740d442002a311cbeb8282cfca4d

Zefram and mst opined in #p5p that this might be fixable:

(Zefram) your four() function doesn't sv_force_normal() or otherwise respect SvREADONLY
(mst) I guess nobody realised they needed to teach Inline::C about that
(Zefram) Inline::C can't tell whether the function body is going to try to mutate the string. XS has the same problem
(Mithaldu) is there a quick and common way to declare those inputs as "gonna mutate those"?
(Zefram) no, it's a rare need
(Zefram) you'll have to take an SV* and do it yourself, or create a custom typemap to do it if you need it a lot
(Zefram) the failure to respect SvREADONLY is a reportable bug in any case
(Mithaldu) how does one normally respect SvREADONLY?
(Zefram) if(SvREADONLY(argsv)) croak("woah nelly!");
(Zefram) sv_force_normal() is a better way, because COWed strings are SvREADONLY but may actually be mutatable
(Zefram) sv_force_normal() will de-COW and remove the SvREADONLY status if you're allowed to mutate the scalar

Pegex-related (?) error with 0.62_11

The following program does not work with Inline::C 0.62_11. It worked with earler Inline::C versions.

#!/usr/bin/perl -w

use strict;
use Inline C => 'DATA';

_dump_ptr(1,2,3);

__END__
__C__
void _dump_ptr(long d1, long d2, int use_long_output) {
    printf("hello, world!\n");
}

Error message is:

Could not find a typemap for C type 'd'.

The generated xs file looks broken:

void
_dump_ptr (1, 2, use_long_output)
        d       1
        d       2
        int     use_long_output

t/27inline_maker.t fails on MS Windows

Hi,

I have experienced the following failure on MS Windows (gcc-4.8.3)

Regards
kmx

Building and testing Inline-C-0.73 ... cp share\inline-c.pgx blib\lib\auto\share\dist\Inline-C\inline-c.pgx
cp lib/Inline/C/Parser/RecDescent.pm blib\lib\Inline\C\Parser\RecDescent.pm
cp lib/Inline/C/Parser/Pegex/AST.pm blib\lib\Inline\C\Parser\Pegex\AST.pm
cp lib/Inline/C/ParseRegExp.pod blib\lib\Inline\C\ParseRegExp.pod
cp lib/Inline/C.pod blib\lib\Inline\C.pod
cp lib/Inline/C.pm blib\lib\Inline\C.pm
cp lib/Inline/C/Parser/Pegex.pm blib\lib\Inline\C\Parser\Pegex.pm
cp lib/Inline/C/Parser/Pegex/Grammar.pm blib\lib\Inline\C\Parser\Pegex\Grammar.pm
cp lib/Inline/C/Parser/RegExp.pm blib\lib\Inline\C\Parser\RegExp.pm
cp lib/Inline/C/Parser.pm blib\lib\Inline\C\Parser.pm
cp lib/Inline/C/Cookbook.pod blib\lib\Inline\C\Cookbook.pod
cp lib/Inline/C/ParsePegex.pod blib\lib\Inline\C\ParsePegex.pod
cp lib/Inline/C/ParseRecDescent.pod blib\lib\Inline\C\ParseRecDescent.pod
Skip blib\lib\auto\share\dist\Inline-C\inline-c.pgx (unchanged)
"C:\strawberry\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/000-require-modules.t .. ok
t/01syntax.t ............. ok
t/02config.t ............. ok
t/03typemap.t ............ ok
t/04perlapi.t ............ ok
t/05xsmode.t ............. ok
t/06parseregexp.t ........ ok
t/07typemap_multi.t ...... ok
t/08taint.t .............. ok
This test could take a couple of minutes to run
t/09parser.t ............. ok
t/10callback.t ........... ok
t/11default_readonly.t ... ok
t/14void_arg.t ........... ok
t/14void_arg_PRD.t ....... ok
t/15ccflags.t ............ ok
t/16ccflagsex.t .......... ok
t/17prehead.t ............ ok
t/18quote_space.t ........ ok
t/19INC.t ................ ok
t/20eval.t ............... ok
t/21read_DATA.t .......... ok
t/22read_DATA_2.t ........ ok
t/23validate.t ........... ok
t/24prefix.t ............. ok
t/25proto.t .............. ok
t/26fork.t ............... ok

#   Failed test 'make install'
#   at t/27inline_maker.t line 60.
# Can't open file C:\STRAWB~1\data\.cpanm\work\1422211646.3912\Inline-C-0.73\_Inline_27inline_maker.4112\inst dir\lib\perl5\MSWin32-x64-multi-thread\auto\Math\Simple\.packlist: Permission denied at C:/strawberry/perl/lib/ExtUtils/Install.pm line 842.

# Files found in blib\arch: installing files in blib\lib into architecture dependent library tree

# Installing C:\STRAWB~1\data\.cpanm\work\1422211646.3912\Inline-C-0.73\_Inline_27inline_maker.4112\inst dir\lib\perl5\MSWin32-x64-multi-thread\auto\Math\Simple\.packlist

# Installing C:\STRAWB~1\data\.cpanm\work\1422211646.3912\Inline-C-0.73\_Inline_27inline_maker.4112\inst dir\lib\perl5\MSWin32-x64-multi-thread\auto\Math\Simple\Simple.xs.dll

# Installing C:\STRAWB~1\data\.cpanm\work\1422211646.3912\Inline-C-0.73\_Inline_27inline_maker.4112\inst dir\lib\perl5\MSWin32-x64-multi-thread\Math\Simple.pm

# dmake:  Error code 141, while making 'pure_vendor_install'

# Looks like you failed 1 test of 8.
t/27inline_maker.t ....... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/8 subtests 
t/28autowrap.t ........... ok
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
'diff' is not recognized as an internal or external command,
operable program or batch file.
t/parse-pegex.t .......... ok
'rm' is not recognized as an internal or external command,
operable program or batch file.
'rm' is not recognized as an internal or external command,
operable program or batch file.
t/pegex-parser.t ......... skipped: $ENV{PERL_INLINE_DEVELOPER_TEST} not set
t/release-pod-syntax.t ... skipped: these tests are for release candidate testing

Test Summary Report
-------------------
t/27inline_maker.t     (Wstat: 256 Tests: 8 Failed: 1)
  Failed test:  7
  Non-zero exit status: 1
t/parse-pegex.t        (Wstat: 0 Tests: 24 Failed: 0)
  TODO passed:   4, 7-9
Files=31, Tests=153, 416 wallclock secs ( 0.48 usr +  0.05 sys =  0.53 CPU)
Result: FAIL
Failed 1/31 test programs. 1/153 subtests failed.
dmake.exe:  Error code 255, while making 'test_dynamic'

inline::c 0.75 fails to write Makefile.PL

I’m trying to install modules Inline::C and Pegex into a Perl 5 version 12 installation.
And the same error occurs:

syntax error at Makefile.PL line 13, near "install_share dist"
BEGIN not safe after errors--compilation aborted at Makefile.PL line 86.
Warning: No success on command[/usr/local/bin/perl Makefile.PL PREFIX=/usr/local/lib/perl5/5.12.4]
INGY/Inline-C-0.75.tar.gz
/usr/local/bin/perl Makefile.PL PREFIX=/usr/local/lib/perl5/5.12.4 -- NOT OK
Running make test
Make had some problems, won't test
Running make install
Make had some problems, won't install
Failed during this command:
INGY/Inline-C-0.75.tar.gz : writemakefile NO '/usr/local/bin/perl Makefile.PL PREFIX=/usr/local/lib/perl5/5.12.4' returned status 65280

Here’s what the Makefile.PL looks like at point of failure:

use File::ShareDir::Install;
$File::ShareDir::Install::INCLUDE_DOTFILES = 1;
$File::ShareDir::Install::INCLUDE_DOTDIRS = 1;
install_share dist => "share"; <<<<< line 13

The other pre-reqs are installed, along with File::ShareDir::Install (version 0.10)

What can I do to solve or get around this???
Thanks for ANY suggestions!

Makefile.PL needs non-core module

The 0.62_03 Makefile.PL wants to load File::ShareDir::Install - but there's no guarantee that the module will be present.
If File::ShareDir::Install has not previously been installed, then the Makefile.PL simply aborts:

Can't locate File/ShareDir/Install.pm in @inc .... at Makefile.PL line 10

(When this happens on a smoker, no test report is generated.)

Neatest solution I can think of is to have Inline's Makefile.PL specify File::ShareDir::Install as a prerequisite - though, of course, strictly speaking that module is not a prerequisite for Inline.

Is there a preferable way of dealing with this ?

Cheers,
Rob

C Preprocessor Flags Not Properly Passed To Inline::Filters::Preprocess()

This is an issue in both Inline::C and Inline::Filters, we need Preprocess() to correctly utilize a new "cppflags" option containing command-line arguments to be passed directly to the C preprocessor cpp.

I already have working code fixes for both Inline::C and Inline::Filters, I will create docs and tests and create a pull request in the next few days.

Inline C has no tests for prototypes for generated XSubs.

PROTOTYPES: DISABLE appears to be the default for Inline-generated xsubs. There appears to be no way to change that, and we haven't provided a means for authors to specify prototypes for a specific Inline-generated subroutine anyway.

Proposal:

use Inline Config => PROTOTYPE => { subname => 'perl prototype', another_subname, => 'some other prototype' };

Internally this should invert the "PROTOTYPES: DISABLED" to "ENABLED". It should also apply the correct prototype(s) to the subname(s) listed. It should further override "ENABLED" for any subs not listed, setting those that are unlisted specifically to "DISABLED".

Fixing this in Inline::C would allow Inline::CPP to benefit from the same feature.

Possibly remove code dealing with older perls

Now that we dep on perl 5.8.1, we can remove ocde that deals with older perls.

I think we should remove code from tests, but maybe leave in code that would
break the runtime on older perls.

I don't want to support older perls, but intentionally breaking things seems
like bad form.

Opinions?

USING is not back compatible.

Old usage:

use Inline C => using => 'ParseRecDescent';

New syntax:

use Inline C => using => 'Inline::C::Parser::RecDescent';

Or:

use Inline C => using => 'RecDescent';

We need to provide special support for the 2 old parsers to DTRT:

  • ParseRecDescent
  • ParseRegExp

Maybe with tests :)

New Version Of Inline::C Fails Basic Tests

Something in the latest versions of Inline and/or Inline::C has caused 3 of my most basic and long-standing tests to start failing without compiler errors. I've isolated 1 of the 3 failing tests to start with:

https://github.com/wbraswell/rperl/blob/master/bin/development/inline_c_debug.pl

These now-failing tests are based directly on the original Inline::C Cookbook code:

http://search.cpan.org/~sisyphus/Inline-0.55/C/C-Cookbook.pod

(Now a broken link in metacpan: https://metacpan.org/pod/Inline::C-Cookbook)

I am running the following software versions:

Inline v0.68
Inline::C v0.62_03
Inline::CPP v0.55_002
Perl v5.18.2

Until now, this test always returned the following string output:

'Hello Larry! Hello Ingy! Hello Reini! Hello Neil! Hello Sisyphus! Hello Davido!'

Now it seems to compile fine (no compiler errors), but it just fails as if it did not bind to the correct function name:

Undefined subroutine &main::greetings_char called at bin/development/inline_c_debug.pl line 19.

[Win32]t/TestInlineSetup.pm unworkable on Windows.

Hi,
The Inline-C-0.62 test suite produces lots of warnings like:

cannot unlink file for C:\sisyphusion\Inline-C-0.62_Inline_01syntax.508\lib\auto_01syntax_t_05dd_01syntax_t_05dd.dll: Permission denied at t/TestInlineSetup.pm line 35.

(For the full scale of these and ensuing warnings see, for example:

http://www.cpantesters.org/cpan/report/d5d76ac2-97ed-1014-92c7-6d122b825c07

The problem is that the specified dll is still in use - and Windows will not allow that file to be removed while it's still in use. In pondering what to do about this, I came upon a couple of questions for which I have no answer.

  1. Why do we want to create and destroy the build dir every time a test script is run ?
  2. Why do we give these build dirs names that are probably (but not inevitably) unique ? Given that there's a good reason (which I'm not seeing) that these build dirs ought to be created and destroyed, why not just give them the same name ?

Cheers,
Rob

t/27inline_maker.t test fails with ExtUtils-MakeMaker-7.12

After upgrading ExtUtils-MakeMaker from 7.10 to 7.12 t/27inline_maker.t test fails:

t/26fork.t ............... ok
#   Failed test 'make test'
#   at t/27inline_maker.t line 60.
# make[1]: Entering directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir'
# cp lib/Boo/Far/Faz.pm blib/lib/Boo/Far/Faz.pm
# cp lib/Boo/Far.pm blib/lib/Boo/Far.pm
# cp lib/Boo.pm blib/lib/Boo.pm
# cp lib/Boo/Far/data.txt blib/lib/Boo/Far/data.txt
# "/usr/bin/perl" -Mblib -MInline=NOISY,_INSTALL_ -MBoo -e"my %A = (modinlname => 'Boo.inl', module => 'Boo'); my %S = (API => \%A); Inline::satisfy_makefile_dep(\%S);" 2.01 blib/arch
# Can't locate Boo.pm in @INC (you may need to install the Boo module) (@INC contains: /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir/../../blib/arch /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir/../../blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/arch /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .).
# BEGIN failed--compilation aborted.
# Makefile:843: recipe for target 'Boo.inl' failed
# make[1]: Leaving directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir'
# make[1]: *** [Boo.inl] Error 2
#   Failed test 'make test'
#   at t/27inline_maker.t line 60.
# make[1]: Entering directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir'
# cp Simple.pm blib/lib/Math/Simple.pm
# "/usr/bin/perl" -Mblib -MInline=NOISY,_INSTALL_ -MMath::Simple -e"my %A = (modinlname => 'Math-Simple.inl', module => 'Math::Simple'); my %S = (API => \%A); Inline::satisfy_makefile_dep(\%S);" 1.23 blib/arch
# Can't locate Math/Simple.pm in @INC (you may need to install the Math::Simple module) (@INC contains: /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir/../../blib/arch /builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir/../../blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/lib /builddir/build/BUILD/Inline-C-0.76/blib/arch /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .).
# BEGIN failed--compilation aborted.
# Makefile:837: recipe for target 'Math-Simple.inl' failed
# make[1]: *** [Math-Simple.inl] Error 2
# make[1]: Leaving directory '/builddir/build/BUILD/Inline-C-0.76/_Inline_27inline_maker.16203/src dir'
# Looks like you failed 2 tests of 8.
t/27inline_maker.t ....... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/8 subtests 

According to CPAN test matrix, it fails even with ExtUtils-MakeMaker-7.11_01.

Scripts run in /git_tree/perl/Porting won't build

This was initially reported by demerphq to the Inline mailing list:

http://www.nntp.perl.org/group/perl.inline/2014/07/msg4714.html

Briefly, problems were experienced when he tried building a simple Inline::C script located in /git_tree/perl/Porting, though the same script built and ran fine when located in a different directory.
Eventually, demerphq narrowed it down to this:

When the script was run in the "problem" directory, MakeMaker created a Makefile that contained (incorrectly):

PERL_LIB = ../../../../lib
PERL_ARCHLIB = ../../../../lib

When the same script was run in another directory, MakeMaker replaced those incorrect assignments with (correctly):

PERL_LIB = /home/yorton/perl5/perlbrew/perls/perl-5.14.4/lib/5.14.4
PERL_ARCHLIB = /home/yorton/perl5/perlbrew/perls/perl-5.14.4/lib/5.14.4/x86_64-linux

This issue is raised here in order that it be investigated further.

Cheers,
Rob

t/pegex-parser.t may fail on Mac OS X

I see the following error while running the test suite on a Mac OS X El Capitan with homebrew perl518:

rm: _Inline*: No such file or directory
rm: -fr: No such file or directory
rm: _Inline: is a directory
rm: -fr: No such file or directory
# Looks like your test exited with 256 before it could output anything.
t/pegex-parser.t ......... skipped: $ENV{PERL_INLINE_DEVELOPER_TEST} not set

It seems that the rm here does not like having the options after the files. Using rm -rf _Inline* instead seems to fix the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.