Skip to content

Commit 4a1bbd3

Browse files
committed
More preparation for 7.0 in versioning
This modifies the macros introduced in 9b6e951 that allow one to determine how the version of the perl currently being compiled compares to an arbitrary one. The modification is based on changes in the plan, including renaming of variables. This also introduces the use of '*' for the subversion (or micro as it is now called) to make conversion from the soon-to-be deprecated PERL_VERSION macro more rote, with less thinking involved.
1 parent 9435e77 commit 4a1bbd3

File tree

1 file changed

+75
-15
lines changed

1 file changed

+75
-15
lines changed

handy.h

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,34 @@ Perl_xxx(aTHX_ ...) form for any API calls where it's used.
430430
Perl_get_cvn_flags(aTHX_ STR_WITH_LEN(str), (flags))
431431

432432
/* internal helpers */
433-
#define PERL_RVS_TO_DECIMAL_(r,v,s) (((r)*1000000)+((v)*1000)+(s))
433+
/* Transitional */
434+
#ifndef PERL_MAJOR_VERSION
435+
# define PERL_MAJOR_VERSION PERL_REVISION
436+
#else
437+
# undef PERL_REVISION /* We don't want code to be using these */
438+
#endif
439+
#ifndef PERL_MINOR_VERSION
440+
# define PERL_MINOR_VERSION PERL_VERSION
441+
#else
442+
# undef PERL_VERSION
443+
#endif
444+
#ifndef PERL_MICRO_VERSION
445+
# define PERL_MICRO_VERSION PERL_SUBVERSION
446+
#else
447+
# undef PERL_SUBVERSION
448+
#endif
449+
450+
#define PERL_JNP_TO_DECIMAL_(maJor,miNor,Patch) \
451+
/* '10*' leaves room for things like alpha, beta, releases */ \
452+
(10 * ((maJor) * 1000000) + ((miNor) * 1000) + (Patch))
434453
#define PERL_DECIMAL_VERSION_ \
435-
PERL_RVS_TO_DECIMAL_(PERL_REVISION, PERL_VERSION, PERL_SUBVERSION)
454+
PERL_JNP_TO_DECIMAL_(PERL_MAJOR_VERSION, PERL_MINOR_VERSION, \
455+
PERL_MICRO_VERSION)
436456

437457
/*
438-
=for apidoc AmR|bool|PERL_VERSION_EQ|const int r|const int v|const int s
458+
=for apidoc AmR|bool|PERL_VERSION_EQ|const U8 major|const U8 minor|const U8 patch
439459
440-
Returns whether or not the perl currently executing has the specified
460+
Returns whether or not the perl currently being compiled has the specified
441461
relationship to the perl given by the parameters. For example,
442462
443463
#if PERL_VERSION_GT(5,24,2)
@@ -452,21 +472,61 @@ The possible comparisons are C<PERL_VERSION_EQ>, C<PERL_VERSION_NE>,
452472
C<PERL_VERSION_GE>, C<PERL_VERSION_GT>, C<PERL_VERSION_LE>, and
453473
C<PERL_VERSION_LT>.
454474
455-
=for apidoc AmRh|bool|PERL_VERSION_NE|const int r|const int v|const int s
456-
=for apidoc AmRh|bool|PERL_VERSION_GE|const int r|const int v|const int s
457-
=for apidoc AmRh|bool|PERL_VERSION_GT|const int r|const int v|const int s
458-
=for apidoc AmRh|bool|PERL_VERSION_LE|const int r|const int v|const int s
459-
=for apidoc AmRh|bool|PERL_VERSION_LT|const int r|const int v|const int s
475+
You may use the special value '*' for the final number to mean ALL possible
476+
values for it. Thus,
477+
478+
#if PERL_VERSION_EQ(5,31,'*')
479+
480+
means all perls in the 5.31 series. And
481+
482+
#if PERL_VERSION_NE(5,24,'*')
483+
484+
means all perls EXCEPT 5.24 ones. And
485+
486+
#if PERL_VERSION_LE(5,9,'*')
487+
488+
is effectively
489+
490+
#if PERL_VERSION_LT(5,10,0)
491+
492+
This means you don't have to think so much when converting from the existing
493+
deprecated C<PERL_VERSION> to using this macro:
494+
495+
#if PERL_VERSION <= 9
496+
497+
becomes
498+
499+
#if PERL_VERSION_LE(5,9,'*')
500+
501+
=for apidoc AmRh|bool|PERL_VERSION_NE|const U8 major|const U8 minor|const U8 patch
502+
=for apidoc AmRh|bool|PERL_VERSION_GE|const U8 major|const U8 minor|const U8 patch
503+
=for apidoc AmRh|bool|PERL_VERSION_GT|const U8 major|const U8 minor|const U8 patch
504+
=for apidoc AmRh|bool|PERL_VERSION_LE|const U8 major|const U8 minor|const U8 patch
505+
=for apidoc AmRh|bool|PERL_VERSION_LT|const U8 major|const U8 minor|const U8 patch
460506
461507
=cut
462508
*/
463509

464-
# define PERL_VERSION_EQ(r,v,s) (PERL_DECIMAL_VERSION_ == PERL_RVS_TO_DECIMAL_(r,v,s))
465-
# define PERL_VERSION_NE(r,v,s) (! PERL_VERSION_EQ(r,v,s))
466-
# define PERL_VERSION_LT(r,v,s) (PERL_DECIMAL_VERSION_ < PERL_RVS_TO_DECIMAL_(r,v,s))
467-
# define PERL_VERSION_LE(r,v,s) (PERL_DECIMAL_VERSION_ <= PERL_RVS_TO_DECIMAL_(r,v,s))
468-
# define PERL_VERSION_GT(r,v,s) (! PERL_VERSION_LE(r,v,s))
469-
# define PERL_VERSION_GE(r,v,s) (! PERL_VERSION_LT(r,v,s))
510+
/* N.B. These don't work if the patch version is 42 or 92, as those are what
511+
* '*' is in ASCII and EBCDIC respectively */
512+
# define PERL_VERSION_EQ(j,n,p) \
513+
(((p) == '*') \
514+
? ( (j) == PERL_MAJOR_VERSION \
515+
&& (n) == PERL_MINOR_VERSION) \
516+
: (PERL_DECIMAL_VERSION_ == PERL_JNP_TO_DECIMAL_(j,n,p)))
517+
# define PERL_VERSION_NE(j,n,p) (! PERL_VERSION_EQ(j,n,p))
518+
519+
# define PERL_VERSION_LT(j,n,p) /* < '*' effectively means < 0 */ \
520+
(PERL_DECIMAL_VERSION_ < PERL_JNP_TO_DECIMAL_( (j), \
521+
(n), \
522+
(((p) == '*') ? 0 : p)))
523+
# define PERL_VERSION_GE(j,n,p) (! PERL_VERSION_LT(j,n,p))
524+
525+
# define PERL_VERSION_LE(j,n,p) /* <= '*' effectively means < n+1 */ \
526+
(PERL_DECIMAL_VERSION_ < PERL_JNP_TO_DECIMAL_( (j), \
527+
(((p) == '*') ? ((n)+1) : (n)), \
528+
(((p) == '*') ? 0 : p)))
529+
# define PERL_VERSION_GT(j,n,p) (! PERL_VERSION_LE(j,n,p))
470530

471531
/*
472532
=head1 Miscellaneous Functions

0 commit comments

Comments
 (0)