> When compiling parts of gnulib into a shared library, it is useful
> to add a namespace-like prefix to the symbols that come from gnulib,
> in order to avoid conflicts with other shared libraries.
> 
> Gettext's libgettextpo does so, through macro definitions in config.h,
> such as
>   #define fcntl libgettextpo_fcntl
>   #define rpl_open libgettextpo_rpl_open
> etc.
> 
> This works fine with most gnulib modules.

But a couple of modules fail to support this so far. The attached patches
fixes this.


2018-10-05  Bruno Haible  <br...@clisp.org>

        strpbrk: Make it possible to namespace the defined symbol.
        * lib/strpbrk.c (strpbrk): Don't undefine outside of glibc.

2018-10-05  Bruno Haible  <br...@clisp.org>

        strcspn: Make it possible to namespace the defined symbol.
        * lib/strcspn.c (strcspn): Don't undefine outside of glibc.

2018-10-05  Bruno Haible  <br...@clisp.org>

        raise: Make it possible to namespace the defined symbol.
        * lib/raise.c (raise): Undefine only after the replacement function has
        been defined.
        (raise): Renamed from rpl_raise.
        (raise_nothrow): Move to the end of the compilation unit.

2018-10-05  Bruno Haible  <br...@clisp.org>

        memcmp: Make it possible to namespace the defined symbol.
        * lib/memcmp.c (memcmp): Don't undefine outside of glibc.

2018-10-05  Bruno Haible  <br...@clisp.org>

        explicit_bzero: Make it possible to namespace the defined symbol.
        * lib/explicit_bzero.c (explicit_bzero): Don't undefine outside of
        glibc.

>From a67bce28a13b2ceb8614bf374941580c8047a209 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 5 Oct 2018 21:49:39 +0200
Subject: [PATCH 1/5] explicit_bzero: Make it possible to namespace the defined
 symbol.

* lib/explicit_bzero.c (explicit_bzero): Don't undefine outside of
glibc.
---
 ChangeLog            | 6 ++++++
 lib/explicit_bzero.c | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index fd631de..4d2542b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2018-10-05  Bruno Haible  <br...@clisp.org>
 
+	explicit_bzero: Make it possible to namespace the defined symbol.
+	* lib/explicit_bzero.c (explicit_bzero): Don't undefine outside of
+	glibc.
+
+2018-10-05  Bruno Haible  <br...@clisp.org>
+
 	mkdir-p: Depend on 'mkdir'.
 	* modules/mkdir-p (Depends-on): Add 'mkdir'.
 
diff --git a/lib/explicit_bzero.c b/lib/explicit_bzero.c
index 0331764..124b3cc 100644
--- a/lib/explicit_bzero.c
+++ b/lib/explicit_bzero.c
@@ -27,9 +27,11 @@
 
 #include <string.h>
 
+#if _LIBC
 /* glibc-internal users use __explicit_bzero_chk, and explicit_bzero
    redirects to that.  */
-#undef explicit_bzero
+# undef explicit_bzero
+#endif
 
 /* Set LEN bytes of S to 0.  The compiler will not delete a call to
    this function, even if S is dead after the call.  */
-- 
2.7.4

>From a738b735c245067d6696244dc9306aa82295de21 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 5 Oct 2018 21:50:47 +0200
Subject: [PATCH 2/5] memcmp: Make it possible to namespace the defined symbol.

* lib/memcmp.c (memcmp): Don't undefine outside of glibc.
---
 ChangeLog    | 5 +++++
 lib/memcmp.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4d2542b..8d2921d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2018-10-05  Bruno Haible  <br...@clisp.org>
 
+	memcmp: Make it possible to namespace the defined symbol.
+	* lib/memcmp.c (memcmp): Don't undefine outside of glibc.
+
+2018-10-05  Bruno Haible  <br...@clisp.org>
+
 	explicit_bzero: Make it possible to namespace the defined symbol.
 	* lib/explicit_bzero.c (explicit_bzero): Don't undefine outside of
 	glibc.
diff --git a/lib/memcmp.c b/lib/memcmp.c
index 9799dcb..8298ae4 100644
--- a/lib/memcmp.c
+++ b/lib/memcmp.c
@@ -27,10 +27,10 @@
 
 #include <stdint.h>
 
-#undef memcmp
-
 #ifdef _LIBC
 
+# undef memcmp
+
 # include <memcopy.h>
 # include <endian.h>
 
-- 
2.7.4

>From a50f188c7928e3d01d1b4c59712c50c3a571bfd0 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 5 Oct 2018 21:53:24 +0200
Subject: [PATCH 3/5] raise: Make it possible to namespace the defined symbol.

* lib/raise.c (raise): Undefine only after the replacement function has
been defined.
(raise): Renamed from rpl_raise.
(raise_nothrow): Move to the end of the compilation unit.
---
 ChangeLog   |  8 ++++++++
 lib/raise.c | 48 +++++++++++++++++++++++++-----------------------
 2 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8d2921d..8d4d249 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2018-10-05  Bruno Haible  <br...@clisp.org>
 
+	raise: Make it possible to namespace the defined symbol.
+	* lib/raise.c (raise): Undefine only after the replacement function has
+	been defined.
+	(raise): Renamed from rpl_raise.
+	(raise_nothrow): Move to the end of the compilation unit.
+
+2018-10-05  Bruno Haible  <br...@clisp.org>
+
 	memcmp: Make it possible to namespace the defined symbol.
 	* lib/memcmp.c (memcmp): Don't undefine outside of glibc.
 
diff --git a/lib/raise.c b/lib/raise.c
index 3a29339..8a93bea 100644
--- a/lib/raise.c
+++ b/lib/raise.c
@@ -31,27 +31,9 @@
 #  include "msvc-inval.h"
 # endif
 
-# undef raise
-
 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-static int
-raise_nothrow (int sig)
-{
-  int result;
-
-  TRY_MSVC_INVAL
-    {
-      result = raise (sig);
-    }
-  CATCH_MSVC_INVAL
-    {
-      result = -1;
-      errno = EINVAL;
-    }
-  DONE_MSVC_INVAL;
-
-  return result;
-}
+/* Forward declaration.  */
+static int raise_nothrow (int sig);
 # else
 #  define raise_nothrow raise
 # endif
@@ -61,12 +43,11 @@ raise_nothrow (int sig)
 
 # include <unistd.h>
 
-# define rpl_raise raise
-
 #endif
 
 int
-rpl_raise (int sig)
+raise (int sig)
+#undef raise
 {
 #if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE
   if (sig == SIGPIPE)
@@ -79,3 +60,24 @@ rpl_raise (int sig)
   return kill (getpid (), sig);
 #endif
 }
+
+#if HAVE_RAISE && HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+raise_nothrow (int sig)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = raise (sig);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EINVAL;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#endif
-- 
2.7.4

>From f6b7c8766bee0d297235771cbc91fe2e8353db34 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 5 Oct 2018 21:54:14 +0200
Subject: [PATCH 4/5] strcspn: Make it possible to namespace the defined
 symbol.

* lib/strcspn.c (strcspn): Don't undefine outside of glibc.
---
 ChangeLog     | 5 +++++
 lib/strcspn.c | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 8d4d249..10c3cd8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2018-10-05  Bruno Haible  <br...@clisp.org>
 
+	strcspn: Make it possible to namespace the defined symbol.
+	* lib/strcspn.c (strcspn): Don't undefine outside of glibc.
+
+2018-10-05  Bruno Haible  <br...@clisp.org>
+
 	raise: Make it possible to namespace the defined symbol.
 	* lib/raise.c (raise): Undefine only after the replacement function has
 	been defined.
diff --git a/lib/strcspn.c b/lib/strcspn.c
index 0e98603..735b91b 100644
--- a/lib/strcspn.c
+++ b/lib/strcspn.c
@@ -22,7 +22,9 @@
 #include <stddef.h>
 #include <string.h>
 
-#undef strcspn
+#if _LIBC
+# undef strcspn
+#endif
 
 /* Return the length of the maximum initial segment of S
    which contains no characters from REJECT.  */
-- 
2.7.4

>From 4719603f57f33099804664f691a072b5033fb11c Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 5 Oct 2018 21:54:56 +0200
Subject: [PATCH 5/5] strpbrk: Make it possible to namespace the defined
 symbol.

* lib/strpbrk.c (strpbrk): Don't undefine outside of glibc.
---
 ChangeLog     | 5 +++++
 lib/strpbrk.c | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 10c3cd8..e3688b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2018-10-05  Bruno Haible  <br...@clisp.org>
 
+	strpbrk: Make it possible to namespace the defined symbol.
+	* lib/strpbrk.c (strpbrk): Don't undefine outside of glibc.
+
+2018-10-05  Bruno Haible  <br...@clisp.org>
+
 	strcspn: Make it possible to namespace the defined symbol.
 	* lib/strcspn.c (strcspn): Don't undefine outside of glibc.
 
diff --git a/lib/strpbrk.c b/lib/strpbrk.c
index 1cdb2db..8aeefb9 100644
--- a/lib/strpbrk.c
+++ b/lib/strpbrk.c
@@ -22,7 +22,9 @@
 #include <stddef.h>
 #include <string.h>
 
-#undef strpbrk
+#if _LIBC
+# undef strpbrk
+#endif
 
 /* Find the first occurrence in S of any character in ACCEPT.  */
 char *
-- 
2.7.4

Reply via email to