texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Reimplement perl_only_* wrappers


From: Gavin D. Smith
Subject: branch master updated: Reimplement perl_only_* wrappers
Date: Sun, 03 Mar 2024 09:46:46 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 12b741c160 Reimplement perl_only_* wrappers
12b741c160 is described below

commit 12b741c160cd787141e459c72364751ea52c4f60
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Mar 3 14:46:39 2024 +0000

    Reimplement perl_only_* wrappers
    
    * tp/Texinfo/XS/main/build_perl_info.c
    (perl_only_strdup, perl_only_strndup): Reimplement as it is
    likely that Perl does not define its own versions of these.
---
 ChangeLog                            |  8 ++++++++
 tp/Texinfo/XS/main/build_perl_info.c | 30 +++++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 51f3558791..3b1238d27e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-03-03  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Reimplement perl_only_* wrappers
+
+       * tp/Texinfo/XS/main/build_perl_info.c
+       (perl_only_strdup, perl_only_strndup): Reimplement as it is
+       likely that Perl does not define its own versions of these.
+
 2024-03-03  Gavin Smith <gavinsmith0123@gmail.com>
 
        Consolidate "#undef free" comment.
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 10b27982ec..1eb3856eba 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -56,11 +56,11 @@
 
   /* NOTE This file includes the Perl headers, therefore we get the Perl
      redefinitions of functions related to memory allocation, such as
-     'free', 'malloc', 'strdup' or 'asprintf'. In other files, the Gnulib
-     redefinition of those functions are used. It is wrong to mix functions
-     from Perl and Gnulib. If memory is allocated with Gnulib defined malloc,
-     and then freed with Perl defined free (or vice versa), then an error
-     can occur like "Free to wrong pool".
+     'free' or 'malloc'.  In other files, the Gnulib redefinition of
+     those functions are used.  It is wrong to mix functions from Perl
+     and Gnulib.  If memory is allocated with Gnulib defined malloc,
+     and then freed with Perl defined free (or vice versa), then an
+     error can occur like "Free to wrong pool".
     https://lists.gnu.org/archive/html/bug-texinfo/2016-01/msg00016.html
    */
 
@@ -91,16 +91,32 @@ perl_only_malloc (size_t size)
   return malloc (size);
 }
 
+/* Implement as we are not sure that Perl will define a version of this
+   function. */
+/* NB this function does not appear to be used currently. */
 char *
 perl_only_strdup (const char *s)
 {
-  return strdup (s);
+  size_t len = strlen (s);
+  char *ret = perl_only_malloc (len+1);
+  memcpy (ret, s, len+1);
+  return ret;
 }
 
+/* Implement as we are not sure that Perl will define a version of this
+   function. */
+/* NB this function does not appear to be used currently. */
 char *
 perl_only_strndup (const char *s, size_t n)
 {
-  return strndup (s, n);
+  size_t len = strlen (s);
+  if (len > n)
+    len = n;
+
+  char *ret = perl_only_malloc (len+1);
+  memcpy (ret, s, len);
+  ret[len] = '\0';
+  return ret;
 }
 
 /* wrapper for vasprintf */



reply via email to

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