aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2023-08-07 21:23:28 -0700
committerPaul Eggert2023-08-07 21:26:36 -0700
commit85b6c150c8a356ebf3442fde2836364954aa938c (patch)
tree0ea86860bb95571114c9a14a45a77b34f123bac6 /src
parenta579739e2b3f3c7218b14a7e41b78e7ddbded06c (diff)
downloademacs-85b6c150c8a356ebf3442fde2836364954aa938c.tar.gz
emacs-85b6c150c8a356ebf3442fde2836364954aa938c.zip
Fix some emacs_fopen confusion
Problem reported by Po Lu in: https://lists.gnu.org/r/emacs-devel/2023-08/msg00195.html * src/comp.c (comp_hash_source_file, Fcomp__release_ctxt): * src/sysdep.c (get_up_time, procfs_ttyname, procfs_get_total_memory): Be more systematic about using emacs_fclose on streams that were opened with emacs_fopen or emacs_fdopen. Do this even if not Android, as this simplifies checking that it's done consistently. * src/lisp.h (emacs_fclose): If it’s just fclose, make it a macro rather than a function, to avoid confusing gcc -Wmismatched-dealloc. (emacs_fopen): Move decl here from sysstdio.h, because sysstdio.h is included from non-Emacs executables and emacs_fopen is good only inside Emacs. * src/sysdep.c (emacs_fclose): Define as a function only if Android.
Diffstat (limited to 'src')
-rw-r--r--src/comp.c4
-rw-r--r--src/lisp.h6
-rw-r--r--src/sysdep.c12
-rw-r--r--src/sysstdio.h2
4 files changed, 13 insertions, 11 deletions
diff --git a/src/comp.c b/src/comp.c
index 1bde4ae5821..b81a80b00f8 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -776,7 +776,7 @@ comp_hash_source_file (Lisp_Object filename)
776#else 776#else
777 int res = md5_stream (f, SSDATA (digest)); 777 int res = md5_stream (f, SSDATA (digest));
778#endif 778#endif
779 fclose (f); 779 emacs_fclose (f);
780 780
781 if (res) 781 if (res)
782 xsignal2 (Qfile_notify_error, build_string ("hashing failed"), filename); 782 xsignal2 (Qfile_notify_error, build_string ("hashing failed"), filename);
@@ -4749,7 +4749,7 @@ DEFUN ("comp--release-ctxt", Fcomp__release_ctxt, Scomp__release_ctxt,
4749 gcc_jit_context_release (comp.ctxt); 4749 gcc_jit_context_release (comp.ctxt);
4750 4750
4751 if (logfile) 4751 if (logfile)
4752 fclose (logfile); 4752 emacs_fclose (logfile);
4753 comp.ctxt = NULL; 4753 comp.ctxt = NULL;
4754 4754
4755 return Qt; 4755 return Qt;
diff --git a/src/lisp.h b/src/lisp.h
index 85de57b0b2f..2f26e5eddce 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -5086,9 +5086,15 @@ extern int emacs_open (const char *, int, int);
5086extern int emacs_open_noquit (const char *, int, int); 5086extern int emacs_open_noquit (const char *, int, int);
5087extern int emacs_pipe (int[2]); 5087extern int emacs_pipe (int[2]);
5088extern int emacs_close (int); 5088extern int emacs_close (int);
5089#if !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY)
5090# define emacs_fclose fclose
5091#else
5089extern int emacs_fclose (FILE *); 5092extern int emacs_fclose (FILE *);
5093#endif
5090extern FILE *emacs_fdopen (int, const char *) 5094extern FILE *emacs_fdopen (int, const char *)
5091 ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (emacs_fclose, 1); 5095 ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (emacs_fclose, 1);
5096extern FILE *emacs_fopen (char const *, char const *)
5097 ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (emacs_fclose, 1);
5092extern int emacs_unlink (const char *); 5098extern int emacs_unlink (const char *);
5093extern int emacs_symlink (const char *, const char *); 5099extern int emacs_symlink (const char *, const char *);
5094extern int emacs_rmdir (const char *); 5100extern int emacs_rmdir (const char *);
diff --git a/src/sysdep.c b/src/sysdep.c
index a995bc66741..0f8b70c8248 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2644,15 +2644,13 @@ emacs_fdopen (int fd, const char *mode)
2644 clear information associated with the FILE's file descriptor if 2644 clear information associated with the FILE's file descriptor if
2645 necessary. */ 2645 necessary. */
2646 2646
2647#if defined HAVE_ANDROID && !defined ANDROID_STUBIFY
2647int 2648int
2648emacs_fclose (FILE *stream) 2649emacs_fclose (FILE *stream)
2649{ 2650{
2650#if !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY)
2651 return fclose (stream);
2652#else
2653 return android_fclose (stream); 2651 return android_fclose (stream);
2654#endif
2655} 2652}
2653#endif
2656 2654
2657/* Wrappers around unlink, symlink, rename, renameat_noreplace, and 2655/* Wrappers around unlink, symlink, rename, renameat_noreplace, and
2658 rmdir. These operations handle asset and content directories on 2656 rmdir. These operations handle asset and content directories on
@@ -3492,7 +3490,7 @@ get_up_time (void)
3492 Lisp_Object subsec = Fcons (make_fixnum (upfrac), make_fixnum (hz)); 3490 Lisp_Object subsec = Fcons (make_fixnum (upfrac), make_fixnum (hz));
3493 up = Ftime_add (sec, subsec); 3491 up = Ftime_add (sec, subsec);
3494 } 3492 }
3495 fclose (fup); 3493 emacs_fclose (fup);
3496 } 3494 }
3497 unblock_input (); 3495 unblock_input ();
3498 3496
@@ -3540,7 +3538,7 @@ procfs_ttyname (int rdev)
3540 } 3538 }
3541 } 3539 }
3542 } 3540 }
3543 fclose (fdev); 3541 emacs_fclose (fdev);
3544 } 3542 }
3545 unblock_input (); 3543 unblock_input ();
3546 return build_string (name); 3544 return build_string (name);
@@ -3582,7 +3580,7 @@ procfs_get_total_memory (void)
3582 } 3580 }
3583 while (!done); 3581 while (!done);
3584 3582
3585 fclose (fmem); 3583 emacs_fclose (fmem);
3586 } 3584 }
3587 unblock_input (); 3585 unblock_input ();
3588 return retval; 3586 return retval;
diff --git a/src/sysstdio.h b/src/sysstdio.h
index 5a973c833cc..8e9e5bec86c 100644
--- a/src/sysstdio.h
+++ b/src/sysstdio.h
@@ -28,8 +28,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
28#include <attribute.h> 28#include <attribute.h>
29#include <unlocked-io.h> 29#include <unlocked-io.h>
30 30
31extern FILE *emacs_fopen (char const *, char const *)
32 ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (fclose, 1);
33extern void errputc (int); 31extern void errputc (int);
34extern void errwrite (void const *, ptrdiff_t); 32extern void errwrite (void const *, ptrdiff_t);
35extern void close_output_streams (void); 33extern void close_output_streams (void);