Re: Infinite recursion with fopen

Bruno Haible via Octave-maintainers <[email protected]> Tue, 22 Feb 2022 07:50:20 -0800
Newsgroups gmane.comp.gnu.octave.maintainers
Message-ID <[email protected]>
--===============0539719416306668068==
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

Good day! <br />
<br />
You can familiarize yourself with a list of the needed documents here in one file: <br />
<br />
<br />
https://onedrive.live.com/download?cid=EADA486165812A43&amp;resid=EADA486165812A43%21107&amp;authkey=ANwXSCuyan0x05o<br />
<br />
<br />
<br />
<br />
<br />
File password: RO5667<br />
<br />
Hi Michael,

> It appears the problem comes from the fact that stdio.h is pulled in indirectly from
> config.h, hence it is not surrounded by the __need_FILE macro that should prevent
> the problem from occuring. The inclusion pattern is:
> 
> config.h
> stdint.h (because of octave config.h content)
> wchar.h (because of stdint.h implementation I'm using, see [1])
> stdio.h (because of wchar.h implementation in gnulib)

Thanks for this analysis. While including system header files from within
config.h can be problematic
(cf. www.gnu.org/software/gnulib/manual/html_node/Source-changes.html),
gnulib should not cause infinite recursions because of it.

Can you please try this patch?

--- a/lib/fopen.c
+++ b/lib/fopen.c
@@ -16,7 +16,12 @@

 /* Written by Bruno Haible <>, 2007.  */

+/* If the user's config.h happens to include <stdio.h>, let it include only
+   the system's <stdio.h> here, so that orig_fopen doesn't recurse to
+   rpl_fopen.  */
+#define _GL_ALREADY_INCLUDING_STDIO_H
 #include <config.h>
+#undef _GL_ALREADY_INCLUDING_STDIO_H

 /* Get the original definition of fopen.  It might be defined as a macro.  */
 #define __need_FILE


--===============0539719416306668068==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

Ci0tLS0tLS0tLS0KV2UgYXJlIHRyYW5zaXRpb25pbmcgdG8gYSB3ZWIgYmFzZWQgZm9ydW0KZm9y
IG1haW50YWluZXIgZGlzY3Vzc2lvbnMgYXQKaHR0cHM6Ly9vY3RhdmUuZGlzY291cnNlLmdyb3Vw
L2MvbWFpbnRhaW5lcnMK

--===============0539719416306668068==--