Skip to content

Commit 9b6e951

Browse files
committed
Add PERL_VERSION_GE macro, and kin
This moves things from vutil.h, and into handy.h; this is required for v7
1 parent 1da21e2 commit 9b6e951

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

handy.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ Perl_xxx(aTHX_ ...) form for any API calls where it's used.
384384
=cut
385385
*/
386386

387-
388387
#define STR_WITH_LEN(s) ("" s ""), (sizeof(s)-1)
389388

390389
/* STR_WITH_LEN() shortcuts */
@@ -421,6 +420,45 @@ Perl_xxx(aTHX_ ...) form for any API calls where it's used.
421420
#define get_cvs(str, flags) \
422421
Perl_get_cvn_flags(aTHX_ STR_WITH_LEN(str), (flags))
423422

423+
/* internal helpers */
424+
#define PERL_RVS_TO_DECIMAL_(r,v,s) (((r)*1000000)+((v)*1000)+(s))
425+
#define PERL_DECIMAL_VERSION_ \
426+
PERL_RVS_TO_DECIMAL_(PERL_REVISION, PERL_VERSION, PERL_SUBVERSION)
427+
428+
/*
429+
=for apidoc AmR|bool|PERL_VERSION_EQ|const int r|const int v|const int s
430+
431+
Returns whether or not the perl currently executing has the specified
432+
relationship to the perl given by the parameters. For example,
433+
434+
#if PERL_VERSION_GT(5,24,2)
435+
code that will only be compiled on perls after v5.24.2
436+
#else
437+
fallback code
438+
#endif
439+
440+
Note that this is usable in making compile-time decisions
441+
442+
The possible comparisons are C<PERL_VERSION_EQ>, C<PERL_VERSION_NE>,
443+
C<PERL_VERSION_GE>, C<PERL_VERSION_GT>, C<PERL_VERSION_LE>, and
444+
C<PERL_VERSION_LT>.
445+
446+
=for apidoc AmRh|bool|PERL_VERSION_NE|const int r|const int v|const int s
447+
=for apidoc AmRh|bool|PERL_VERSION_GE|const int r|const int v|const int s
448+
=for apidoc AmRh|bool|PERL_VERSION_GT|const int r|const int v|const int s
449+
=for apidoc AmRh|bool|PERL_VERSION_LE|const int r|const int v|const int s
450+
=for apidoc AmRh|bool|PERL_VERSION_LT|const int r|const int v|const int s
451+
452+
=cut
453+
*/
454+
455+
# define PERL_VERSION_EQ(r,v,s) (PERL_DECIMAL_VERSION_ == PERL_RVS_TO_DECIMAL_(r,v,s))
456+
# define PERL_VERSION_NE(r,v,s) (! PERL_VERSION_EQ(r,v,s))
457+
# define PERL_VERSION_LT(r,v,s) (PERL_DECIMAL_VERSION_ < PERL_RVS_TO_DECIMAL_(r,v,s))
458+
# define PERL_VERSION_LE(r,v,s) (PERL_DECIMAL_VERSION_ <= PERL_RVS_TO_DECIMAL_(r,v,s))
459+
# define PERL_VERSION_GT(r,v,s) (! PERL_VERSION_LE(r,v,s))
460+
# define PERL_VERSION_GE(r,v,s) (! PERL_VERSION_LT(r,v,s))
461+
424462
/*
425463
=head1 Miscellaneous Functions
426464

vutil.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ Perl_ck_warner(pTHX_ U32 err, const char* pat, ...)
7575
# endif
7676
#endif
7777

78-
#define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
79-
#define PERL_DECIMAL_VERSION \
80-
PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
81-
#define PERL_VERSION_LT(r,v,s) \
82-
(PERL_DECIMAL_VERSION < PERL_VERSION_DECIMAL(r,v,s))
83-
#define PERL_VERSION_GE(r,v,s) \
84-
(PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
85-
8678
#if PERL_VERSION_LT(5,15,4)
8779
# define ISA_VERSION_OBJ(v) (sv_isobject(v) && sv_derived_from(v,"version"))
8880
#else

0 commit comments

Comments
 (0)