ingydotnet / inline-c-pm

10 stars 19 forks source link

prototypes and prototype config options don't work #28

Open daoswald opened 10 years ago

daoswald commented 10 years ago

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.

sisyphus commented 10 years ago

From: David Oswald Sent: Friday, October 24, 2014 6:53 AM To: ingydotnet/inline-c-pm Subject: [inline-c-pm] prototypes and prototype config options don't work (#28)

(Feel free to ignore this post - complete and utter prototyping idiot here.)

What does a correct XS file for the demo program look like ??

I used InlineX::C2XS to generate:

include "EXTERN.h"

include "perl.h"

include "XSUB.h"

long add( long a, long b ) { return a+b; }

long subtract ( long a, long b ) { return a-b; }

long multiply ( long a, long b ) { return a*b; }

MODULE = Foo PACKAGE = Foo

PROTOTYPES: ENABLE

long add (a, b) long a long b PROTOTYPE: $$

long subtract (a, b) long a long b PROTOTYPE: DISABLE

long multiply (a, b) long a long b PROTOTYPE: $$

But it's the same compile-time errors - 'say add(@{[2,1]});' generates: Not enough arguments for Foo::add at t/test1.t line 13, near "})"

and 'say multiply(@{[2,1]});' generates: Not enough arguments for Foo::multiply at t/test1.t line 19, near "})"

Is there something wrong with that XS file ? ... or is the error in the way the functions are being accessed from perl ?

Cheers, Rob

daoswald commented 10 years ago

The XS file is fine, which is good news. The problem is that as long as Inline is in control the prototypes aren't checked at compiletime.

sisyphus commented 10 years ago

However, that code was compiled as a normal module - completely free of Inline's influence. Yet the problem persists.

sisyphus commented 10 years ago

Aaah ... ignore that last post. I now get the point. Cheers, Rob