This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
inline.h: eliminate conversion warnings
authorTony Cook <tony@develop-help.com>
Tue, 4 Apr 2023 23:14:01 +0000 (09:14 +1000)
committerTony Cook <tony@develop-help.com>
Tue, 4 Jul 2023 00:31:07 +0000 (10:31 +1000)
Setting si_cxsubix in the context helper functions from the
difference of two pointers on 64-bit builds produced warnings
on MSVC like:

inline.h(2815): warning C4244: '=': conversion from '__int64' to 'I32', possible loss of data

Similar warnings are produced on gcc with -Wconversion (and many more)

The machine that needs 2**32 context entries would also require
much more memory to store the contexts themselves and any SVs and
stack entries needed within each context, so I've cast the
values rather than making si_cxsubix a SSize_t.

Fixes parts of #20841, preventing this warning when the header is
used by embedders or extension builders.

inline.h

index 9093018..cc2fa09 100644 (file)
--- a/inline.h
+++ b/inline.h
@@ -2812,7 +2812,7 @@ Perl_cx_pushsub(pTHX_ PERL_CONTEXT *cx, CV *cv, OP *retop, bool hasargs)
 
     PERL_DTRACE_PROBE_ENTRY(cv);
     cx->blk_sub.old_cxsubix     = PL_curstackinfo->si_cxsubix;
-    PL_curstackinfo->si_cxsubix = cx - PL_curstackinfo->si_cxstack;
+    PL_curstackinfo->si_cxsubix = (I32)(cx - PL_curstackinfo->si_cxstack);
     cx->blk_sub.cv = cv;
     cx->blk_sub.olddepth = CvDEPTH(cv);
     cx->blk_sub.prevcomppad = PL_comppad;
@@ -2887,7 +2887,7 @@ Perl_cx_pushformat(pTHX_ PERL_CONTEXT *cx, CV *cv, OP *retop, GV *gv)
     PERL_ARGS_ASSERT_CX_PUSHFORMAT;
 
     cx->blk_format.old_cxsubix = PL_curstackinfo->si_cxsubix;
-    PL_curstackinfo->si_cxsubix= cx - PL_curstackinfo->si_cxstack;
+    PL_curstackinfo->si_cxsubix= (I32)(cx - PL_curstackinfo->si_cxstack);
     cx->blk_format.cv          = cv;
     cx->blk_format.retop       = retop;
     cx->blk_format.gv          = gv;
@@ -2948,7 +2948,7 @@ Perl_cx_pusheval(pTHX_ PERL_CONTEXT *cx, OP *retop, SV *namesv)
     Perl_push_evalortry_common(aTHX_ cx, retop, namesv);
 
     cx->blk_eval.old_cxsubix    = PL_curstackinfo->si_cxsubix;
-    PL_curstackinfo->si_cxsubix = cx - PL_curstackinfo->si_cxstack;
+    PL_curstackinfo->si_cxsubix = (I32)(cx - PL_curstackinfo->si_cxstack);
 }
 
 PERL_STATIC_INLINE void