mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-04 03:13:24 +00:00
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.
This commit is contained in:
parent
a579739e2b
commit
85b6c150c8
4 changed files with 13 additions and 11 deletions
|
@ -776,7 +776,7 @@ comp_hash_source_file (Lisp_Object filename)
|
|||
#else
|
||||
int res = md5_stream (f, SSDATA (digest));
|
||||
#endif
|
||||
fclose (f);
|
||||
emacs_fclose (f);
|
||||
|
||||
if (res)
|
||||
xsignal2 (Qfile_notify_error, build_string ("hashing failed"), filename);
|
||||
|
@ -4749,7 +4749,7 @@ DEFUN ("comp--release-ctxt", Fcomp__release_ctxt, Scomp__release_ctxt,
|
|||
gcc_jit_context_release (comp.ctxt);
|
||||
|
||||
if (logfile)
|
||||
fclose (logfile);
|
||||
emacs_fclose (logfile);
|
||||
comp.ctxt = NULL;
|
||||
|
||||
return Qt;
|
||||
|
|
|
@ -5086,9 +5086,15 @@ extern int emacs_open (const char *, int, int);
|
|||
extern int emacs_open_noquit (const char *, int, int);
|
||||
extern int emacs_pipe (int[2]);
|
||||
extern int emacs_close (int);
|
||||
#if !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY)
|
||||
# define emacs_fclose fclose
|
||||
#else
|
||||
extern int emacs_fclose (FILE *);
|
||||
#endif
|
||||
extern FILE *emacs_fdopen (int, const char *)
|
||||
ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (emacs_fclose, 1);
|
||||
extern FILE *emacs_fopen (char const *, char const *)
|
||||
ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (emacs_fclose, 1);
|
||||
extern int emacs_unlink (const char *);
|
||||
extern int emacs_symlink (const char *, const char *);
|
||||
extern int emacs_rmdir (const char *);
|
||||
|
|
12
src/sysdep.c
12
src/sysdep.c
|
@ -2644,15 +2644,13 @@ emacs_fdopen (int fd, const char *mode)
|
|||
clear information associated with the FILE's file descriptor if
|
||||
necessary. */
|
||||
|
||||
#if defined HAVE_ANDROID && !defined ANDROID_STUBIFY
|
||||
int
|
||||
emacs_fclose (FILE *stream)
|
||||
{
|
||||
#if !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY)
|
||||
return fclose (stream);
|
||||
#else
|
||||
return android_fclose (stream);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Wrappers around unlink, symlink, rename, renameat_noreplace, and
|
||||
rmdir. These operations handle asset and content directories on
|
||||
|
@ -3492,7 +3490,7 @@ get_up_time (void)
|
|||
Lisp_Object subsec = Fcons (make_fixnum (upfrac), make_fixnum (hz));
|
||||
up = Ftime_add (sec, subsec);
|
||||
}
|
||||
fclose (fup);
|
||||
emacs_fclose (fup);
|
||||
}
|
||||
unblock_input ();
|
||||
|
||||
|
@ -3540,7 +3538,7 @@ procfs_ttyname (int rdev)
|
|||
}
|
||||
}
|
||||
}
|
||||
fclose (fdev);
|
||||
emacs_fclose (fdev);
|
||||
}
|
||||
unblock_input ();
|
||||
return build_string (name);
|
||||
|
@ -3582,7 +3580,7 @@ procfs_get_total_memory (void)
|
|||
}
|
||||
while (!done);
|
||||
|
||||
fclose (fmem);
|
||||
emacs_fclose (fmem);
|
||||
}
|
||||
unblock_input ();
|
||||
return retval;
|
||||
|
|
|
@ -28,8 +28,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
|
|||
#include <attribute.h>
|
||||
#include <unlocked-io.h>
|
||||
|
||||
extern FILE *emacs_fopen (char const *, char const *)
|
||||
ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC (fclose, 1);
|
||||
extern void errputc (int);
|
||||
extern void errwrite (void const *, ptrdiff_t);
|
||||
extern void close_output_streams (void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue