Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h2xs AUTOLOAD problem #991

Closed
p5pRT opened this issue Dec 26, 1999 · 3 comments
Closed

h2xs AUTOLOAD problem #991

p5pRT opened this issue Dec 26, 1999 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 26, 1999

Migrated from rt.perl.org#1941 (status was 'resolved')

Searchable as RT1941$

@p5pRT
Copy link
Author

p5pRT commented Dec 26, 1999

From swmcd@world.std.com

sub AUTOLOAD {
[...]
  no strict 'refs';
  *$AUTOLOAD = sub () { $val };
  goto &$AUTOLOAD;
}

  *$AUTOLOAD = sub () { $val };
  ^^
The autoloaded sub is declared with a prototype, which causes an error
if &$AUTOLOAD doesn't have the same prototype when the assignment
executes.

So if I have a constant in a .h file

  #define FOO 17

and I try to get to it from Perl

  print FOO();

I get an error

  Prototype mismatch​: sub Foo​::FOO vs () at blib/lib/Foo.pm line 40.

unless I predeclare FOO() with the correct prototype

  sub FOO ();

Is this a bug or a feature?

- SWM

world​:~/PM/dev/Foo>perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration​:
  Platform​:
  osname=irix, osvers=6.2, archname=IP19-irix
  uname='irix64 world 6.2 03131016 ip19 '
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='cc -n32', optimize=' ', gccversion=
  cppflags='-D_BSD_TYPES -D_BSD_TIME -woff -I/usr/local/include
-DLANGUAGE_C'
  ccflags ='-D_BSD_TYPES -D_BSD_TIME -woff 1009,1110,1184
-I/usr/local/include -DLANGUAGE_C'
  stdchar='unsigned char', d_stdstdio=define, usevfork=false
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
  alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries​:
  ld='cc -n32', ldflags =' -L/usr/local/lib32 -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib32 /lib32 /lib /usr/lib
  libs=-lm -lc
  libc=/usr/lib32/libc.so, so=so, useshrplib=false,
libperl=libperl.a
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-n32 -shared -L/usr/local/lib32
-L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Built under irix
  Compiled at Sep 22 1999 10​:45​:43
  @​INC​:
  /home/abhaile/swmcd/perl/lib/5.00503/IP19-irix
  /home/abhaile/swmcd/perl/lib/5.00503
  /home/abhaile/swmcd/perl/lib/site_perl/5.005/IP19-irix
  /home/abhaile/swmcd/perl/lib/site_perl/5.005
  .

@p5pRT
Copy link
Author

p5pRT commented Dec 27, 1999

From @gsar

On Mon, 27 Dec 1999 01​:21​:53 EST, Steven W McDougall wrote​:

h2xs generates AUTOLOAD() like this

sub AUTOLOAD {
[...]
no strict 'refs';
*$AUTOLOAD = sub () { $val };
goto &$AUTOLOAD;
}

*$AUTOLOAD = sub () { $val };
^^
The autoloaded sub is declared with a prototype, which causes an error
if &$AUTOLOAD doesn't have the same prototype when the assignment
executes.

So if I have a constant in a .h file

#define FOO 17

and I try to get to it from Perl

print FOO();

I get an error

Prototype mismatch​: sub Foo​::FOO vs () at blib/lib/Foo.pm line 40.

unless I predeclare FOO() with the correct prototype

sub FOO ();

Is this a bug or a feature?

It is a feature. You are expected to define constant subs with an empty
prototype. IIRC, the version of h2ph in 5.00503 will do this for you.

Sarathy
gsar@​ActiveState.com

@p5pRT p5pRT closed this as completed Nov 28, 2003
@p5pRT
Copy link
Author

p5pRT commented Nov 28, 2003

From The RT System itself

feature, not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant