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:
Paul Eggert 2023-08-07 21:23:28 -07:00
parent a579739e2b
commit 85b6c150c8
4 changed files with 13 additions and 11 deletions

View file

@ -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;