summaryrefslogtreecommitdiff
path: root/vutil.h
diff options
context:
space:
mode:
authorJohn Peacock <jpeacock@cpan.org>2014-01-12 11:19:53 -0500
committerFather Chrysostomos <sprout@cpan.org>2014-01-18 17:37:02 -0800
commit05402f6b212ae526674299c1c22151299db21ebb (patch)
treeeef8e3c64975aa948484806ee11ab88260705ca5 /vutil.h
parent5b20939a81d8c63c45bc3221699c4e9b7d369729 (diff)
downloadperl-05402f6b212ae526674299c1c22151299db21ebb.tar.gz
Lots of C optimizations for both speed/correctness
Clean up a lot of the less efficient uses of various Perl macros and functions, mostly from bulk88@hotmail.com. Also deal with the fact that older Perl's were not handling locale setting in a consistent manner. This means going back to the less efficient but always correct method of ALWAYS copying the old locale and switch to C and then restoring, for all Perl releases prior to 5.19.0. Discontinue support for Perl's prior to v5.6.2.
Diffstat (limited to 'vutil.h')
-rw-r--r--vutil.h64
1 files changed, 63 insertions, 1 deletions
diff --git a/vutil.h b/vutil.h
index f86631d654..aaf2284e89 100644
--- a/vutil.h
+++ b/vutil.h
@@ -83,7 +83,49 @@ Perl_ck_warner(pTHX_ U32 err, const char* pat, ...)
#define PERL_VERSION_GE(r,v,s) \
(PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
-#define ISA_CLASS_OBJ(v,c) (sv_isobject(v) && sv_derived_from(v,c))
+#if PERL_VERSION_LT(5,15,4)
+# define ISA_VERSION_OBJ(v) (sv_isobject(v) && sv_derived_from(v,"version"))
+#else
+# define ISA_VERSION_OBJ(v) (sv_isobject(v) && sv_derived_from_pvn(v,"version",7,0))
+#endif
+
+
+#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
+#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
+
+/* prototype to pass -Wmissing-prototypes */
+STATIC void
+S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params);
+
+STATIC void
+S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
+{
+ const GV *const gv = CvGV(cv);
+
+ PERL_ARGS_ASSERT_CROAK_XS_USAGE;
+
+ if (gv) {
+ const char *const gvname = GvNAME(gv);
+ const HV *const stash = GvSTASH(gv);
+ const char *const hvname = stash ? HvNAME(stash) : NULL;
+
+ if (hvname)
+ Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
+ else
+ Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
+ } else {
+ /* Pants. I don't think that it should be possible to get here. */
+ Perl_croak_nocontext("Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params);
+ }
+}
+
+#ifdef PERL_IMPLICIT_CONTEXT
+#define croak_xs_usage(a,b) S_croak_xs_usage(aTHX_ a,b)
+#else
+#define croak_xs_usage S_croak_xs_usage
+#endif
+
+#endif
#if PERL_VERSION_GE(5,9,0) && !defined(PERL_CORE)
@@ -109,8 +151,10 @@ const char * Perl_prescan_version2(pTHX_ const char *s, bool strict, const char*
# define VNORMAL(a) Perl_vnormal2(aTHX_ a)
# define VCMP(a,b) Perl_vcmp2(aTHX_ a,b)
# define PRESCAN_VERSION(a,b,c,d,e,f,g) Perl_prescan_version2(aTHX_ a,b,c,d,e,f,g)
+# undef is_LAX_VERSION
# define is_LAX_VERSION(a,b) \
(a != Perl_prescan_version2(aTHX_ a, FALSE, b, NULL, NULL, NULL, NULL))
+# undef is_STRICT_VERSION
# define is_STRICT_VERSION(a,b) \
(a != Perl_prescan_version2(aTHX_ a, TRUE, b, NULL, NULL, NULL, NULL))
@@ -177,3 +221,21 @@ const char * Perl_prescan_version(pTHX_ const char *s, bool strict, const char**
# define PERL_ARGS_ASSERT_CK_WARNER \
assert(pat)
#endif
+
+
+#if PERL_VERSION_LT(5,19,0)
+# undef STORE_NUMERIC_LOCAL_SET_STANDARD
+# undef RESTORE_NUMERIC_LOCAL
+# ifdef USE_LOCALE
+# define STORE_NUMERIC_LOCAL_SET_STANDARD()\
+ char *loc = savepv(setlocale(LC_NUMERIC, NULL)); \
+ SAVEFREEPV(loc); \
+ setlocale(LC_NUMERIC, "C");
+
+# define RESTORE_NUMERIC_LOCAL()\
+ setlocale(LC_NUMERIC, loc);
+# else
+# define STORE_NUMERIC_LOCAL_SET_STANDARD()
+# define RESTORE_NUMERIC_LOCAL()
+# endif
+#endif