bug-texinfo
[Top][All Lists]
Advanced

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

how to mix or avoid perl and gnulib headers and object files together?


From: Patrice Dumas
Subject: how to mix or avoid perl and gnulib headers and object files together?
Date: Fri, 23 Feb 2024 17:33:53 +0100

Hello,

There are notes in C code warning against calling malloc or free and
functions potentially redefined by gnulib in files which include the
perl headers.  It may be related to the discussion here:

https://lists.gnu.org/archive/html/bug-texinfo/2022-10/msg00381.html

The NOTE is
  /* NOTE: Do not call 'malloc' or 'free' in any function called in this file.
     Since this file (build_perl_info.c) includes the Perl headers,
     we get the Perl redefinitions, which we do not want, as we don't use
     them throughout the rest of the program. */

  /* Can't use asprintf here, because it might come from Gnulib, and
     will then use malloc that is different from Perl's malloc, whereas
     free below is redirected to Perl's implementation.  This could
     cause crashes if the two malloc/free implementations were different.  */

There have been lots of reorganization of C code and some of these
issues may be obsolete, while new issues may have been introduced (by
me).


First a question.  Is the mixing of perl and gnulib functions bad at
compile time only or also at link time?  A somewhat related question
is can code like
#if defined _WIN32 && !defined __CYGWIN__
  #undef free
#endif
be removed if the C file does not include the gnulib headers but is
eventually part of a binary object including binary objects compiled
from gnulib code?

This is the case of tp/Texinfo/XS/convert/main/build_perl_info.c, which
is compiled and linked in libtexinfoxs.la, without any use of gnulib
CPPFLAGS.  The compilation of the other library, libtexinfo.la uses
gnulib.  Most XS objects link against both libtexinfoxs.la and
libtexinfo.la.


There are files which include the perl header and also include gnulib
headers and call functions such as strndup or free, for example
tp/Texinfo/XS/convert/build_html_perl_state.c
tp/Texinfo/XS/convert/get_html_perl_info.c

Will this setup lead to problems?  I do not think that it is possible in
general to avoid calling strdup/malloc/free in the file.  However it is
possible to add #undef or use wrappers or segregate some code.

Any guidance of what should and shouldn't be done on that matter?

-- 
Pat



reply via email to

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