]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - Magic.xs
Fix expected constness for utf8_length() arguments
[perl/modules/Variable-Magic.git] / Magic.xs
index 3a170c0332a32e77402fffcf5aa91c9816f9c4bd..f64d001f5efef803452f63eb2cc4ae0280885708 100644 (file)
--- a/Magic.xs
+++ b/Magic.xs
@@ -104,10 +104,6 @@ STATIC SV *vmg_clone(pTHX_ SV *sv, tTHX owner) {
 # define mPUSHu(U) PUSHs(sv_2mortal(newSVuv(U)))
 #endif
 
-#ifndef SvPV_const
-# define SvPV_const SvPV
-#endif
-
 #ifndef PERL_MAGIC_ext
 # define PERL_MAGIC_ext '~'
 #endif
@@ -907,23 +903,15 @@ STATIC SV *vmg_op_info(pTHX_ unsigned int opinfo) {
 
 /* ... svt callbacks ....................................................... */
 
-#define VMG_CB_CALL_SET_RET(D) \
- {            \
-  SV *svr;    \
-  SPAGAIN;    \
-  svr = POPs; \
-  ret = SvOK(svr) ? SvIV(svr) : (D); \
-  PUTBACK;    \
- }
-
 #define VMG_CB_CALL_ARGS_MASK  15
 #define VMG_CB_CALL_ARGS_SHIFT 4
 #define VMG_CB_CALL_OPINFO     (VMG_OP_INFO_NAME|VMG_OP_INFO_OBJECT)
 
 STATIC int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) {
  va_list ap;
- int ret;
+ int ret = 0;
  unsigned int i, args, opinfo;
+ SV *svr;
 
  dSP;
 
@@ -949,7 +937,11 @@ STATIC int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) {
 
  call_sv(cb, G_SCALAR);
 
- VMG_CB_CALL_SET_RET(0);
+ SPAGAIN;
+ svr = POPs;
+ if (SvOK(svr))
+  ret = (int) SvIV(svr);
+ PUTBACK;
 
  FREETMPS;
  LEAVE;
@@ -978,6 +970,7 @@ STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) {
  const MGWIZ *w = vmg_wizard_mgwiz(mg->mg_ptr);
  unsigned int opinfo = w->opinfo;
  U32 len, ret;
+ SV *svr;
  svtype t = SvTYPE(sv);
 
  dSP;
@@ -991,7 +984,11 @@ STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) {
  PUSHs(mg->mg_obj ? mg->mg_obj : &PL_sv_undef);
  if (t < SVt_PVAV) {
   STRLEN l;
-  const U8 *s = (const U8 *) SvPV_const(sv, l);
+#if VMG_HAS_PERL(5, 9, 2)
+  const U8 *s = SvPV_const(sv, l);
+#else
+  U8 *s = SvPV(sv, l);
+#endif
   if (DO_UTF8(sv))
    len = utf8_length(s, s + l);
   else
@@ -1010,12 +1007,17 @@ STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) {
 
  call_sv(w->cb_len, G_SCALAR);
 
- VMG_CB_CALL_SET_RET(len);
+ SPAGAIN;
+ svr = POPs;
+ ret = SvOK(svr) ? (U32) SvUV(svr) : len;
+ if (t == SVt_PVAV)
+   --ret;
+ PUTBACK;
 
  FREETMPS;
  LEAVE;
 
- return t == SVt_PVAV ? ret - 1 : ret;
+ return ret;
 }
 
 STATIC int vmg_svt_clear(pTHX_ SV *sv, MAGIC *mg) {
@@ -1031,6 +1033,7 @@ STATIC int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) {
 #endif
  I32 had_err, has_err, flags = G_SCALAR | G_EVAL;
  int ret = 0;
+ SV *svr;
 
  dSP;
 
@@ -1087,7 +1090,11 @@ STATIC int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) {
  if (IN_PERL_COMPILETIME && !had_err && has_err)
   ++PL_error_count;
 
- VMG_CB_CALL_SET_RET(0);
+ SPAGAIN;
+ svr = POPs;
+ if (SvOK(svr))
+  ret = (int) SvIV(svr);
+ PUTBACK;
 
  FREETMPS;
  LEAVE;