develooper Front page | perl.perl5.porters | Postings from July 2003

Re: Which platforms need symbols to export to be explicitly listed?

Thread Previous | Thread Next
From:
Steve Hay
Date:
July 30, 2003 09:14
Subject:
Re: Which platforms need symbols to export to be explicitly listed?
Message ID:
3F27EF54.3070900@uk.radan.com
Randy Kobes wrote:

>On Wed, 30 Jul 2003, Steve Hay wrote:
>
>  
>
>>I'll just enclose the XS code that
>>uses PerlIO_isutf8() inside
>>
>>#if PERL_VERSION >= 8 && defined(PerlIO_isutf8)
>>...
>>#endif
>>
>>    
>>
>I don't have access to my Win32 machine with a compiler at the
>moment to test this, but using "defined(PerlIO_isutf8)" in this
>way may depend on the order the Perl header files are included,
>as well as on the perl version. I checked for a 5.6.1, and
>PerlIO_isutf8 isn't in the Perl headers, so this should be OK in
>that case.  However, in the 5.8.0 C:\Perl\lib\CORE\perlio.h
>there's
>
>#ifndef PerlIO_isutf8
>extern int PerlIO_isutf8(PerlIO *);
>#endif
>
>So, if this has been seen already, PerlIO_isutf8 would be
>defined, but then a link error would result if PerlIO_isutf8
>wasn't in the library.
>  
>
OK, now I'm really confused.

What you say makes sense, albeit with some confusion over 
declaration/definition:  the "extern int PerlIO_isutf8(PerlIO *)" line 
above is a declaration of the function, not a definition of it, so what 
should "#if defined(PerlIO_isutf8)" do?

I tried out this test program:

#include <stdio.h>
extern void foo(void);
void main(void) {
#if defined(foo)
    foo();
#else
    printf("foo is NOT defined\n");
#endif
}

This compiles & links OK, even though the promised "external" definition 
of foo() is not supplied.  The reason is, of course, that the "#if 
defined(foo)" test returns false.

This made me think that what I had proposed would be OK after all.  
However, I then tried this:

#include <stdio.h>
void foo(void) {
    printf("foo is defined\n");
}
void main(void) {
#if defined(foo)
    foo();
#else
    printf("foo is NOT defined\n");
#endif
}

This, of course, also compiles & links OK, but, to my surprise, prints 
"foo is NOT defined"!  Am I missing something here?  Why does "#if 
defined(foo)" return false immediately after foo() has been defined?

Anyway, all this makes me think that the "#if defined(PerlIO_isutf8)" 
plan might not be such a good idea, even if I could get it working.  The 
problem with perl-5.8.0 on Windows et al is that PerlIO_isutf8 is not 
defined, not that it isn't declared.  Presumably, the compiler is never 
going to be able to work that out; the problem doesn't occur until you 
try to link.  Therefore, the question can't be answered by a 
pre-processor directive.

Back to this, then:

#if PERL_VERSION >= 8 && ((!defined(WIN32) && !defined(NETWARE) && 
!defined(OS2) && !defined(_AIX) && !defined(MACOS_TRADITIONAL) && 
!defined(VMS)) || PERL_SUBVERSION >= 1)
...
#endif

Steve


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About