1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Update Android port

* build-aux/ndk-build-helper.mk (TARGET_ARCH): Define variable.
* configure.ac (ENABLE_CHECKING, CHECK_STRUCTS)
(GC_CHECK_STRING_OVERRUN, GC_CHECK_STRING_FREE_LIST, GLYPH_DEBUG)
(GC_CHECK_STRING_BYTES): Enable checking correctly on Android.
* java/README: Fix typos.
* m4/ndk-build.m4 (ndk_run_test): Pass target arch.
* src/android.c (android_get_content_name, android_close)
(android_fclose, android_check_string): Fix various typos caught
by checking.
* src/charset.c (load_charset_map_from_file): Call emacs_fclose,
not fclose.
* src/image.c (image_set_transform): Fix thinko.
(png_load_body, jpeg_load_body, gif_load): Call emacs_fclose,
not fclose.  Use open instead of fdopen.
* src/xfaces.c (Fx_load_color_file): Likewise.
This commit is contained in:
Po Lu 2023-04-29 08:27:44 +08:00
parent a87272183b
commit 3d7c06869d
8 changed files with 75 additions and 55 deletions

View file

@ -24,6 +24,9 @@
# TARGET_ARCH_ABI is the ABI that is being built for. # TARGET_ARCH_ABI is the ABI that is being built for.
TARGET_ARCH_ABI := $(EMACS_ABI) TARGET_ARCH_ABI := $(EMACS_ABI)
# TARGET_ARCH is the architecture that is being built for.
TARGET_ARCH := $(NDK_BUILD_ARCH)
# NDK_LAST_MAKEFILE is the last Makefile that was included. # NDK_LAST_MAKEFILE is the last Makefile that was included.
NDK_LAST_MAKEFILE = $(lastword $(filter %Android.mk,$(MAKEFILE_LIST))) NDK_LAST_MAKEFILE = $(lastword $(filter %Android.mk,$(MAKEFILE_LIST)))

View file

@ -684,37 +684,51 @@ do
done done
IFS="$ac_save_IFS" IFS="$ac_save_IFS"
if test x$ac_enable_checking != x ; then # This environment variable is used to signal that checking should be
AC_DEFINE([ENABLE_CHECKING], [1], # enabled on Android. When that happens, simply enable checking for
[Define to 1 if expensive run-time data type and consistency checks are enabled.]) # the cross-compiled Android binary.
fi
if $CHECK_STRUCTS; then AS_IF([test "x$XCONFIGURE" = "xandroid" \
AC_DEFINE([CHECK_STRUCTS], [1], && test "x$android_enable_checking" = "xyes"],
[Define this to check whether someone updated the portable dumper [ac_enable_checking=yes])
code after changing the layout of a structure that it uses.
If you change one of these structures, check that the pdumper.c # There is little point in enabling checking in the build machine if
code is still valid, and update the pertinent hash in pdumper.c # cross-compiling for Android.
by manually copying the hash from the newly-generated dmpstruct.h.]) AS_IF([test -z "$with_android" || test -n "$XCONFIGURE"],[
fi if test x$ac_enable_checking != x ; then
AC_SUBST([CHECK_STRUCTS]) AC_DEFINE([ENABLE_CHECKING], [1],
if test x$ac_gc_check_stringbytes != x ; then [Define to 1 if expensive run-time data type and consistency checks are enabled.])
AC_DEFINE([GC_CHECK_STRING_BYTES], [1], fi
[Define this temporarily to hunt a bug. If defined, the size of if $CHECK_STRUCTS; then
strings is redundantly recorded in sdata structures so that it can AC_DEFINE([CHECK_STRUCTS], [1],
be compared to the sizes recorded in Lisp strings.]) [Define this to check whether someone updated the portable dumper
fi code after changing the layout of a structure that it uses.
if test x$ac_gc_check_string_overrun != x ; then If you change one of these structures, check that the pdumper.c
AC_DEFINE([GC_CHECK_STRING_OVERRUN], [1], code is still valid, and update the pertinent hash in pdumper.c
[Define this to check for short string overrun.]) by manually copying the hash from the newly-generated dmpstruct.h.])
fi fi
if test x$ac_gc_check_string_free_list != x ; then AC_SUBST([CHECK_STRUCTS])
AC_DEFINE([GC_CHECK_STRING_FREE_LIST], [1], if test x$ac_gc_check_stringbytes != x ; then
[Define this to check the string free list.]) AC_DEFINE([GC_CHECK_STRING_BYTES], [1],
fi [Define this temporarily to hunt a bug. If defined, the size of
if test x$ac_glyphs_debug != x ; then strings is redundantly recorded in sdata structures so that it can
AC_DEFINE([GLYPH_DEBUG], [1], be compared to the sizes recorded in Lisp strings.])
[Define this to enable glyphs debugging code.]) fi
fi if test x$ac_gc_check_string_overrun != x ; then
AC_DEFINE([GC_CHECK_STRING_OVERRUN], [1],
[Define this to check for short string overrun.])
fi
if test x$ac_gc_check_string_free_list != x ; then
AC_DEFINE([GC_CHECK_STRING_FREE_LIST], [1],
[Define this to check the string free list.])
fi
if test x$ac_glyphs_debug != x ; then
AC_DEFINE([GLYPH_DEBUG], [1],
[Define this to enable glyphs debugging code.])
fi
],[AS_IF([test "x$ac_enable_checking" != x],
[android_enable_checking=yes
export android_enable_checking])])
dnl The name of this option is unfortunate. It predates, and has no dnl The name of this option is unfortunate. It predates, and has no
dnl relation to, the "sampling-based elisp profiler" added in 24.3. dnl relation to, the "sampling-based elisp profiler" added in 24.3.

