bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Avoid having GNULIB_NAMESPACE::func always inject references


From: Bruno Haible
Subject: Re: [PATCH] Avoid having GNULIB_NAMESPACE::func always inject references to rpl_func
Date: Sun, 20 Nov 2016 13:26:32 +0100
User-agent: KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; )

Hi Pedro,

> Currently, with C++ namespace support enabled, by defining
> GNULIB_NAMESPACE, the replacement symbols put in the GNULIB_NAMESPACE
> namespace are function pointers that point to the rpl_func functions.
> This means that the linker must pull in the rpl_func functions, even
> when "GNULIB_NAMESPACE::func(....)" is not called anywhere in the
> program.
> 
> Fix that by making the GNULIB_NAMESPACE::func symbols be C++ (empty)
> objects with inline conversion operators instead of function pointers
> that point to the replacement.

A really nice improvement. It works even with -O0.

I added ChangeLog entries for your two patches from 2016-11-12
(that Paul committed).

The member function 'rpl ()' is not used, other than in the 'operator type'.
How about inlining and eliminating it?


2016-11-19  Bruno Haible  <address@hidden>

        snippet/c++defs: Simplify _GL_CXXALIAS_* macros.
        * build-aux/snippet/c++defs.h [__cplusplus && GNULIB_NAMESPACE]
        (_GL_CXXALIAS_RPL_1, _GL_CXXALIAS_RPL_CAST_1,
        _GL_CXXALIAS_SYS, _GL_CXXALIAS_SYS_CAST, _GL_CXXALIAS_SYS_CAST2):
        Inline and remove member function 'rpl ()' of the wrapper struct.

diff --git a/build-aux/snippet/c++defs.h b/build-aux/snippet/c++defs.h
index b19a0be..c71475d 100644
--- a/build-aux/snippet/c++defs.h
+++ b/build-aux/snippet/c++defs.h
@@ -133,8 +133,7 @@
       static const struct _gl_ ## func ## _wrapper            \
       {                                                       \
         typedef rettype (*type) parameters;                   \
-        inline type rpl () const { return ::rpl_func; }       \
-        inline operator type () const  { return rpl (); }     \
+        inline operator type () const { return ::rpl_func; }  \
       } func = {};                                            \
     }                                                         \
     _GL_EXTERN_C int _gl_cxxalias_dummy
@@ -155,9 +154,7 @@
       static const struct _gl_ ## func ## _wrapper                 \
       {                                                            \
         typedef rettype (*type) parameters;                        \
-        inline type rpl () const                                   \
-        { return reinterpret_cast<type>(::rpl_func); }             \
-        inline operator type () const { return rpl (); }           \
+        inline operator type () const { return 
reinterpret_cast<type>(::rpl_func); } \
       } func = {};                                                 \
     }                                                              \
     _GL_EXTERN_C int _gl_cxxalias_dummy
@@ -183,10 +180,9 @@
       static const struct _gl_ ## func ## _wrapper            \
       {                                                       \
         typedef rettype (*type) parameters;                   \
-        inline type rpl () const { return ::func; }           \
-        inline operator type () const { return rpl (); }      \
+        inline operator type () const { return ::func; }      \
       } func = {};                                            \
-    }                                              \
+    }                                                         \
     _GL_EXTERN_C int _gl_cxxalias_dummy
 #else
 # define _GL_CXXALIAS_SYS(func,rettype,parameters) \
@@ -205,9 +201,7 @@
       static const struct _gl_ ## func ## _wrapper      \
       {                                                 \
         typedef rettype (*type) parameters;             \
-        inline type rpl () const                        \
-        { return reinterpret_cast<type>(::func); }      \
-        inline operator type () const { return rpl (); }\
+        inline operator type () const { return reinterpret_cast<type>(::func); 
} \
       } func = {};                                      \
     }                                                   \
     _GL_EXTERN_C int _gl_cxxalias_dummy
@@ -234,11 +228,7 @@
       static const struct _gl_ ## func ## _wrapper                            \
       {                                                                       \
         typedef rettype (*type) parameters;                                   \
-                                                                              \
-        inline type rpl () const                                              \
-        { return reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); }\
-                                                                              \
-        inline operator type () const { return rpl (); }                      \
+        inline operator type () const { return 
reinterpret_cast<type>((rettype2 (*) parameters2)(::func)); } \
       } func = {};                                                            \
     }                                                                         \
     _GL_EXTERN_C int _gl_cxxalias_dummy




reply via email to

[Prev in Thread] Current Thread [Next in Thread]