5 Devel::PPPort - Perl/Pollution/Portability
9 Devel::PPPort::WriteFile() ; # defaults to ./ppport.h
10 Devel::PPPort::WriteFile('someheader.h') ;
14 Perl has changed over time, gaining new features, new functions,
15 increasing its flexibility, and reducing the impact on the C namespace
16 environment (reduced pollution). The header file, typicaly C<ppport.h>,
17 written by this module attempts to bring some of the newer Perl
18 features to older versions of Perl, so that you can worry less about
19 keeping track of old releases, but users can still reap the benefit.
21 Why you should use C<ppport.h> in modern code: so that your code will work
22 with the widest range of Perl interpreters possible, without significant
25 Why you should attempt older code to fully use C<ppport.h>: because
26 the reduced pollution of newer Perl versions is an important thing, so
27 important that the old polluting ways of original Perl modules will not be
28 supported very far into the future, and your module will almost certainly
29 break! By adapting to it now, you'll gained compatibility and a sense of
30 having done the electronic ecology some good.
32 How to use ppport.h: Don't direct the user to download C<Devel::PPPort>,
33 and don't make C<ppport.h> optional. Rather, just take the most recent
34 copy of C<ppport.h> that you can find (probably in C<Devel::PPPort>
35 on CPAN), copy it into your project, adjust your project to use it,
36 and distribute the header along with your module.
38 C<Devel::PPPort> contains a single function, called C<WriteFile>. It's
39 purpose is to write a 'C' header file that is used when writing XS
40 modules. The file contains a series of macros that allow XS modules to
41 be built using older versions of Perl.
43 This module is used by h2xs to write the file F<ppport.h>.
47 C<WriteFile> takes a zero or one parameters. When called with one
48 parameter it expects to be passed a filename. When called with no
49 parameters, it defults to the filename C<./pport.h>.
51 The function returns TRUE if the file was written successfully. Otherwise
56 The file written by this module, typically C<ppport.h>, provides access
57 to the following Perl API if not already available (and in some cases [*]
58 even if available, access to a fixed interface):
89 gv_stashpvn(str,len,flags)
94 newCONSTSUB(stash,name,sv)
144 Version 1.x of Devel::PPPort was written by Kenneth Albanowski.
146 Version 2.x was ported to the Perl core by Paul Marquess.
155 package Devel::PPPort;
161 use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK $data );
165 @ISA = qw(Exporter DynaLoader);
167 # Other items we are prepared to export if requested
170 bootstrap Devel::PPPort;
172 package Devel::PPPort;
178 my $pkg = __PACKAGE__;
179 $data =~ s/__VERSION__/$VERSION/g;
180 $data =~ s/__DATE__/$now/g;
181 $data =~ s/__PKG__/$pkg/g;
186 my $file = shift || 'ppport.h' ;
188 open F, ">$file" || return undef ;
199 /* ppport.h -- Perl/Pollution/Portability Version __VERSION__
201 * Automatically Created by __PKG__ on __DATE__
203 * Do NOT edit this file directly! -- Edit PPPort.pm instead.
205 * Version 2.x, Copyright (C) 2001, Paul Marquess.
206 * Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
207 * This code may be used and distributed under the same license as any
210 * This version of ppport.h is designed to support operation with Perl
211 * installations back to 5.004, and has been tested up to 5.8.1.
213 * If this version of ppport.h is failing during the compilation of this
214 * module, please check if a newer version of Devel::PPPort is available
215 * on CPAN before sending a bug report.
217 * If you are using the latest version of Devel::PPPort and it is failing
218 * during compilation of this module, please send a report to perlbug@perl.com
220 * Include all following information:
222 * 1. The complete output from running "perl -V"
226 * 3. The name & version of the module you were trying to build.
228 * 4. A full log of the build that failed.
230 * 5. Any other information that you think could be relevant.
233 * For the latest version of this code, please retreive the Devel::PPPort
239 * In order for a Perl extension module to be as portable as possible
240 * across differing versions of Perl itself, certain steps need to be taken.
241 * Including this header is the first major one, then using dTHR is all the
242 * appropriate places and using a PL_ prefix to refer to global Perl
243 * variables is the second.
248 /* If you use one of a few functions that were not present in earlier
249 * versions of Perl, please add a define before the inclusion of ppport.h
250 * for a static include, or use the GLOBAL request in a single module to
251 * produce a global definition that can be referenced from the other
254 * Function: Static define: Extern define:
255 * newCONSTSUB() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL
260 /* To verify whether ppport.h is needed for your module, and whether any
261 * special defines should be used, ppport.h can be run through Perl to check
262 * your source code. Simply say:
264 * perl -x ppport.h *.c *.h *.xs foo/bar*.c [etc]
266 * The result will be a list of patches suggesting changes that should at
267 * least be acceptable, if not necessarily the most efficient solution, or a
268 * fix for all possible problems. It won't catch where dTHR is needed, and
269 * doesn't attempt to account for global macro or function definitions,
270 * nested includes, typemaps, etc.
272 * In order to test for the need of dTHR, please try your module under a
273 * recent version of Perl that has threading compiled-in.
280 @ARGV = ("*.xs") if !@ARGV;
281 %badmacros = %funcs = %macros = (); $replace = 0;
283 $funcs{$1} = 1 if /Provide:\s+(\S+)/;
284 $macros{$1} = 1 if /^#\s*define\s+([a-zA-Z0-9_]+)/;
285 $replace = $1 if /Replace:\s+(\d+)/;
286 $badmacros{$2}=$1 if $replace and /^#\s*define\s+([a-zA-Z0-9_]+).*?\s+([a-zA-Z0-9_]+)/;
287 $badmacros{$1}=$2 if /Replace (\S+) with (\S+)/;
289 foreach $filename (map(glob($_),@ARGV)) {
290 unless (open(IN, "<$filename")) {
291 warn "Unable to read from $file: $!\n";
294 print "Scanning $filename...\n";
295 $c = ""; while (<IN>) { $c .= $_; } close(IN);
296 $need_include = 0; %add_func = (); $changes = 0;
297 $has_include = ($c =~ /#.*include.*ppport/m);
299 foreach $func (keys %funcs) {
300 if ($c =~ /#.*define.*\bNEED_$func(_GLOBAL)?\b/m) {
301 if ($c !~ /\b$func\b/m) {
302 print "If $func isn't needed, you don't need to request it.\n" if
303 $changes += ($c =~ s/^.*#.*define.*\bNEED_$func\b.*\n//m);
305 print "Uses $func\n";
309 if ($c =~ /\b$func\b/m) {
310 $add_func{$func} =1 ;
311 print "Uses $func\n";
317 if (not $need_include) {
318 foreach $macro (keys %macros) {
319 if ($c =~ /\b$macro\b/m) {
320 print "Uses $macro\n";
326 foreach $badmacro (keys %badmacros) {
327 if ($c =~ /\b$badmacro\b/m) {
328 $changes += ($c =~ s/\b$badmacro\b/$badmacros{$badmacro}/gm);
329 print "Uses $badmacros{$badmacro} (instead of $badmacro)\n";
334 if (scalar(keys %add_func) or $need_include != $has_include) {
336 $inc = join('',map("#define NEED_$_\n", sort keys %add_func)).
337 "#include \"ppport.h\"\n";
338 $c = "$inc$c" unless $c =~ s/#.*include.*XSUB.*\n/$&$inc/m;
339 } elsif (keys %add_func) {
340 $inc = join('',map("#define NEED_$_\n", sort keys %add_func));
341 $c = "$inc$c" unless $c =~ s/^.*#.*include.*ppport.*$/$inc$&/m;
343 if (!$need_include) {
344 print "Doesn't seem to need ppport.h.\n";
345 $c =~ s/^.*#.*include.*ppport.*\n//m;
351 open(OUT,">/tmp/ppport.h.$$");
354 open(DIFF, "diff -u $filename /tmp/ppport.h.$$|");
355 while (<DIFF>) { s!/tmp/ppport\.h\.$$!$filename.patched!; print STDOUT; }
357 unlink("/tmp/ppport.h.$$");
365 #ifndef _P_P_PORTABILITY_H_
366 #define _P_P_PORTABILITY_H_
368 #ifndef PERL_REVISION
369 # ifndef __PATCHLEVEL_H_INCLUDED__
370 # include <patchlevel.h>
372 # if !(defined(PERL_VERSION) || (SUBVERSION > 0 && defined(PATCHLEVEL)))
373 # include <could_not_find_Perl_patchlevel.h>
375 # ifndef PERL_REVISION
376 # define PERL_REVISION (5)
378 # define PERL_VERSION PATCHLEVEL
379 # define PERL_SUBVERSION SUBVERSION
380 /* Replace PERL_PATCHLEVEL with PERL_VERSION */
385 #define PERL_BCDVERSION ((PERL_REVISION * 0x1000000L) + (PERL_VERSION * 0x1000L) + PERL_SUBVERSION)
387 /* It is very unlikely that anyone will try to use this with Perl 6
388 (or greater), but who knows.
390 #if PERL_REVISION != 5
391 # error ppport.h only works with Perl version 5
392 #endif /* PERL_REVISION != 5 */
395 # define ERRSV perl_get_sv("@",FALSE)
398 #if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5))
401 # define PL_compiling compiling
402 # define PL_copline copline
403 # define PL_curcop curcop
404 # define PL_curstash curstash
405 # define PL_defgv defgv
406 # define PL_dirty dirty
407 # define PL_dowarn dowarn
408 # define PL_hints hints
410 # define PL_perldb perldb
411 # define PL_rsfp_filters rsfp_filters
412 # define PL_rsfpv rsfp
413 # define PL_stdingv stdingv
414 # define PL_sv_no sv_no
415 # define PL_sv_undef sv_undef
416 # define PL_sv_yes sv_yes
421 # if defined(__GNUC__) && defined(__cplusplus)
422 # define PERL_UNUSED_DECL
424 # define PERL_UNUSED_DECL __attribute__((unused))
427 # define PERL_UNUSED_DECL
431 # define NOOP (void)0
432 # define dNOOP extern int Perl___notused PERL_UNUSED_DECL
441 # define dTHXa(x) dNOOP
442 # define dTHXoa(x) dNOOP
452 /* IV could also be a quad (say, a long long), but Perls
453 * capable of those should have IVSIZE already. */
454 #if !defined(IVSIZE) && defined(LONGSIZE)
455 # define IVSIZE LONGSIZE
458 # define IVSIZE 4 /* A bold guess, but the best we can make. */
462 # define UVSIZE IVSIZE
466 # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE)
467 # define NVTYPE long double
469 # define NVTYPE double
476 #if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
478 # define INT2PTR(any,d) (any)(d)
480 # if PTRSIZE == LONGSIZE
481 # define PTRV unsigned long
483 # define PTRV unsigned
485 # define INT2PTR(any,d) (any)(PTRV)(d)
487 #define NUM2PTR(any,d) (any)(PTRV)(d)
488 #define PTR2IV(p) INT2PTR(IV,p)
489 #define PTR2UV(p) INT2PTR(UV,p)
490 #define PTR2NV(p) NUM2PTR(NV,p)
491 #if PTRSIZE == LONGSIZE
492 # define PTR2ul(p) (unsigned long)(p)
494 # define PTR2ul(p) INT2PTR(unsigned long,p)
497 #endif /* !INT2PTR */
500 # define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
504 # define gv_stashpvn(str,len,flags) gv_stashpv(str,flags)
508 # define newSVpvn(data,len) ((len) ? newSVpv ((data), (len)) : newSVpv ("", 0))
513 # define newRV_inc(sv) newRV(sv)
517 /* DEFSV appears first in 5.004_56 */
519 # define DEFSV GvSV(PL_defgv)
523 # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
528 # define newRV_noinc(sv) \
530 SV *nsv = (SV*)newRV(sv); \
535 # if defined(USE_THREADS)
536 static SV * newRV_noinc (SV * sv)
538 SV *nsv = (SV*)newRV(sv);
543 # define newRV_noinc(sv) \
544 (PL_Sv=(SV*)newRV(sv), SvREFCNT_dec(sv), (SV*)PL_Sv)
549 /* Provide: newCONSTSUB */
551 /* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */
552 #if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION < 63))
554 #if defined(NEED_newCONSTSUB)
557 extern void newCONSTSUB(HV * stash, char * name, SV *sv);
560 #if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL)
562 newCONSTSUB(stash,name,sv)
567 U32 oldhints = PL_hints;
568 HV *old_cop_stash = PL_curcop->cop_stash;
569 HV *old_curstash = PL_curstash;
570 line_t oldline = PL_curcop->cop_line;
571 PL_curcop->cop_line = PL_copline;
573 PL_hints &= ~HINT_BLOCK_SCOPE;
575 PL_curstash = PL_curcop->cop_stash = stash;
579 #if (PERL_VERSION < 3) || ((PERL_VERSION == 3) && (PERL_SUBVERSION < 22))
580 /* before 5.003_22 */
583 # if (PERL_VERSION == 3) && (PERL_SUBVERSION == 22)
587 /* 5.003_23 onwards */
588 start_subparse(FALSE, 0),
592 newSVOP(OP_CONST, 0, newSVpv(name,0)),
593 newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */
594 newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
598 PL_curcop->cop_stash = old_cop_stash;
599 PL_curstash = old_curstash;
600 PL_curcop->cop_line = oldline;
604 #endif /* newCONSTSUB */
609 * Boilerplate macros for initializing and accessing interpreter-local
610 * data from C. All statics in extensions should be reworked to use
611 * this, if you want to make the extension thread-safe. See ext/re/re.xs
612 * for an example of the use of these macros.
614 * Code that uses these macros is responsible for the following:
615 * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts"
616 * 2. Declare a typedef named my_cxt_t that is a structure that contains
617 * all the data that needs to be interpreter-local.
618 * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
619 * 4. Use the MY_CXT_INIT macro such that it is called exactly once
620 * (typically put in the BOOT: section).
621 * 5. Use the members of the my_cxt_t structure everywhere as
623 * 6. Use the dMY_CXT macro (a declaration) in all the functions that
627 #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \
628 defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT)
630 /* This must appear in all extensions that define a my_cxt_t structure,
631 * right after the definition (i.e. at file scope). The non-threads
632 * case below uses it to declare the data as static. */
635 #if (PERL_VERSION < 4 || (PERL_VERSION == 4 && PERL_SUBVERSION < 68 ))
636 /* Fetches the SV that keeps the per-interpreter data. */
638 SV *my_cxt_sv = perl_get_sv(MY_CXT_KEY, FALSE)
639 #else /* >= perl5.004_68 */
641 SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \
642 sizeof(MY_CXT_KEY)-1, TRUE)
643 #endif /* < perl5.004_68 */
645 /* This declaration should be used within all functions that use the
646 * interpreter-local data. */
649 my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv))
651 /* Creates and zeroes the per-interpreter data.
652 * (We allocate my_cxtp in a Perl SV so that it will be released when
653 * the interpreter goes away.) */
654 #define MY_CXT_INIT \
656 /* newSV() allocates one more than needed */ \
657 my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
658 Zero(my_cxtp, 1, my_cxt_t); \
659 sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
661 /* This macro must be used to access members of the my_cxt_t structure.
662 * e.g. MYCXT.some_data */
663 #define MY_CXT (*my_cxtp)
665 /* Judicious use of these macros can reduce the number of times dMY_CXT
666 * is used. Use is similar to pTHX, aTHX etc. */
667 #define pMY_CXT my_cxt_t *my_cxtp
668 #define pMY_CXT_ pMY_CXT,
669 #define _pMY_CXT ,pMY_CXT
670 #define aMY_CXT my_cxtp
671 #define aMY_CXT_ aMY_CXT,
672 #define _aMY_CXT ,aMY_CXT
674 #else /* single interpreter */
676 #define START_MY_CXT static my_cxt_t my_cxt;
677 #define dMY_CXT_SV dNOOP
678 #define dMY_CXT dNOOP
679 #define MY_CXT_INIT NOOP
680 #define MY_CXT my_cxt
691 #endif /* START_MY_CXT */
694 # if IVSIZE == LONGSIZE
701 # if IVSIZE == INTSIZE
712 # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && \
713 defined(PERL_PRIfldbl) /* Not very likely, but let's try anyway. */
714 # define NVef PERL_PRIeldbl
715 # define NVff PERL_PRIfldbl
716 # define NVgf PERL_PRIgldbl
724 #ifndef AvFILLp /* Older perls (<=5.003) lack AvFILLp */
725 # define AvFILLp AvFILL
729 # if PERL_REVISION == 5 && PERL_VERSION < 7
730 /* SvPVbyte does not work in perl-5.6.1, borrowed version for 5.7.3 */
732 # define SvPVbyte(sv, lp) \
733 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
734 ? ((lp = SvCUR(sv)), SvPVX(sv)) : my_sv_2pvbyte(aTHX_ sv, &lp))
736 my_sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
738 sv_utf8_downgrade(sv,0);
743 # define SvPVbyte SvPV
747 # define SvPV_nolen(sv) \
748 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
749 ? SvPVX(sv) : sv_2pv_nolen(sv))
751 sv_2pv_nolen(pTHX_ register SV *sv)
754 return sv_2pv(sv, &n_a);
759 # define get_cv(name,create) perl_get_cv(name,create)
763 # define get_sv(name,create) perl_get_sv(name,create)
767 # define get_av(name,create) perl_get_av(name,create)
771 # define get_hv(name,create) perl_get_hv(name,create)
775 # define call_argv perl_call_argv
779 # define call_method perl_call_method
783 # define call_pv perl_call_pv
787 # define call_sv perl_call_sv
790 #ifndef PERL_SCAN_GREATER_THAN_UV_MAX
791 # define PERL_SCAN_GREATER_THAN_UV_MAX 0x02
794 #ifndef PERL_SCAN_SILENT_ILLDIGIT
795 # define PERL_SCAN_SILENT_ILLDIGIT 0x04
798 #ifndef PERL_SCAN_ALLOW_UNDERSCORES
799 # define PERL_SCAN_ALLOW_UNDERSCORES 0x01
802 #ifndef PERL_SCAN_DISALLOW_PREFIX
803 # define PERL_SCAN_DISALLOW_PREFIX 0x02
806 #if (PERL_VERSION >= 6)
809 #define I32_CAST (I32*)
813 static UV _grok_hex (char *string, STRLEN *len, I32 *flags, NV *result) {
814 NV r = scan_hex(string, *len, I32_CAST len);
816 *flags |= PERL_SCAN_GREATER_THAN_UV_MAX;
817 if (result) *result = r;
823 # define grok_hex(string, len, flags, result) \
824 _grok_hex((string), (len), (flags), (result))
828 static UV _grok_oct (char *string, STRLEN *len, I32 *flags, NV *result) {
829 NV r = scan_oct(string, *len, I32_CAST len);
831 *flags |= PERL_SCAN_GREATER_THAN_UV_MAX;
832 if (result) *result = r;
838 # define grok_oct(string, len, flags, result) \
839 _grok_oct((string), (len), (flags), (result))
843 static UV _grok_bin (char *string, STRLEN *len, I32 *flags, NV *result) {
844 NV r = scan_bin(string, *len, I32_CAST len);
846 *flags |= PERL_SCAN_GREATER_THAN_UV_MAX;
847 if (result) *result = r;
853 # define grok_bin(string, len, flags, result) \
854 _grok_bin((string), (len), (flags), (result))
859 (PL_curcop == &PL_compiling ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
862 #ifndef IN_LOCALE_RUNTIME
863 # define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE)
866 #ifndef IN_LOCALE_COMPILETIME
867 # define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE)
871 #ifndef IS_NUMBER_IN_UV
872 # define IS_NUMBER_IN_UV 0x01
873 # define IS_NUMBER_GREATER_THAN_UV_MAX 0x02
874 # define IS_NUMBER_NOT_INT 0x04
875 # define IS_NUMBER_NEG 0x08
876 # define IS_NUMBER_INFINITY 0x10
877 # define IS_NUMBER_NAN 0x20
880 #ifndef grok_numeric_radix
881 # define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send)
883 #define grok_numeric_radix Perl_grok_numeric_radix
886 Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send)
888 #ifdef USE_LOCALE_NUMERIC
889 #if (PERL_VERSION >= 6)
890 if (PL_numeric_radix_sv && IN_LOCALE) {
892 char* radix = SvPV(PL_numeric_radix_sv, len);
893 if (*sp + len <= send && memEQ(*sp, radix, len)) {
899 /* pre5.6.0 perls don't have PL_numeric_radix_sv so the radix
900 * must manually be requested from locale.h */
902 struct lconv *lc = localeconv();
903 char *radix = lc->decimal_point;
904 if (radix && IN_LOCALE) {
906 if (*sp + len <= send && memEQ(*sp, radix, len)) {
911 #endif /* PERL_VERSION */
912 #endif /* USE_LOCALE_NUMERIC */
913 /* always try "." if numeric radix didn't match because
914 * we may have data from different locales mixed */
915 if (*sp < send && **sp == '.') {
921 #endif /* grok_numeric_radix */
925 #define grok_number Perl_grok_number
928 Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep)
931 const char *send = pv + len;
932 const UV max_div_10 = UV_MAX / 10;
933 const char max_mod_10 = UV_MAX % 10;
938 while (s < send && isSPACE(*s))
942 } else if (*s == '-') {
944 numtype = IS_NUMBER_NEG;
952 /* next must be digit or the radix separator or beginning of infinity */
954 /* UVs are at least 32 bits, so the first 9 decimal digits cannot
957 /* This construction seems to be more optimiser friendly.
958 (without it gcc does the isDIGIT test and the *s - '0' separately)
959 With it gcc on arm is managing 6 instructions (6 cycles) per digit.
960 In theory the optimiser could deduce how far to unroll the loop
961 before checking for overflow. */
963 int digit = *s - '0';
964 if (digit >= 0 && digit <= 9) {
965 value = value * 10 + digit;
968 if (digit >= 0 && digit <= 9) {
969 value = value * 10 + digit;
972 if (digit >= 0 && digit <= 9) {
973 value = value * 10 + digit;
976 if (digit >= 0 && digit <= 9) {
977 value = value * 10 + digit;
980 if (digit >= 0 && digit <= 9) {
981 value = value * 10 + digit;
984 if (digit >= 0 && digit <= 9) {
985 value = value * 10 + digit;
988 if (digit >= 0 && digit <= 9) {
989 value = value * 10 + digit;
992 if (digit >= 0 && digit <= 9) {
993 value = value * 10 + digit;
995 /* Now got 9 digits, so need to check
996 each time for overflow. */
998 while (digit >= 0 && digit <= 9
999 && (value < max_div_10
1000 || (value == max_div_10
1001 && digit <= max_mod_10))) {
1002 value = value * 10 + digit;
1008 if (digit >= 0 && digit <= 9
1010 /* value overflowed.
1011 skip the remaining digits, don't
1012 worry about setting *valuep. */
1015 } while (s < send && isDIGIT(*s));
1017 IS_NUMBER_GREATER_THAN_UV_MAX;
1037 numtype |= IS_NUMBER_IN_UV;
1042 if (GROK_NUMERIC_RADIX(&s, send)) {
1043 numtype |= IS_NUMBER_NOT_INT;
1044 while (s < send && isDIGIT(*s)) /* optional digits after the radix */
1048 else if (GROK_NUMERIC_RADIX(&s, send)) {
1049 numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */
1050 /* no digits before the radix means we need digits after it */
1051 if (s < send && isDIGIT(*s)) {
1054 } while (s < send && isDIGIT(*s));
1056 /* integer approximation is valid - it's 0. */
1062 } else if (*s == 'I' || *s == 'i') {
1063 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
1064 s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
1065 s++; if (s < send && (*s == 'I' || *s == 'i')) {
1066 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
1067 s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
1068 s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
1069 s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
1073 } else if (*s == 'N' || *s == 'n') {
1074 /* XXX TODO: There are signaling NaNs and quiet NaNs. */
1075 s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
1076 s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
1083 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
1084 numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;
1085 } else if (sawnan) {
1086 numtype &= IS_NUMBER_NEG; /* Keep track of sign */
1087 numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT;
1088 } else if (s < send) {
1089 /* we can have an optional exponent part */
1090 if (*s == 'e' || *s == 'E') {
1091 /* The only flag we keep is sign. Blow away any "it's UV" */
1092 numtype &= IS_NUMBER_NEG;
1093 numtype |= IS_NUMBER_NOT_INT;
1095 if (s < send && (*s == '-' || *s == '+'))
1097 if (s < send && isDIGIT(*s)) {
1100 } while (s < send && isDIGIT(*s));
1106 while (s < send && isSPACE(*s))
1110 if (len == 10 && memEQ(pv, "0 but true", 10)) {
1113 return IS_NUMBER_IN_UV;
1117 #endif /* grok_number */
1118 #endif /* _P_P_PORTABILITY_H_ */
1120 /* End of File ppport.h */