develooper Front page | perl.perl5.porters | Postings from November 2014

portable way of stopping C compilation, XS_VERSION_BOOTCHECK, XS_VERSION

From:
bulk88
Date:
November 2, 2014 02:27
Subject:
portable way of stopping C compilation, XS_VERSION_BOOTCHECK, XS_VERSION
Message ID:
20141102022718.3000.qmail@lists-nntp.develooper.com
Currently blead has XS_APIVERSION_BOOTCHECK and XS_VERSION_BOOTCHECK.

http://perl5.git.perl.org/perl.git/blob/HEAD:/XSUB.h#l326

note the

------------------------------------------------------
#  define XS_VERSION_BOOTCHECK
------------------------------------------------------
line in that gitweb link.

I currently have some proposed code for blead to introduce a 
"XS_BOTHVERSION_BOOTCHECK" token to replace the following boilerplate

-------------------------------------------------------
#ifdef XS_APIVERSION_BOOTCHECK
     XS_APIVERSION_BOOTCHECK;
#endif
     XS_VERSION_BOOTCHECK;
-------------------------------------------------------

in most xs modules. The proposed code is

-------------------------------------------------------
#ifdef XS_VERSION

#  define XS_BOTHVERSION_BOOTCHECK				\
     Perl_xs_handshake(HS_KEY(FALSE, "v" PERL_API_VERSION_STRING, 
XS_VERSION)	\
     , HS_CXT, items, ax, "v" PERL_API_VERSION_STRING, XS_VERSION)

#else

/* should this be a #error? if you want both checked, you better supply 
XS_VERSION right? */
#  define XS_BOTHVERSION_BOOTCHECK XS_APIVERSION_BOOTCHECK

#endif
-------------------------------------------------------

and has the #ifdef XS_VERSION guard that the current code does around 
XS_VERSION_BOOTCHECK. My problem is, what to do about the #else branch.

The #else from XS_VERSION_BOOTCHECK is from
"Updated to match xsubpp-1.929." 1 Jan 1996 
http://perl5.git.perl.org/perl.git/commitdiff/720fb644424900350db135e470934a00919daa13
from 5.002/1996. Very old. The docs for VERSIONCHECK in perlxs.pod are 
in a mega commit from 3 Feb 1996 
http://perl5.git.perl.org/perl.git/commitdiff/c07a80fdfe3926b5eb0585b674aa5d1f57b32ade 
perl5.002beta3. ParseXS/xsubpp's VERSIONCHECK feature was added in 
http://perl5.git.perl.org/perl.git/8fc38fdaa1848793e9b9d4a3642e644f9d791ae0 
  "Updated from xsubpp-1.924 to 1.929." 2 Jan 1996.

Some modules do disable XS version checking see 
http://grep.cpan.me/?q=VERSIONCHECK%3A\s%2BDISABLE . IDK if they also 
never create the XS_VERSION CPP token.


XS_BOTHVERSION_BOOTCHECK in its name says "BOTH", so presumably you 
intended to define a XS_VERSION (XS_VERSION is passed on cmd line to CC 
by EUMM, it is reasonable to imagine XS_VERSION getting lost 
accidentally in makefile section overrides or cmd line or env var 
overrides to the make tool). If I put a #error there, all intentionally 
XS_VERSION-less XS modules will always break, if such modules exist exist.

So what should go into #else?

#  define XS_BOTHVERSION_BOOTCHECK XS_APIVERSION_BOOTCHECK /*which hides 
mistakes, i dont like this*/

#error /*which breaks all non-XS_VERSION defining modules */

#  define XS_BOTHVERSION_BOOTCHECK Perl_croak_nocontext("panic: in 
XS_BOTHVERSION_BOOTCHECK: XS_VERSION is not defined") /* I'd like it to 
break at C compile time, not runtime, it might never run due to low 
testing for example*/

#  define XS_BOTHVERSION_BOOTCHECK typedef char 
You_need_to_defined_XS_VERSION[-1]; /*static assert style*/

Are there any problems with static assert style? Perl does not use 
static asserts at all AFAIK, so this would the first -1 length char 
array in core I think.



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