develooper Front page | perl.perl5.porters | Postings from August 2010

Re: [PATCH] Configure probe for static inline (version 2)

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
August 2, 2010 06:13
Subject:
Re: [PATCH] Configure probe for static inline (version 2)
Message ID:
20100802131348.GS48531@plum.flirble.org
On Thu, Jul 22, 2010 at 12:05:11PM -0400, Andy Dougherty wrote:
> On Sat, 10 Jul 2010, Vincent Pit wrote:
> 
> > 
> > > Here is a proposed patch to enable Configure to probe for C99-style
> > > 'static inline'.  (That is, functions may be inlined, but will not be
> > > externally visible.)  The initial idea is that some common code in messy
> > > macros inside headers might be simplified using inline functions.  If the
> > > compiler does not support 'static inline', then a plain 'static' is used
> > > instead, along with the consequent implications of a function call.  In
> > > either case, you simply use  PERL_STATIC_INLINE.
> 
> Having received no reports of failures, I have applied this change to the 
> repository as commit 17a6c8e38505fd8d5700febfe392e470c9c5fff8 ,
> and also updated the metaconfig repository as commits
> commits 907a968f1883e76eea71816c9428d036dcfff971 and
> bed4b4c1ddba06b9f4653f7769acf6c91b9cba58 .
> 
> I have also updated the guesses in the canned configuration files
> for epoc, symbian, uconfig, Cross, and plan9.
> 
> Still needed are updates to VMS and Windows, and Netware.

Thanks for doing this.


I'm a bit slow on reporting that a week or two ago I tried the most simple
"simplify things by converting alternate macro definitions to one inline
function" that I could find:

$ git show  stash@{0}
commit 62a6bca43714332ca276963104a3f2e42b9e595a
Merge: ff906f8 7af5165
Author: Nicholas Clark <nick@ccl4.org>
Date:   Sat Jul 24 14:44:48 2010 +0200

    On blead: SvTRUEx inline hmm

diff --cc sv.h
index bc75d1e,bc75d1e..4e9428b
--- a/sv.h
+++ b/sv.h
@@@ -1653,7 -1653,7 +1653,6 @@@ Like sv_utf8_upgrade, but doesn't do ma
            :   SvNOK(sv)                                       \
                ? SvNVX(sv) != 0.0                              \
                : sv_2bool(sv) )
--#  define SvTRUEx(sv) ({SV *_sv = (sv); SvTRUE(_sv); })
  
  #else /* __GNUC__ */
  
@@@ -1685,9 -1685,9 +1684,10 @@@
            :   SvNOK(sv)                                       \
                ? SvNVX(sv) != 0.0                              \
                : sv_2bool(sv) )
--#  define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
  #endif /* __GNU__ */
  
++PERL_STATIC_INLINE bool SvTRUEx(SV *const sv) { return SvTRUE(sv); }
++
  #define SvIsCOW(sv)           ((SvFLAGS(sv) & (SVf_FAKE | SVf_READONLY)) == \
                                    (SVf_FAKE | SVf_READONLY))
  #define SvIsCOW_shared_hash(sv)       (SvIsCOW(sv) && SvLEN(sv) == 0)



and, well, it fails with a most beautiful explosion of cryptic compiler errors.
Because, it turns out, at this point, I'm attempting to define (and therefore
compile) SvTRUEx in terms of SvTRUE(), so *that* is textually expanded right
there and then, and expected to work. It looks like this:

#  define SvTRUE(sv) (						\
    !sv								\
    ? 0								\
    :    SvPOK(sv)						\
	?   ((PL_Xpv = (XPV*)SvANY(PL_Sv = (sv))) &&		\
	     (PL_Xpv->xpv_cur > 1 ||				\
	      (PL_Xpv->xpv_cur && *PL_Sv->sv_u.svu_pv != '0'))	\
	     ? 1						\
	     : 0)						\
	:							\
	    SvIOK(sv)						\
	    ? SvIVX(sv) != 0					\
	    :   SvNOK(sv)					\
		? SvNVX(sv) != 0.0				\
		: sv_2bool(sv) )

at this point in the compilation of sv.h, various of the functions and
variables that it calls are not *yet* defined. This hadn't mattered until
now.

I suspect that there's going to need to be some untangling of the order of
definition of

1: structure and types
2: variables and (global) functions that use those structures and types
3: inline functions that use both of the above

particularly if we want to keep logically related things close together in
their source files.

Nicholas Clark


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About