texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Add wrappers around functions to avoid mixing Per


From: Patrice Dumas
Subject: branch master updated: Add wrappers around functions to avoid mixing Perl and non-Perl
Date: Sun, 25 Feb 2024 18:59:18 -0500

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

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new ba169cd7a8 Add wrappers around functions to avoid mixing Perl and 
non-Perl
ba169cd7a8 is described below

commit ba169cd7a8a8e67f280b305e19412fb63d23c71c
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Feb 26 00:59:11 2024 +0100

    Add wrappers around functions to avoid mixing Perl and non-Perl
    
    * tp/Texinfo/XS/convert/call_html_perl_function.h,
    tp/Texinfo/XS/main/utils.h (TARGET_CONTENTS_FILENAME, FILE_NAME_PATH)
    (TARGET_DIRECTORY_FILENAME): move to main/utils.h.
    
    * tp/Texinfo/XS/*/*.xs, tp/Texinfo/XS/convert/build_html_perl_state.c
    (build_html_translated_names),
    tp/Texinfo/XS/convert/call_html_perl_function.c,
    tp/Texinfo/XS/convert/get_html_perl_info.c,
    tp/Texinfo/XS/main/api_to_perl.c, tp/Texinfo/XS/main/build_perl_info.c
    (perl_only_free, perl_only_malloc, perl_only_strdup)
    (perl_only_strndup, perl_only_xvasprintf, perl_only_xasprintf),
    tp/Texinfo/XS/main/call_perl_function.c,
    tp/Texinfo/XS/main/get_perl_info.c, tp/Texinfo/XS/main/utils.c
    (non_perl_free, non_perl_strdup, non_perl_strndup, new_string_list)
    (new_target_filename, new_target_contents_filename, new_file_name_path)
    (new_target_directory_filename, new_formatted_button_info),
    tp/maintain/regenerate_C_options_info.pl: add and use wrappers for
    some of free, strdup, strndup, malloc, xvasprintf and xasprintf with
    Perl only variants defined in files including only Perl headers (no
    gnulib headers) and non Perl variants defined in files not including
    Perl headers.  Also add constructors to call malloc in main/utils.c.
---
 ChangeLog                                       |  26 ++++
 tp/Texinfo/XS/convert/ConvertXS.xs              |  25 ++--
 tp/Texinfo/XS/convert/build_html_perl_state.c   |   6 +-
 tp/Texinfo/XS/convert/call_html_perl_function.c | 177 +++++++++++-------------
 tp/Texinfo/XS/convert/call_html_perl_function.h |  21 +--
 tp/Texinfo/XS/convert/get_html_perl_info.c      |  24 ++--
 tp/Texinfo/XS/main/DocumentXS.xs                |  11 +-
 tp/Texinfo/XS/main/IndicesXS.xs                 |   5 +-
 tp/Texinfo/XS/main/api_to_perl.c                |   5 +-
 tp/Texinfo/XS/main/build_perl_info.c            |  55 ++++++++
 tp/Texinfo/XS/main/build_perl_info.h            |   8 ++
 tp/Texinfo/XS/main/call_perl_function.c         |   6 +-
 tp/Texinfo/XS/main/get_perl_info.c              |  29 ++--
 tp/Texinfo/XS/main/utils.c                      |  82 +++++++++++
 tp/Texinfo/XS/main/utils.h                      |  34 ++++-
 tp/maintain/regenerate_C_options_info.pl        |   4 +-
 16 files changed, 349 insertions(+), 169 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7ea2cf0f24..a1fe0b38c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2024-02-25  Patrice Dumas  <pertusus@free.fr>
+
+       Add wrappers around functions to avoid mixing Perl and non-Perl
+
+       * tp/Texinfo/XS/convert/call_html_perl_function.h,
+       tp/Texinfo/XS/main/utils.h (TARGET_CONTENTS_FILENAME, FILE_NAME_PATH)
+       (TARGET_DIRECTORY_FILENAME): move to main/utils.h.
+
+       * tp/Texinfo/XS/*/*.xs, tp/Texinfo/XS/convert/build_html_perl_state.c
+       (build_html_translated_names),
+       tp/Texinfo/XS/convert/call_html_perl_function.c,
+       tp/Texinfo/XS/convert/get_html_perl_info.c,
+       tp/Texinfo/XS/main/api_to_perl.c, tp/Texinfo/XS/main/build_perl_info.c
+       (perl_only_free, perl_only_malloc, perl_only_strdup)
+       (perl_only_strndup, perl_only_xvasprintf, perl_only_xasprintf),
+       tp/Texinfo/XS/main/call_perl_function.c,
+       tp/Texinfo/XS/main/get_perl_info.c, tp/Texinfo/XS/main/utils.c
+       (non_perl_free, non_perl_strdup, non_perl_strndup, new_string_list)
+       (new_target_filename, new_target_contents_filename, new_file_name_path)
+       (new_target_directory_filename, new_formatted_button_info),
+       tp/maintain/regenerate_C_options_info.pl: add and use wrappers for
+       some of free, strdup, strndup, malloc, xvasprintf and xasprintf with
+       Perl only variants defined in files including only Perl headers (no
+       gnulib headers) and non Perl variants defined in files not including
+       Perl headers.  Also add constructors to call malloc in main/utils.c.
+
 2024-02-25  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/DocumentXS.xs, tp/Texinfo/XS/main/IndicesXS.xs,
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 91b3f016f5..aa9b47b239 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -363,7 +363,7 @@ plain_texinfo_convert_tree (SV *tree_in)
           {
             char *result = convert_to_texinfo (document->tree);
             RETVAL = newSVpv_utf8 (result, 0);
-            free (result);
+            non_perl_free (result);
           }
         else
           RETVAL = newSV(0);
@@ -393,7 +393,7 @@ text_convert_tree (SV *options_in, SV *tree_in)
 
             destroy_text_options (text_options);
             RETVAL = newSVpv_utf8 (result, 0);