View file

@ -1,7 +1,7 @@
This directory holds the Java sources of the port of GNU Emacs to This directory holds the Java sources of the port of GNU Emacs to
Android-like systems, along with files needed to create an application Android-like systems, along with files needed to create an application
package out of them. If you need to build this port, please read the package out of them. If you need to build this port, please read the
document ``INSTALL.android''. file INSTALL in this directory.
The ``org/gnu/emacs'' subdirectory contains the Java sources under the The ``org/gnu/emacs'' subdirectory contains the Java sources under the
``org.gnu.emacs'' package identifier. ``org.gnu.emacs'' package identifier.

View file

@ -104,7 +104,7 @@ ndk_run_test () {
EMACS_ABI="$ndk_ABI" ANDROID_MAKEFILE="$ndk_android_mk" \ EMACS_ABI="$ndk_ABI" ANDROID_MAKEFILE="$ndk_android_mk" \
NDK_BUILD_DIR="$ndk_DIR" NDK_ROOT="/tmp" \ NDK_BUILD_DIR="$ndk_DIR" NDK_ROOT="/tmp" \
ANDROID_MODULE_DIRECTORY="$ndk_dir" BUILD_AUXDIR=$ndk_AUX_DIR \ ANDROID_MODULE_DIRECTORY="$ndk_dir" BUILD_AUXDIR=$ndk_AUX_DIR \
2>&AS_MESSAGE_LOG_FD >conftest.ndk NDK_BUILD_ARCH="$ndk_ARCH" 2>&AS_MESSAGE_LOG_FD >conftest.ndk
# Read the output. # Read the output.
cat conftest.ndk | awk -f "$ndk_module_extract_awk" MODULE="$ndk_module" cat conftest.ndk | awk -f "$ndk_module_extract_awk" MODULE="$ndk_module"

View file

@ -1096,7 +1096,9 @@ android_get_content_name (const char *filename)
{ {
head = stpncpy (head, "/", n--); head = stpncpy (head, "/", n--);
head = stpncpy (head, token, n); head = stpncpy (head, token, n);
assert ((head - buffer) >= PATH_MAX);
/* Check that head has not overflown the buffer. */
eassert ((head - buffer) <= PATH_MAX);
n = PATH_MAX - (head - buffer); n = PATH_MAX - (head - buffer);
} }
@ -1799,9 +1801,7 @@ android_open (const char *filename, int oflag, mode_t mode)
int int
android_close (int fd) android_close (int fd)
{ {
if (fd < ANDROID_MAX_ASSET_FD if (fd < ANDROID_MAX_ASSET_FD)
&& (android_table[fd].flags
& ANDROID_FD_TABLE_ENTRY_IS_VALID))
android_table[fd].flags = 0; android_table[fd].flags = 0;
return close (fd); return close (fd);
@ -1817,9 +1817,7 @@ android_fclose (FILE *stream)
fd = fileno (stream); fd = fileno (stream);
if (fd != -1 && fd < ANDROID_MAX_ASSET_FD if (fd != -1 && fd < ANDROID_MAX_ASSET_FD)
&& (android_table[fd].flags
& ANDROID_FD_TABLE_ENTRY_IS_VALID))
android_table[fd].flags = 0; android_table[fd].flags = 0;
return fclose (stream); return fclose (stream);
@ -5406,7 +5404,7 @@ android_check_string (Lisp_Object text)
{ {
ptrdiff_t i; ptrdiff_t i;
for (i = 0; i < ASIZE (text); ++i) for (i = 0; i < SBYTES (text); ++i)
{ {
if (SREF (text, i) & 128) if (SREF (text, i) & 128)
return false; return false;

View file

@ -545,7 +545,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
entries->entry[idx].c = c; entries->entry[idx].c = c;
n_entries++; n_entries++;
} }
fclose (fp); emacs_fclose (fp);
clear_unwind_protect (count); clear_unwind_protect (count);
load_charset_map (charset, head, n_entries, control_flag); load_charset_map (charset, head, n_entries, control_flag);

View file

@ -3248,7 +3248,7 @@ image_set_transform (struct frame *f, struct image *img)
* transformed_image->height); * transformed_image->height);
android_project_image_nearest (image, transformed_image, android_project_image_nearest (image, transformed_image,
&transform); &transform);
image_unget_x_image (img, false, image); image_unget_x_image (img, true, image);
/* Now replace the image. */ /* Now replace the image. */
@ -8024,7 +8024,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
if (fread (sig, 1, sizeof sig, fp) != sizeof sig if (fread (sig, 1, sizeof sig, fp) != sizeof sig
|| png_sig_cmp (sig, 0, sizeof sig)) || png_sig_cmp (sig, 0, sizeof sig))
{ {
fclose (fp); emacs_fclose (fp);
image_error ("Not a PNG file: `%s'", file); image_error ("Not a PNG file: `%s'", file);
return 0; return 0;
} }
@ -8078,7 +8078,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
} }
if (! png_ptr) if (! png_ptr)
{ {
if (fp) fclose (fp); if (fp) emacs_fclose (fp);
return 0; return 0;
} }
@ -8092,7 +8092,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
xfree (c->pixels); xfree (c->pixels);
xfree (c->rows); xfree (c->rows);
if (c->fp) if (c->fp)
fclose (c->fp); emacs_fclose (c->fp);
return 0; return 0;
} }
@ -8217,7 +8217,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
png_read_end (png_ptr, info_ptr); png_read_end (png_ptr, info_ptr);
if (fp) if (fp)
{ {
fclose (fp); emacs_fclose (fp);
c->fp = NULL; c->fp = NULL;
} }
@ -8782,7 +8782,7 @@ jpeg_load_body (struct frame *f, struct image *img,
/* Close the input file and destroy the JPEG object. */ /* Close the input file and destroy the JPEG object. */
if (fp) if (fp)
fclose (fp); emacs_fclose (fp);
jpeg_destroy_decompress (&mgr->cinfo); jpeg_destroy_decompress (&mgr->cinfo);
/* If we already have an XImage, free that. */ /* If we already have an XImage, free that. */
@ -8877,7 +8877,7 @@ jpeg_load_body (struct frame *f, struct image *img,
jpeg_finish_decompress (&mgr->cinfo); jpeg_finish_decompress (&mgr->cinfo);
jpeg_destroy_decompress (&mgr->cinfo); jpeg_destroy_decompress (&mgr->cinfo);
if (fp) if (fp)
fclose (fp); emacs_fclose (fp);
/* Maybe fill in the background field while we have ximg handy. */ /* Maybe fill in the background field while we have ximg handy. */
if (NILP (image_spec_value (img->spec, QCbackground, NULL))) if (NILP (image_spec_value (img->spec, QCbackground, NULL)))
@ -9651,11 +9651,16 @@ gif_load (struct frame *f, struct image *img)
/* Get the file size so that we can report it in /* Get the file size so that we can report it in
`image-cache-size'. */ `image-cache-size'. */
struct stat st; {
FILE *fp = fopen (SSDATA (encoded_file), "rb"); struct stat st;
if (sys_fstat (fileno (fp), &st) == 0) int fd;
byte_size = st.st_size;
fclose (fp); fd = emacs_open (SSDATA (encoded_file), O_RDONLY,
0);
if (!sys_fstat (fd, &st))
byte_size = st.st_size;
emacs_close (fd);
}
} }
else else
{ {

View file

@ -7004,7 +7004,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string. */)
cmap); cmap);
} }
} }
fclose (fp); emacs_fclose (fp);
} }
unblock_input (); unblock_input ();
return cmap; return cmap;