XS Constants peculiarity

Graham Barr gbarr at pobox.com
Thu Oct 28 19:25:35 BST 2010


On Oct 28, 2010, at 10:09 , Dirk Koopman wrote:

> On 28/10/10 17:26, Chris Jack wrote:
>> 
>> Dirk Koopman djk at tobit.co.uk wrote:
>>> This is not my stuff, this is generated from the original header file(s).
>>> 
>>> Prototypes? Functions??
>> 
>> What kind of a solution are you looking for here and what is your real problem?
> 
> There is a fair but not insurmountable amount of code. RK+LOCK is common (meaning Read Key with Lock on some C-Isam files). More people used to the C version of the system are likely to start using it and RK+LOCK is a even more common idiom there.
> 
> Manually defining all the constants using "use constant" is IMHO a cop out without understanding why.
> 
>> 
>> Have you tried the suggestion about surrounding your constants in round brackets? Or is this so widespread in your code that it would take too long.
>> 
> 
> Yes, and it fixes the problem.
> 
> There are several hundred constants. Some of which are bit maps.
> 
> However it does not explain why a constant, that is generated from a header file by h2xs, is taken to be a function with arguments. Especially as all the XS code (and generated C) implies it is an integer.

It depends how the functions themselves are defined and exported from the module.

h2xs IIRC depends on AUTOLOAD to actually make the constant subs get defined. However this does not happen until the constant is first needed at runtime and the import sub is really exported an undefined subroutine, causing AUTOLOAD to be called when needed.

THe smallest should would be to make your import sub create the sub when it is imported and ensure that sub is created with a prototype of (), then you code for RK+LOCK will work.

Graham.




More information about the london.pm mailing list