-            free (result);
+            non_perl_free (result);
           }
         else
           {
@@ -625,7 +625,7 @@ html_debug_print_html_contexts (SV *converter_in)
            {
              char *result = debug_print_html_contexts (self);
              RETVAL = newSVpv_utf8 (result, 0);
-             free (result);
+             non_perl_free (result);
            }
          else
            RETVAL = newSVpv_utf8 ("", 0);
@@ -1113,7 +1113,7 @@ html_internal_command_href (SV *converter_in, SV 
*element_sv, SV *source_filenam
          if (href)
            {
              RETVAL = newSVpv_utf8 (href, 0);
-             free (href);
+             non_perl_free (href);
            }
          else
            RETVAL = newSV (0);
@@ -1144,7 +1144,7 @@ html_command_contents_href (SV *converter_in, SV 
*element_sv, cmdname, SV *sourc
          if (href)
            {
              RETVAL = newSVpv_utf8 (href, 0);
-             free (href);
+             non_perl_free (href);
            }
          else
            RETVAL = newSV (0);
@@ -1179,7 +1179,7 @@ html_footnote_location_href (SV *converter_in, SV 
*element_sv, SV *source_filena
          if (href)
            {
              RETVAL = newSVpv_utf8 (href, 0);
-             free (href);
+             non_perl_free (href);
            }
          else
            RETVAL = newSV (0);
@@ -1250,7 +1250,7 @@ html_internal_command_text (SV *converter_in, SV 
*element_sv, const char *type)
          if (text)
            {
              RETVAL = newSVpv_utf8 (text, 0);
-             free (text);
+             non_perl_free (text);
            }
          else
            RETVAL = newSV (0);
@@ -1272,7 +1272,7 @@ html_set_shared_conversion_state (SV *converter_in, 
cmdname, state_name, ...)
          if (args_nr > 0)
            {
              int i;
-             args_sv = (SV **) malloc (args_nr * sizeof (SV *));
+             args_sv = (SV **) perl_only_malloc (args_nr * sizeof (SV *));
              for (i = 0; i < args_nr; i++)
                {
                  args_sv[i] = ST(i+3);
@@ -1280,7 +1280,7 @@ html_set_shared_conversion_state (SV *converter_in, 
cmdname, state_name, ...)
            }
          html_set_shared_conversion_state (self, converter_in,
                                 cmdname, state_name, args_nr, args_sv);
-         free (args_sv);
+         perl_only_free (args_sv);
 
 SV *
 html_get_shared_conversion_state (SV *converter_in, cmdname, state_name, ...)
@@ -1297,7 +1297,7 @@ html_get_shared_conversion_state (SV *converter_in, 
cmdname, state_name, ...)
          if (args_nr > 0)
            {
              int i;
-             args_sv = (SV **) malloc (args_nr * sizeof (SV *));
+             args_sv = (SV **) perl_only_malloc (args_nr * sizeof (SV *));
              for (i = 0; i < args_nr; i++)
                {
                  args_sv[i] = ST(i+3);
@@ -1305,7 +1305,7 @@ html_get_shared_conversion_state (SV *converter_in, 
cmdname, state_name, ...)
            }
          RETVAL = html_get_shared_conversion_state (self, converter_in,
                                      cmdname, state_name, args_nr, args_sv);
-         free (args_sv);
+         perl_only_free (args_sv);
     OUTPUT:
          RETVAL
 
@@ -1371,8 +1371,7 @@ html_attribute_class (SV *converter_in, element, ...)
              char *result;
              if (classes_sv)
                {
-                 classes = (STRING_LIST *) malloc (sizeof (STRING_LIST));
-                 memset (classes, 0, sizeof (STRING_LIST));
+                 classes = new_string_list ();
                  add_svav_to_string_list (classes_sv, classes, svt_char);
                }
              result = html_attribute_class (self, element, classes);
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c 
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index 5d32e9de8c..df732a7dfd 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -40,6 +40,7 @@
 #include "convert_to_texinfo.h"
 #include "output_unit.h"
 #include "command_stack.h"
+/* also for perl_only_* wrappers */
 #include "build_perl_info.h"
 /* for NAMED_STRING_ELEMENT_LIST */
 #include "translations.h"
@@ -286,11 +287,10 @@ build_html_translated_names (HV *hv, CONVERTER *converter)
       const char *type_name = special_unit_info_type_names[string_type];
       char *key;
       HV *special_unit_hv = newHV ();
-      /* TODO do not call xasprintf/free?  See NOTE at the beginning */
-      xasprintf (&key, "%s_tree", type_name);
+      perl_only_xasprintf (&key, "%s_tree", type_name);
       hv_store (special_unit_info_hv, key, strlen (key),
                 newRV_noinc ((SV *) special_unit_hv), 0);
-      free (key);
+      perl_only_free (key);
     }
 
   /* pass all the information for each context for translated commands */
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.c 
b/tp/Texinfo/XS/convert/call_html_perl_function.c
index 771e5ef5c4..54ad4bcbf1 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.c
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.c
@@ -84,9 +84,7 @@ call_file_id_setting_special_unit_target_file_name (CONVERTER 
*self,
           SV *target_ret_sv;
           SV *filename_sv;
           STRLEN len;
-          TARGET_FILENAME *result
-            = (TARGET_FILENAME *) malloc (sizeof (TARGET_FILENAME));
-          result->filename = 0;
+          TARGET_FILENAME *result = new_target_filename ();
 
           dSP;
 
@@ -114,12 +112,12 @@ call_file_id_setting_special_unit_target_file_name 
(CONVERTER *self,
             {
               STRLEN len;
               filename = SvPVutf8 (filename_sv, len);
-              result->filename = strndup (filename, len);
+              result->filename = non_perl_strndup (filename, len);
             }
 
           target_ret_sv = POPs;
           target_ret = SvPVutf8 (target_ret_sv, len);
-          result->target = strndup (target_ret, len);
+          result->target = non_perl_strndup (target_ret, len);
 
           PUTBACK;
 
@@ -195,7 +193,7 @@ call_file_id_setting_label_target_name (CONVERTER *self,
 
           target_ret_sv = POPs;
           target_ret = SvPVutf8 (target_ret_sv, len);
-          result = strndup (target_ret, len);
+          result = non_perl_strndup (target_ret, len);
 
           PUTBACK;
 
@@ -270,7 +268,7 @@ call_file_id_setting_node_file_name (CONVERTER *self,
               char *node_filename_ret;
               STRLEN len;
               node_filename_ret = SvPVutf8 (node_filename_ret_sv, len);
-              result = strndup (node_filename_ret, len);
+              result = non_perl_strndup (node_filename_ret, len);
             }
           else
             result = 0;
@@ -324,8 +322,7 @@ call_file_id_setting_sectioning_command_target_name 
(CONVERTER *self,
           char *target_contents_ret;
           char *target_shortcontents_ret;
           char *filename_ret;
-          TARGET_CONTENTS_FILENAME *result = (TARGET_CONTENTS_FILENAME *)
-                                malloc (sizeof (TARGET_CONTENTS_FILENAME));
+          TARGET_CONTENTS_FILENAME *result = new_target_contents_filename ();
 
           dSP;
 
@@ -352,18 +349,18 @@ call_file_id_setting_sectioning_command_target_name 
(CONVERTER *self,
 
           filename_ret_sv = POPs;
           filename_ret = SvPVutf8 (filename_ret_sv, len);
-          result->filename = strndup (filename_ret, len);
+          result->filename = non_perl_strndup (filename_ret, len);
           target_shortcontents_ret_sv = POPs;
           target_shortcontents_ret = SvPVutf8 (target_shortcontents_ret_sv,
                                                len);
-          result->target_shortcontents = strndup (target_shortcontents_ret,
-                                                   len);
+          result->target_shortcontents
+            = non_perl_strndup (target_shortcontents_ret, len);
           target_contents_ret_sv = POPs;
           target_contents_ret = SvPVutf8 (target_contents_ret_sv, len);
-          result->target_contents = strndup (target_contents_ret, len);
+          result->target_contents = non_perl_strndup (target_contents_ret, 
len);
           target_ret_sv = POPs;
           target_ret = SvPVutf8 (target_ret_sv, len);
-          result->target = strndup (target_ret, len);
+          result->target = non_perl_strndup (target_ret, len);
 
           PUTBACK;
 
@@ -406,9 +403,7 @@ call_file_id_setting_unit_file_name (CONVERTER *self,
           int count;
           SV *filepath_ret_sv;
           SV *filename_ret_sv;
-          FILE_NAME_PATH *result
-            = (FILE_NAME_PATH *) malloc (sizeof (FILE_NAME_PATH));
-          memset (result, 0, sizeof (FILE_NAME_PATH));
+          FILE_NAME_PATH *result = new_file_name_path ();
 
           dSP;
 
@@ -436,7 +431,7 @@ call_file_id_setting_unit_file_name (CONVERTER *self,
             {
               STRLEN len;
               char *filepath_ret = SvPVutf8 (filepath_ret_sv, len);
-              result->filepath = strndup (filepath_ret, len);
+              result->filepath = non_perl_strndup (filepath_ret, len);
             }
 
           filename_ret_sv = POPs;
@@ -444,7 +439,7 @@ call_file_id_setting_unit_file_name (CONVERTER *self,
             {
               STRLEN len;
               char *filename_ret = SvPVutf8 (filename_ret_sv, len);
-              result->filename = strndup (filename_ret, len);
+              result->filename = non_perl_strndup (filename_ret, len);
             }
 
           PUTBACK;
@@ -487,9 +482,7 @@ call_file_id_setting_external_target_split_name (CONVERTER 
*self,
           SV *target_sv;
           SV *filename_sv;
           SV *directory_sv;
-          TARGET_DIRECTORY_FILENAME *result = (TARGET_DIRECTORY_FILENAME *)
-              malloc (sizeof (TARGET_DIRECTORY_FILENAME));
-          memset (result, 0, sizeof (TARGET_DIRECTORY_FILENAME));
+          TARGET_DIRECTORY_FILENAME *result = new_target_directory_filename ();
 
           dSP;
 
@@ -519,30 +512,30 @@ call_file_id_setting_external_target_split_name 
(CONVERTER *self,
             {
               STRLEN len;
               char *filename_ret = SvPVutf8 (filename_sv, len);
-              result->filename = strndup (filename_ret, len);
+              result->filename = non_perl_strndup (filename_ret, len);
             }
           else
-            result->filename = strdup ("");
+            result->filename = non_perl_strdup ("");
 
           directory_sv = POPs;
           if (SvOK (directory_sv))
             {
               STRLEN len;
               char *directory_ret = SvPVutf8 (directory_sv, len);
-              result->directory = strndup (directory_ret, len);
+              result->directory = non_perl_strndup (directory_ret, len);
             }
           else
-            result->directory = strdup ("");
+            result->directory = non_perl_strdup ("");
 
           target_sv = POPs;
           if (SvOK (target_sv))
             {
               STRLEN len;
               char *target_ret = SvPVutf8 (target_sv, len);
-              result->target = strndup (target_ret, len);
+              result->target = non_perl_strndup (target_ret, len);
             }
           else
-            result->target = strdup ("");
+            result->target = non_perl_strdup ("");
 
           PUTBACK;
 
@@ -582,9 +575,7 @@ call_file_id_setting_external_target_non_split_name 
(CONVERTER *self,
           int count;
           SV *target_sv;
           SV *file_sv;
-          TARGET_FILENAME *result
-            = (TARGET_FILENAME *) malloc (sizeof (TARGET_FILENAME));
-          result->filename = 0;
+          TARGET_FILENAME *result = new_target_filename ();
 
           dSP;
 
@@ -612,16 +603,16 @@ call_file_id_setting_external_target_non_split_name 
(CONVERTER *self,
           if (SvOK (file_sv))
             {
               STRLEN len;
-              char *file_ret = SvPVutf8 (file_sv, len);
-              result->filename = strndup (file_ret, len);
+              const char *file_ret = SvPVutf8 (file_sv, len);
+              result->filename = non_perl_strndup (file_ret, len);
             }
 
           target_sv = POPs;
           if (SvOK (target_sv))
             {
               STRLEN len;
-              char *target_ret = SvPVutf8 (target_sv, len);
-              result->target = strndup (target_ret, len);
+              const char *target_ret = SvPVutf8 (target_sv, len);
+              result->target = non_perl_strndup (target_ret, len);
             }
 
           PUTBACK;
@@ -645,7 +636,7 @@ call_formatting_function_format_comment (CONVERTER *self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -685,7 +676,7 @@ call_formatting_function_format_comment (CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -701,7 +692,7 @@ call_formatting_function_format_program_string (CONVERTER 
*self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -740,7 +731,7 @@ call_formatting_function_format_program_string (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -756,7 +747,7 @@ call_formatting_function_format_titlepage (CONVERTER *self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -795,7 +786,7 @@ call_formatting_function_format_titlepage (CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -811,7 +802,7 @@ call_formatting_function_format_title_titlepage (CONVERTER 
*self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -850,7 +841,7 @@ call_formatting_function_format_title_titlepage (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -867,7 +858,7 @@ call_formatting_function_format_protect_text (CONVERTER 
*self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -907,7 +898,7 @@ call_formatting_function_format_protect_text (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -923,7 +914,7 @@ call_formatting_function_format_footnotes_segment 
(CONVERTER *self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -962,7 +953,7 @@ call_formatting_function_format_footnotes_segment 
(CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -978,7 +969,7 @@ call_formatting_function_format_footnotes_sequence 
(CONVERTER *self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1017,7 +1008,7 @@ call_formatting_function_format_footnotes_sequence 
(CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1034,7 +1025,7 @@ call_formatting_function_format_css_lines (CONVERTER 
*self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1074,7 +1065,7 @@ call_formatting_function_format_css_lines (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1091,7 +1082,7 @@ call_formatting_function_format_end_file (CONVERTER *self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1138,7 +1129,7 @@ call_formatting_function_format_end_file (CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1156,7 +1147,7 @@ call_formatting_function_format_begin_file (CONVERTER 
*self,
 {
   int count;
   char *result;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1203,7 +1194,7 @@ call_formatting_function_format_begin_file (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1221,7 +1212,7 @@ call_formatting_function_format_translate_message 
(CONVERTER *self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1265,7 +1256,7 @@ call_formatting_function_format_translate_message 
(CONVERTER *self,
   if (SvOK (result_sv))
     {
       result_ret = SvPVutf8 (result_sv, len);
-      result = strndup (result_ret, len);
+      result = non_perl_strndup (result_ret, len);
     }
 
   PUTBACK;
@@ -1286,7 +1277,7 @@ call_formatting_function_format_button_icon_img 
(CONVERTER *self,
   int count;
   SV *name_sv;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1335,7 +1326,7 @@ call_formatting_function_format_button_icon_img 
(CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1372,9 +1363,7 @@ call_formatting_function_format_button (CONVERTER *self,
 
   build_tree_to_build (&self->tree_to_build);
 
-  FORMATTED_BUTTON_INFO *result
-   = (FORMATTED_BUTTON_INFO *) malloc (sizeof (FORMATTED_BUTTON_INFO));
-  memset (result, 0, sizeof (FORMATTED_BUTTON_INFO));
+  FORMATTED_BUTTON_INFO *result = new_formatted_button_info ();
 
   dSP;
 
@@ -1409,16 +1398,16 @@ call_formatting_function_format_button (CONVERTER *self,
   if (SvOK (passive_sv))
     {
       STRLEN len;
-      char *passive_ret = SvPVutf8 (passive_sv, len);
-      result->passive = strdup (passive_ret);
+      const char *passive_ret = SvPVutf8 (passive_sv, len);
+      result->passive = non_perl_strndup (passive_ret, len);
     }
 
   active_sv = POPs;
   if (SvOK (active_sv))
     {
       STRLEN len;
-      char *active_ret = SvPVutf8 (active_sv, len);
-      result->active = strdup (active_ret);
+      const char *active_ret = SvPVutf8 (active_sv, len);
+      result->active = non_perl_strndup (active_ret, len);
     }
 
   PUTBACK;
@@ -1438,7 +1427,7 @@ call_formatting_function_format_navigation_panel 
(CONVERTER *self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1483,7 +1472,7 @@ call_formatting_function_format_navigation_panel 
(CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1502,7 +1491,7 @@ call_formatting_function_format_navigation_header 
(CONVERTER *self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1546,7 +1535,7 @@ call_formatting_function_format_navigation_header 
(CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1567,7 +1556,7 @@ call_formatting_function_format_heading_text (CONVERTER 
*self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1637,7 +1626,7 @@ call_formatting_function_format_heading_text (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1655,7 +1644,7 @@ call_formatting_function_format_contents (CONVERTER *self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *command_sv;
   SV *result_sv;
@@ -1705,7 +1694,7 @@ call_formatting_function_format_contents (CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1722,7 +1711,7 @@ call_formatting_function_format_separate_anchor 
(CONVERTER *self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1765,7 +1754,7 @@ call_formatting_function_format_separate_anchor 
(CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1783,7 +1772,7 @@ call_formatting_function_format_element_header (CONVERTER 
*self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1827,7 +1816,7 @@ call_formatting_function_format_element_header (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1846,7 +1835,7 @@ call_formatting_function_format_element_footer (CONVERTER 
*self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1893,7 +1882,7 @@ call_formatting_function_format_element_footer (CONVERTER 
*self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1910,7 +1899,7 @@ call_formatting_function_format_node_redirection_page 
(CONVERTER *self,
 {
   int count;
   char *result = 0;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -1953,7 +1942,7 @@ call_formatting_function_format_node_redirection_page 
(CONVERTER *self,
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -1973,7 +1962,7 @@ call_types_conversion (CONVERTER *self, const enum 
element_type type,
                        TEXT *result)
 {
   int count;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -2043,7 +2032,7 @@ call_types_open (CONVERTER *self, const enum element_type 
type,
                  const ELEMENT *element, TEXT *result)
 {
   int count;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -2105,7 +2094,7 @@ call_commands_conversion (CONVERTER *self, const enum 
command_id cmd,
                           const char *content, TEXT *result)
 {
   int count;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -2175,7 +2164,7 @@ call_commands_open (CONVERTER *self, const enum 
command_id cmd,
                     const ELEMENT *element, TEXT *result)
 {
   int count;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -2240,7 +2229,7 @@ call_output_units_conversion (CONVERTER *self,
                               const char *content, TEXT *result)
 {
   int count;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -2307,7 +2296,7 @@ call_special_unit_body_formatting (CONVERTER *self,
                               TEXT *result)
 {
   int count;
-  char *result_ret;
+  const char *result_ret;
   STRLEN len;
   SV *result_sv;
   SV *formatting_reference_sv;
@@ -2387,9 +2376,7 @@ call_button_simple_function (CONVERTER *self,
       self->modified_state = 0;
     }
 
-  result
-   = (FORMATTED_BUTTON_INFO *) malloc (sizeof (FORMATTED_BUTTON_INFO));
-  memset (result, 0, sizeof (FORMATTED_BUTTON_INFO));
+  result = new_formatted_button_info ();
 
   dSP;
 
@@ -2421,7 +2408,7 @@ call_button_simple_function (CONVERTER *self,
     {
       STRLEN len;
       char *active_ret = SvPVutf8 (active_sv, len);
-      result->active = strndup (active_ret, len);
+      result->active = non_perl_strndup (active_ret, len);
     }
 
   PUTBACK;
@@ -2455,9 +2442,7 @@ call_button_direction_function (CONVERTER *self,
       self->modified_state = 0;
     }
 
-  result
-   = (FORMATTED_BUTTON_INFO *) malloc (sizeof (FORMATTED_BUTTON_INFO));
-  memset (result, 0, sizeof (FORMATTED_BUTTON_INFO));
+  result = new_formatted_button_info ();
 
   dSP;
 
@@ -2493,7 +2478,7 @@ call_button_direction_function (CONVERTER *self,
     {
       STRLEN len;
       char *active_ret = SvPVutf8 (active_sv, len);
-      result->active = strndup (active_ret, len);
+      result->active = non_perl_strndup (active_ret, len);
     }
 
   PUTBACK;
diff --git a/tp/Texinfo/XS/convert/call_html_perl_function.h 
b/tp/Texinfo/XS/convert/call_html_perl_function.h
index c2f26636b6..96e91f0d9a 100644
--- a/tp/Texinfo/XS/convert/call_html_perl_function.h
+++ b/tp/Texinfo/XS/convert/call_html_perl_function.h
@@ -5,28 +5,11 @@
 #include "tree_types.h"
 #include "option_types.h"
 #include "converter_types.h"
-/* for TARGET_FILENAME */
+/* for TARGET_FILENAME TARGET_CONTENTS_FILENAME FILE_NAME_PATH
+   TARGET_DIRECTORY_FILENAME */
 #include "utils.h"
 #include "translations.h"
 
-typedef struct FILE_NAME_PATH {
-    char *filename;
-    char *filepath;
-} FILE_NAME_PATH;
-
-typedef struct TARGET_DIRECTORY_FILENAME {
-    char *filename;
-    char *directory;
-    char *target;
-} TARGET_DIRECTORY_FILENAME;
-
-typedef struct TARGET_CONTENTS_FILENAME {
-    char *target;
-    char *filename;
-    char *target_contents;
-    char *target_shortcontents;
-} TARGET_CONTENTS_FILENAME;
-
 TARGET_FILENAME *call_file_id_setting_special_unit_target_file_name
                             (CONVERTER *self,
                           const OUTPUT_UNIT *special_unit, const char *target,
diff --git a/tp/Texinfo/XS/convert/get_html_perl_info.c 
b/tp/Texinfo/XS/convert/get_html_perl_info.c
index b9929a7976..1e372de736 100644
--- a/tp/Texinfo/XS/convert/get_html_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_html_perl_info.c
@@ -204,11 +204,11 @@ html_converter_initialize_sv (SV *converter_sv,
               HTMLXREF_MANUAL *htmlxref_manual = &converter->htmlxref.list[i];
               HE *next = hv_iternext (htmlxref_hv);
               SV *selector_sv = hv_iterkeysv (next);
-              char *selector = (char *) SvPVutf8_nolen (selector_sv);
+              const char *selector = (char *) SvPVutf8_nolen (selector_sv);
               SV *split_type_sv = HeVAL(next);
               HV *split_type_hv = (HV *) SvRV (split_type_sv);
 
-              htmlxref_manual->manual = strdup (selector);
+              htmlxref_manual->manual = non_perl_strdup (selector);
 
               for (j = 0; j < htmlxref_split_type_chapter +1; j++)
                 {
@@ -220,8 +220,9 @@ html_converter_initialize_sv (SV *converter_sv,
                      it is ignored later on when checking an external href */
                   if (urlprefix_sv && SvOK (*urlprefix_sv))
                     {
-                      char *urlprefix = SvPVutf8_nolen (*urlprefix_sv);
-                      htmlxref_manual->urlprefix[j] = strdup (urlprefix);
+                      const char *urlprefix = SvPVutf8_nolen (*urlprefix_sv);
+                      htmlxref_manual->urlprefix[j]
+                        = non_perl_strdup (urlprefix);
                     }
                 }
             }
@@ -523,7 +524,7 @@ html_converter_initialize_sv (SV *converter_sv,
                         {
                           char *value
                             = (char *) SvPVutf8_nolen (*info_type_variety_sv);
-                          converter->special_unit_info[j][k] = strdup (value);
+                          converter->special_unit_info[j][k] = non_perl_strdup 
(value);
                         }
                       else
                         converter->special_unit_info[j][k] = 0;
@@ -621,7 +622,7 @@ html_converter_initialize_sv (SV *converter_sv,
                                             &type_name, &retlen);
           if (SvOK (pre_class_sv))
             {
-              char *pre_class = SvPV_nolen (pre_class_sv);
+              const char *pre_class = SvPV_nolen (pre_class_sv);
               enum element_type type = find_element_type (type_name);
 
               if (type == ET_NONE)
@@ -630,7 +631,7 @@ html_converter_initialize_sv (SV *converter_sv,
                            type_name);
                 }
               else
-                converter->pre_class_types[type] = strdup (pre_class);
+                converter->pre_class_types[type] = non_perl_strdup (pre_class);
             }
         }
     }
@@ -698,7 +699,7 @@ html_converter_initialize_sv (SV *converter_sv,
                   if (entity_sv)
                     {
                       char *entity = (char *) SvPVutf8_nolen (*entity_sv);
-                      accent_info->entity = strdup (entity);
+                      accent_info->entity = non_perl_strdup (entity);
                     }
 
                   if (characters_sv && SvOK (*characters_sv))
@@ -706,7 +707,7 @@ html_converter_initialize_sv (SV *converter_sv,
                       char *characters
                         = (char *) SvPVutf8_nolen (*characters_sv);
                       if (strlen (characters))
-                        accent_info->characters = strdup (characters);
+                        accent_info->characters = non_perl_strdup (characters);
                     }
                 }
             }
@@ -797,9 +798,10 @@ html_converter_initialize_sv (SV *converter_sv,
                                                            &key, &retlen);
                               if (!strcmp (key, "element"))
                                 {
-                                  char *tmp_spec
+                                  const char *tmp_spec
                                     = (char *) SvPVutf8_nolen (spec_sv);
-                                  format_spec->element = strdup (tmp_spec);
+                                  format_spec->element
+                                    = non_perl_strdup (tmp_spec);
                                 }
                               else if (!strcmp (key, "quote"))
                                 format_spec->quote = SvIV (spec_sv);
diff --git a/tp/Texinfo/XS/main/DocumentXS.xs b/tp/Texinfo/XS/main/DocumentXS.xs
index 2d051fcef1..0a846bd9be 100644
--- a/tp/Texinfo/XS/main/DocumentXS.xs
+++ b/tp/Texinfo/XS/main/DocumentXS.xs
@@ -29,6 +29,8 @@
 #include "tree_types.h"
 #include "document_types.h"
 #include "extra.h"
+/* for non_perl_* */
+#include "utils.h"
 #include "document.h"
 #include "translations.h"
 #include "get_perl_info.h"
@@ -130,17 +132,18 @@ set_document_global_info (SV *document_in, char *key, SV 
*value_sv)
                         "BUG: %d: reset input_file_name '%s' -> '%s'\n",
                         document->descriptor,
                         document->global_info->input_file_name, value);
-                    free (document->global_info->input_file_name);
+                    non_perl_free (document->global_info->input_file_name);
                   }
-                document->global_info->input_file_name = strdup (value);
+                document->global_info->input_file_name
+                  = non_perl_strdup (value);
               }
             else if (!strcmp (key, "input_perl_encoding"))
               {
                 /* should not be needed, but in case global information
                    is reused, it will be ok */
-                free (document->global_info->input_perl_encoding);
+                non_perl_free (document->global_info->input_perl_encoding);
                 document->global_info->input_perl_encoding
-                   = strdup ((char *)SvPVbyte_nolen(value_sv));
+                   = non_perl_strdup ((char *)SvPVbyte_nolen(value_sv));
               }
             else
               {
diff --git a/tp/Texinfo/XS/main/IndicesXS.xs b/tp/Texinfo/XS/main/IndicesXS.xs
index 94ef051f5a..1c2ce5c470 100644
--- a/tp/Texinfo/XS/main/IndicesXS.xs
+++ b/tp/Texinfo/XS/main/IndicesXS.xs
@@ -27,9 +27,10 @@
 
 #include "tree_types.h"
 #include "document_types.h"
+/* non_perl_* */
+#include "utils.h"
 /*
 #include "tree.h"
-#include "utils.h"
  */
 #include "document.h"
 #include "manipulate_indices.h"
@@ -144,7 +145,7 @@ index_entry_element_sort_string (SV *customization_info_sv, 
SV *main_entry_sv, S
        else
          {
            RETVAL = newSVpv_utf8 (sort_string, 0);
-           free (sort_string);
+           non_perl_free (sort_string);
          }
     OUTPUT:
          RETVAL
diff --git a/tp/Texinfo/XS/main/api_to_perl.c b/tp/Texinfo/XS/main/api_to_perl.c
index 224dd9c91f..0eee28c0c6 100644
--- a/tp/Texinfo/XS/main/api_to_perl.c
+++ b/tp/Texinfo/XS/main/api_to_perl.c
@@ -34,6 +34,8 @@
 #include "tree_types.h"
 #include "option_types.h"
 #include "converter_types.h"
+/* non_perl_* */
+#include "utils.h"
 
 /* to be called when a tree element is destroyed, to remove the reference
    of the association with the C tree */
@@ -62,7 +64,8 @@ get_perl_scalar_reference_value (const void *sv_string)
 {
   dTHX;
 
-  char *value = strdup ((char *) SvPVutf8_nolen (SvRV ((SV *) sv_string)));
+  const char *value_tmp = (char *) SvPVutf8_nolen (SvRV ((SV *) sv_string));
+  char *value = non_perl_strdup (value_tmp);
   return value;
 }
 
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index b63fe70e02..04e56bdb2e 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -14,6 +14,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
+#include <stdio.h>
+#include <stdarg.h>
 
 /* Avoid namespace conflicts. */
 #define context perl_context
@@ -67,8 +69,61 @@
       free or allocate in files using Gnulib definitions.
 
       TODO say something about wrappers.
+
+      To be sure to use Perl defined functions, wrappers
+      can be used, from build_perl_info.h:
+       perl_only_free, perl_only_strdup, perl_only_strndup.
+
+
+      To be sure to use non Perl defined functions, wrappers
+      can be used, from utils.h:
+       non_perl_free, non_perl_strdup, non_perl_strndup.
     */
 
+/* wrappers to be sure to use Perl defined functions */
+void
+perl_only_free (void *ptr)
+{
+  free (ptr);
+}
+
+void *
+perl_only_malloc (size_t size)
+{
+  return malloc (size);
+}
+
+char *
+perl_only_strdup (const char *s)
+{
+  return strdup (s);
+}
+
+char *
+perl_only_strndup (const char *s, size_t n)
+{
+  return strndup (s, n);
+}
+
+/* wrapper for vasprintf */
+int
+perl_only_xvasprintf (char **ptr, const char *template, va_list ap)
+{
+  int ret;
+  ret = vasprintf (ptr, template, ap);
+  if (ret < 0)
+    abort (); /* out of memory */
+  return ret;
+}
+
+/* wrapper for asprintf */
+int
+perl_only_xasprintf (char **ptr, const char *template, ...)
+{
+  va_list v;
+  va_start (v, template);
+  return perl_only_xvasprintf (ptr, template, v);
+}
 
 int
 init (int texinfo_uninstalled, char *builddir)
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index d5c853b164..72d3a9f961 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -3,6 +3,7 @@
 #define BUILD_PERL_INFO_H
 
 #include <stddef.h>
+#include <stdarg.h>
 
 #include "EXTERN.h"
 #include "perl.h"
@@ -13,6 +14,13 @@
 #include "converter_types.h"
 #include "options_types.h"
 
+void perl_only_free (void *ptr);
+void *perl_only_malloc (size_t size);
+char *perl_only_strdup (const char *s);
+char *perl_only_strndup (const char *s, size_t n);
+int perl_only_xvasprintf (char **ptr, const char *template, va_list ap);
+int perl_only_xasprintf (char **ptr, const char *template, ...);
+
 int init (int texinfo_uninstalled, char *srcdir_in);
 
 /* in options_get_perl.c */
diff --git a/tp/Texinfo/XS/main/call_perl_function.c 
b/tp/Texinfo/XS/main/call_perl_function.c
index 2c4a2eeb19..441c9b351c 100644
--- a/tp/Texinfo/XS/main/call_perl_function.c
+++ b/tp/Texinfo/XS/main/call_perl_function.c
@@ -30,6 +30,8 @@
 #include "tree_types.h"
 #include "converter_types.h"
 #include "document_types.h"
+/* for non_perl_strndup and similar */
+#include "utils.h"
 #include "build_perl_info.h"
 #include "call_perl_function.h"
 
@@ -69,7 +71,7 @@ call_nodenamenormalization_unicode_to_transliterate (const 
char *text)
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
@@ -135,7 +137,7 @@ call_latex_convert_to_latex_math (CONVERTER *self, const 
ELEMENT *element)
 
   result_sv = POPs;
   result_ret = SvPVutf8 (result_sv, len);
-  result = strndup (result_ret, len);
+  result = non_perl_strndup (result_ret, len);
 
   PUTBACK;
 
diff --git a/tp/Texinfo/XS/main/get_perl_info.c 
b/tp/Texinfo/XS/main/get_perl_info.c
index e51346a972..193a0e4a41 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -41,6 +41,8 @@
 #include "output_unit.h"
 #include "convert_to_text.h"
 #include "converter.h"
+/* for perl_only_* */
+#include "build_perl_info.h"
 #include "get_perl_info.h"
 
  /* See the NOTE in build_perl_info.c on use of functions related to
@@ -282,7 +284,7 @@ get_source_info (SV *source_info_sv)
   if (macro_sv)
     {
       char *macro = (char *) SvPVutf8_nolen (*macro_sv);
-      source_info->macro = strdup (macro);
+      source_info->macro = non_perl_strdup (macro);
     }
 
   FETCH(file_name)
@@ -290,7 +292,7 @@ get_source_info (SV *source_info_sv)
   if (file_name_sv && SvOK (*file_name_sv))
     {
       char *file_name = (char *) SvPVbyte_nolen (*file_name_sv);
-      source_info->file_name = strdup (file_name);
+      source_info->file_name = non_perl_strdup (file_name);
     }
 
   FETCH(line_nr)
@@ -312,7 +314,7 @@ get_line_message (CONVERTER *self, enum error_type type, 
int continuation,
     {
       char *saved_string = add_string (source_info->file_name,
                                        &self->small_strings);
-      free (source_info->file_name);
+      non_perl_free (source_info->file_name);
       source_info->file_name = saved_string;
     }
 
@@ -320,7 +322,7 @@ get_line_message (CONVERTER *self, enum error_type type, 
int continuation,
     {
       char *saved_string = add_string (source_info->macro,
                                        &self->small_strings);
-      free (source_info->macro);
+      non_perl_free (source_info->macro);
       source_info->macro = saved_string;
     }
 
@@ -328,7 +330,7 @@ get_line_message (CONVERTER *self, enum error_type type, 
int continuation,
                                        type, continuation, source_info,
                                        message, do_warn);
 
-  free (source_info);
+  non_perl_free (source_info);
 }
 
 void
@@ -497,7 +499,7 @@ set_translated_commands (CONVERTER *converter, HV *hv_in)
                   char *tmp_spec = (char *) SvPVutf8_nolen (translation_sv);
                   TRANSLATED_COMMAND *translated_command
                     = &converter->translated_commands[i];
-                  translated_command->translation = strdup (tmp_spec);
+                  translated_command->translation = non_perl_strdup (tmp_spec);
                   translated_command->cmd = cmd;
                 }
             }
@@ -578,7 +580,7 @@ converter_initialize (SV *converter_sv)
   if (output_format_sv && SvOK (*output_format_sv))
     {
       converter->output_format
-         = strdup (SvPVutf8_nolen (*output_format_sv));
+         = non_perl_strdup (SvPVutf8_nolen (*output_format_sv));
     }
 
    /*
@@ -805,7 +807,7 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
       letter_entries_nr = av_top_index (av) +1;
 
       index_index_letters = &indices_entries_by_letter[j];
-      index_index_letters->name = strdup (idx_name);
+      index_index_letters->name = non_perl_strdup (idx_name);
       index_index_letters->letter_number = letter_entries_nr;
       index_index_letters->letter_entries
         = (LETTER_INDEX_ENTRIES *)
@@ -836,7 +838,7 @@ get_sv_index_entries_sorted_by_letter (INDEX **index_names,
                   fatal (msg);
                 }
               letter_string = (char *) SvPVutf8_nolen (*letter_sv);
-              letter_entries->letter = strdup (letter_string);
+              letter_entries->letter = non_perl_strdup (letter_string);
 
               entries_av = (AV *) SvRV (*entries_sv);
               entries_nr = av_top_index (entries_av) +1;
@@ -859,13 +861,13 @@ get_sv_index_entries_sorted_by_letter (INDEX 
**index_names,
                              idx_name, i, letter_entries->letter, k);
                       fatal (msg);
                     }
-                  xasprintf (&warn_string,
+                  perl_only_xasprintf (&warn_string,
                          "get_sv_index_entries_sorted_by_letter: %s: %d: %s: 
%d",
                          idx_name, i, letter_entries->letter, k);
                   index_entry = find_index_entry_sv (*index_entry_sv, 
index_names,
                                                      warn_string, &entry_idx,
                                                      &entry_number);
-                  free (warn_string);
+                  perl_only_free (warn_string);
 
                   letter_entries->entries[k] = index_entry;
 
@@ -957,7 +959,8 @@ copy_sv_options_for_convert_text (SV *sv_in)
 
   FETCH(enabled_encoding)
   if (enabled_encoding_sv)
-    text_options->encoding = strdup (SvPVutf8_nolen (*enabled_encoding_sv));
+    text_options->encoding
+      = non_perl_strdup (SvPVutf8_nolen (*enabled_encoding_sv));
 
   FETCH(set_case)
   if (set_case_sv)
@@ -1210,7 +1213,7 @@ html_get_direction_icons_sv (const CONVERTER *converter,
       if (direction_icon_sv && SvOK (*direction_icon_sv))
         {
           direction_icons->list[i]
-            = strdup (SvPVutf8_nolen (*direction_icon_sv));
+            = non_perl_strdup (SvPVutf8_nolen (*direction_icon_sv));
         }
       else
         direction_icons->list[i] = 0;
diff --git a/tp/Texinfo/XS/main/utils.c b/tp/Texinfo/XS/main/utils.c
index 6c24db12f5..b922d7b060 100644
--- a/tp/Texinfo/XS/main/utils.c
+++ b/tp/Texinfo/XS/main/utils.c
@@ -137,6 +137,25 @@ char *html_command_text_type_name[] = {
   "href", "node", "section",
 };
 
+/* wrappers to be sure to use non-Perl defined functions */
+void
+non_perl_free (void *ptr)
+{
+  free (ptr);
+}
+
+char *
+non_perl_strdup (const char *s)
+{
+  return strdup (s);
+}
+
+char *
+non_perl_strndup (const char *s, size_t n)
+{
+  return strndup (s, n);
+}
+
 /* wrapper for asprintf */
 int
 xasprintf (char **ptr, const char *template, ...)
@@ -827,6 +846,16 @@ wipe_index_names (INDEX **index_names)
 
 
 /* string lists */
+
+STRING_LIST *
+new_string_list (void)
+{
+  STRING_LIST *result = (STRING_LIST *) malloc (sizeof (STRING_LIST));
+  memset (result, 0, sizeof (STRING_LIST));
+
+  return result;
+}
+
 /* include directories and include file */
 
 void
@@ -1615,3 +1644,56 @@ initialize_option (OPTION *option, enum 
global_option_type type)
       default:
     }
 }
+
+
+/* constructors in particular called from files including perl headers */
+
+TARGET_FILENAME *
+new_target_filename (void)
+{
+  TARGET_FILENAME *result
+    = (TARGET_FILENAME *) malloc (sizeof (TARGET_FILENAME));
+
+  result->filename = 0;
+
+  return result;
+}
+
+TARGET_CONTENTS_FILENAME *
+new_target_contents_filename (void)
+{
+  TARGET_CONTENTS_FILENAME *result = (TARGET_CONTENTS_FILENAME *)
+                         malloc (sizeof (TARGET_CONTENTS_FILENAME));
+
+  return result;
+}
+
+FILE_NAME_PATH *
+new_file_name_path (void)
+{
+  FILE_NAME_PATH *result
+   = (FILE_NAME_PATH *) malloc (sizeof (FILE_NAME_PATH));
+  memset (result, 0, sizeof (FILE_NAME_PATH));
+
+  return result;
+}
+
+TARGET_DIRECTORY_FILENAME *
+new_target_directory_filename (void)
+{
+  TARGET_DIRECTORY_FILENAME *result = (TARGET_DIRECTORY_FILENAME *)
+              malloc (sizeof (TARGET_DIRECTORY_FILENAME));
+  memset (result, 0, sizeof (TARGET_DIRECTORY_FILENAME));
+
+  return result;
+}
+
+FORMATTED_BUTTON_INFO *
+new_formatted_button_info (void)
+{
+  FORMATTED_BUTTON_INFO *result
+   = (FORMATTED_BUTTON_INFO *) malloc (sizeof (FORMATTED_BUTTON_INFO));
+  memset (result, 0, sizeof (FORMATTED_BUTTON_INFO));
+
+  return result;
+}
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 163d8fa9a0..cba2de61cf 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -45,12 +45,12 @@ extern const char *command_location_names[];
 extern const char *html_button_direction_names[];
 extern char *html_command_text_type_name[];
 
-typedef struct {
+typedef struct ENCODING_CONVERSION {
     char *encoding_name;
     iconv_t iconv;
 } ENCODING_CONVERSION;
 
-typedef struct {
+typedef struct ENCODING_CONVERSION_LIST {
     ENCODING_CONVERSION *list;
     size_t number;
     size_t space;
@@ -60,7 +60,7 @@ typedef struct {
 extern ENCODING_CONVERSION_LIST output_conversions;
 extern ENCODING_CONVERSION_LIST input_conversions;
 
-typedef struct {
+typedef struct DEF_ALIAS {
     enum command_id alias;
     enum command_id command;
     char *category;
@@ -148,6 +148,27 @@ typedef struct ACCENTS_STACK {
     ELEMENT *argument;
 } ACCENTS_STACK;
 
+typedef struct TARGET_CONTENTS_FILENAME {
+    char *target;
+    char *filename;
+    char *target_contents;
+    char *target_shortcontents;
+} TARGET_CONTENTS_FILENAME;
+
+typedef struct FILE_NAME_PATH {
+    char *filename;
+    char *filepath;
+} FILE_NAME_PATH;
+
+typedef struct TARGET_DIRECTORY_FILENAME {
+    char *filename;
+    char *directory;
+    char *target;
+} TARGET_DIRECTORY_FILENAME;
+
+void non_perl_free (void *ptr);
+char *non_perl_strdup (const char *s);
+char *non_perl_strndup (const char *s, size_t n);
 
 int xasprintf (char **ptr, const char *template, ...);
 
@@ -182,6 +203,7 @@ char *collapse_spaces (const char *text);
 char *parse_line_directive (char *line, int *retval, int *out_line_no);
 int is_content_empty (const ELEMENT *tree, int do_not_ignore_index_entries);
 
+STRING_LIST *new_string_list (void);
 void clear_strings_list (STRING_LIST *strings);
 void free_strings_list (STRING_LIST *strings);
 void destroy_strings_list (STRING_LIST *strings);
@@ -252,4 +274,10 @@ void initialize_option (OPTION *option, enum 
global_option_type type);
 void clear_option (OPTION *option);
 void free_option (OPTION *option);
 
+TARGET_FILENAME *new_target_filename (void);
+TARGET_CONTENTS_FILENAME *new_target_contents_filename (void);
+FILE_NAME_PATH *new_file_name_path (void);
+TARGET_DIRECTORY_FILENAME *new_target_directory_filename (void);
+FORMATTED_BUTTON_INFO *new_formatted_button_info (void);
+
 #endif
diff --git a/tp/maintain/regenerate_C_options_info.pl 
b/tp/maintain/regenerate_C_options_info.pl
index dd06adefbd..f7dc5cc63f 100755
--- a/tp/maintain/regenerate_C_options_info.pl
+++ b/tp/maintain/regenerate_C_options_info.pl
@@ -309,9 +309,9 @@ foreach my $category (sort(keys(%option_categories))) {
       # TODO the generated file includes perl headers.  The NOTE in
       # build_perl_info.c about not using malloc/free should be relevant for
       # the generated file.
-      print GET "      free (options->$option.string);
+      print GET "      non_perl_free (options->$option.string);
       if (SvOK (value))
-        options->$option.string = strdup (SvPV${SV_function_type}_nolen 
(value));
+        options->$option.string = non_perl_strdup 
(SvPV${SV_function_type}_nolen (value));
       else
         options->$option.string = 0;
     }\n";



reply via email to

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