aboutsummaryrefslogtreecommitdiffstats
path: root/src/android.c
diff options
context:
space:
mode:
authorPo Lu2023-06-27 15:33:05 +0800
committerPo Lu2023-06-27 15:33:05 +0800
commit3079e15f546de2c4b36259521eb960bfd248603e (patch)
treefcd5682e69f8fd77f6a53fba74507caa9315fbdd /src/android.c
parent32352bec968ddcde7d1421f35a05ce6d1e42c348 (diff)
downloademacs-3079e15f546de2c4b36259521eb960bfd248603e.tar.gz
emacs-3079e15f546de2c4b36259521eb960bfd248603e.zip
Update Android port
* src/android.c (android_exception_check) (android_exception_check_1) (android_exception_check_2) (android_exception_check_nonnull) (android_exception_check_nonnull_1): Tell the compiler to expect that the object is non-NULL, or that no exception has been thrown.
Diffstat (limited to 'src/android.c')
-rw-r--r--src/android.c80
1 files changed, 43 insertions, 37 deletions
diff --git a/src/android.c b/src/android.c
index e45aa82fc3c..da5e8da3be1 100644
--- a/src/android.c
+++ b/src/android.c
@@ -6565,8 +6565,8 @@ android_build_jstring (const char *text)
6565 6565
6566 Typically, you use these functions by calling them immediately 6566 Typically, you use these functions by calling them immediately
6567 after a JNI function which allocates memory, passing it any local 6567 after a JNI function which allocates memory, passing it any local
6568 references that are already valid but are not used after leaving 6568 references that are already valid but should be deleted after
6569 the current scope. For example, to allocate foo and then make 6569 leaving the current scope. For example, to allocate foo, make
6570 global_foo its global reference, and then release foo, you write: 6570 global_foo its global reference, and then release foo, you write:
6571 6571
6572 jobject foo, global_foo; 6572 jobject foo, global_foo;
@@ -6585,22 +6585,28 @@ android_build_jstring (const char *text)
6585 if global_foo cannot be allocated, and after the global reference 6585 if global_foo cannot be allocated, and after the global reference
6586 is created. */ 6586 is created. */
6587 6587
6588#if __GNUC__ >= 3
6589#define likely(cond) __builtin_expect ((cond), 1)
6590#else /* __GNUC__ < 3 */
6591#define likely(cond) (cond)
6592#endif /* __GNUC__ >= 3 */
6593
6588/* Check for JNI exceptions and call memory_full in that 6594/* Check for JNI exceptions and call memory_full in that
6589 situation. */ 6595 situation. */
6590 6596
6591void 6597void
6592android_exception_check (void) 6598android_exception_check (void)
6593{ 6599{
6594 if ((*android_java_env)->ExceptionCheck (android_java_env)) 6600 if (likely (!(*android_java_env)->ExceptionCheck (android_java_env)))
6595 { 6601 return;
6596 __android_log_print (ANDROID_LOG_WARN, __func__, 6602
6597 "Possible out of memory error. " 6603 __android_log_print (ANDROID_LOG_WARN, __func__,
6598 " The Java exception follows: "); 6604 "Possible out of memory error. "
6599 /* Describe exactly what went wrong. */ 6605 " The Java exception follows: ");
6600 (*android_java_env)->ExceptionDescribe (android_java_env); 6606 /* Describe exactly what went wrong. */
6601 (*android_java_env)->ExceptionClear (android_java_env); 6607 (*android_java_env)->ExceptionDescribe (android_java_env);
6602 memory_full (0); 6608 (*android_java_env)->ExceptionClear (android_java_env);
6603 } 6609 memory_full (0);
6604} 6610}
6605 6611
6606/* Check for JNI exceptions. If there is one such exception, clear 6612/* Check for JNI exceptions. If there is one such exception, clear
@@ -6610,17 +6616,17 @@ android_exception_check (void)
6610void 6616void
6611android_exception_check_1 (jobject object) 6617android_exception_check_1 (jobject object)
6612{ 6618{
6613 if ((*android_java_env)->ExceptionCheck (android_java_env)) 6619 if (likely (!(*android_java_env)->ExceptionCheck (android_java_env)))
6614 { 6620 return;
6615 __android_log_print (ANDROID_LOG_WARN, __func__, 6621
6616 "Possible out of memory error. " 6622 __android_log_print (ANDROID_LOG_WARN, __func__,
6617 " The Java exception follows: "); 6623 "Possible out of memory error. "
6618 /* Describe exactly what went wrong. */ 6624 " The Java exception follows: ");
6619 (*android_java_env)->ExceptionDescribe (android_java_env); 6625 /* Describe exactly what went wrong. */
6620 (*android_java_env)->ExceptionClear (android_java_env); 6626 (*android_java_env)->ExceptionDescribe (android_java_env);
6621 ANDROID_DELETE_LOCAL_REF (object); 6627 (*android_java_env)->ExceptionClear (android_java_env);
6622 memory_full (0); 6628 ANDROID_DELETE_LOCAL_REF (object);
6623 } 6629 memory_full (0);
6624} 6630}
6625 6631
6626/* Like android_exception_check_1, except it takes more than one local 6632/* Like android_exception_check_1, except it takes more than one local
@@ -6629,18 +6635,18 @@ android_exception_check_1 (jobject object)
6629void 6635void
6630android_exception_check_2 (jobject object, jobject object1) 6636android_exception_check_2 (jobject object, jobject object1)
6631{ 6637{
6632 if ((*android_java_env)->ExceptionCheck (android_java_env)) 6638 if (likely (!(*android_java_env)->ExceptionCheck (android_java_env)))
6633 { 6639 return;
6634 __android_log_print (ANDROID_LOG_WARN, __func__, 6640
6635 "Possible out of memory error. " 6641 __android_log_print (ANDROID_LOG_WARN, __func__,
6636 " The Java exception follows: "); 6642 "Possible out of memory error. "
6637 /* Describe exactly what went wrong. */ 6643 " The Java exception follows: ");
6638 (*android_java_env)->ExceptionDescribe (android_java_env); 6644 /* Describe exactly what went wrong. */
6639 (*android_java_env)->ExceptionClear (android_java_env); 6645 (*android_java_env)->ExceptionDescribe (android_java_env);
6640 ANDROID_DELETE_LOCAL_REF (object); 6646 (*android_java_env)->ExceptionClear (android_java_env);
6641 ANDROID_DELETE_LOCAL_REF (object1); 6647 ANDROID_DELETE_LOCAL_REF (object);
6642 memory_full (0); 6648 ANDROID_DELETE_LOCAL_REF (object1);
6643 } 6649 memory_full (0);
6644} 6650}
6645 6651
6646/* Check for JNI problems based on the value of OBJECT. 6652/* Check for JNI problems based on the value of OBJECT.
@@ -6655,7 +6661,7 @@ android_exception_check_2 (jobject object, jobject object1)
6655void 6661void
6656android_exception_check_nonnull (void *object, jobject object1) 6662android_exception_check_nonnull (void *object, jobject object1)
6657{ 6663{
6658 if (object) 6664 if (likely (object != NULL))
6659 return; 6665 return;
6660 6666
6661 if (object1) 6667 if (object1)
@@ -6673,7 +6679,7 @@ void
6673android_exception_check_nonnull_1 (void *object, jobject object1, 6679android_exception_check_nonnull_1 (void *object, jobject object1,
6674 jobject object2) 6680 jobject object2)
6675{ 6681{
6676 if (object) 6682 if (likely (object != NULL))
6677 return; 6683 return;
6678 6684
6679 if (object1) 6685 if (object1)