diff options
author | Max Kellermann <max@musicpd.org> | 2018-08-28 13:27:28 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-08-28 13:27:28 +0200 |
commit | 35eca08d4829f16a8330939505be4fccb7de8c4b (patch) | |
tree | 86e2dfa3f38bef0b107c3823f35f58883a10e313 | |
parent | 7137ca375afdd258a24f2cb6a50bbac98c16d805 (diff) |
java/*: add `noexcept`
-rw-r--r-- | src/java/Class.hxx | 10 | ||||
-rw-r--r-- | src/java/Exception.hxx | 4 | ||||
-rw-r--r-- | src/java/File.cxx | 6 | ||||
-rw-r--r-- | src/java/File.hxx | 8 | ||||
-rw-r--r-- | src/java/Global.cxx | 4 | ||||
-rw-r--r-- | src/java/Global.hxx | 8 | ||||
-rw-r--r-- | src/java/Object.hxx | 5 | ||||
-rw-r--r-- | src/java/Ref.hxx | 38 | ||||
-rw-r--r-- | src/java/String.cxx | 2 | ||||
-rw-r--r-- | src/java/String.hxx | 9 |
10 files changed, 50 insertions, 44 deletions
diff --git a/src/java/Class.hxx b/src/java/Class.hxx index 82111f01e..083c64217 100644 --- a/src/java/Class.hxx +++ b/src/java/Class.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2018 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -41,10 +41,10 @@ namespace Java { */ class Class : public LocalRef<jclass> { public: - Class(JNIEnv *env, jclass cls) + Class(JNIEnv *env, jclass cls) noexcept :LocalRef<jclass>(env, cls) {} - Class(JNIEnv *env, const char *name) + Class(JNIEnv *env, const char *name) noexcept :LocalRef<jclass>(env, env->FindClass(name)) {} }; @@ -53,7 +53,7 @@ namespace Java { */ class TrivialClass : public TrivialRef<jclass> { public: - void Find(JNIEnv *env, const char *name) { + void Find(JNIEnv *env, const char *name) noexcept { assert(env != nullptr); assert(name != nullptr); @@ -64,7 +64,7 @@ namespace Java { env->DeleteLocalRef(cls); } - bool FindOptional(JNIEnv *env, const char *name) { + bool FindOptional(JNIEnv *env, const char *name) noexcept { assert(env != nullptr); assert(name != nullptr); diff --git a/src/java/Exception.hxx b/src/java/Exception.hxx index b4835e904..2db82dd1d 100644 --- a/src/java/Exception.hxx +++ b/src/java/Exception.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,7 +38,7 @@ namespace Java { * * @return true if an exception was found (and discarded) */ - static inline bool DiscardException(JNIEnv *env) { + static inline bool DiscardException(JNIEnv *env) noexcept { bool result = env->ExceptionCheck(); if (result) env->ExceptionClear(); diff --git a/src/java/File.cxx b/src/java/File.cxx index d79e861ab..20ee1b394 100644 --- a/src/java/File.cxx +++ b/src/java/File.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,7 +38,7 @@ jmethodID Java::File::getAbsolutePath_method; void -Java::File::Initialise(JNIEnv *env) +Java::File::Initialise(JNIEnv *env) noexcept { Class cls(env, "java/io/File"); @@ -47,7 +47,7 @@ Java::File::Initialise(JNIEnv *env) } AllocatedPath -Java::File::ToAbsolutePath(JNIEnv *env, jobject _file) +Java::File::ToAbsolutePath(JNIEnv *env, jobject _file) noexcept { assert(env != nullptr); assert(_file != nullptr); diff --git a/src/java/File.hxx b/src/java/File.hxx index 8822e5321..959283fbd 100644 --- a/src/java/File.hxx +++ b/src/java/File.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,10 +45,10 @@ namespace Java { public: gcc_nonnull_all - static void Initialise(JNIEnv *env); + static void Initialise(JNIEnv *env) noexcept; gcc_nonnull_all - static jstring getAbsolutePath(JNIEnv *env, jobject file) { + static jstring getAbsolutePath(JNIEnv *env, jobject file) noexcept { return (jstring)env->CallObjectMethod(file, getAbsolutePath_method); } @@ -59,7 +59,7 @@ namespace Java { */ gcc_pure gcc_nonnull_all static AllocatedPath ToAbsolutePath(JNIEnv *env, - jobject file); + jobject file) noexcept; }; } diff --git a/src/java/Global.cxx b/src/java/Global.cxx index 58aa9e422..1b7dbf4e8 100644 --- a/src/java/Global.cxx +++ b/src/java/Global.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,7 +32,7 @@ namespace Java { JavaVM *jvm; - void Init(JNIEnv *env) + void Init(JNIEnv *env) noexcept { env->GetJavaVM(&jvm); } diff --git a/src/java/Global.hxx b/src/java/Global.hxx index 9d341b36c..6f9e6b23b 100644 --- a/src/java/Global.hxx +++ b/src/java/Global.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,17 +37,17 @@ namespace Java { extern JavaVM *jvm; - void Init(JNIEnv *env); + void Init(JNIEnv *env) noexcept; static inline void - DetachCurrentThread() + DetachCurrentThread() noexcept { if (jvm != nullptr) jvm->DetachCurrentThread(); } static inline gcc_pure - JNIEnv *GetEnv() + JNIEnv *GetEnv() noexcept { JNIEnv *env; jvm->AttachCurrentThread(&env, nullptr); diff --git a/src/java/Object.hxx b/src/java/Object.hxx index 4e6220a48..f16354929 100644 --- a/src/java/Object.hxx +++ b/src/java/Object.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,7 +48,8 @@ namespace Java { */ Object() = default; - Object(JNIEnv *env, jobject obj):GlobalRef<jobject>(env, obj) {} + Object(JNIEnv *env, jobject obj) noexcept + :GlobalRef<jobject>(env, obj) {} }; } diff --git a/src/java/Ref.hxx b/src/java/Ref.hxx index a6f2d5d84..a80856a79 100644 --- a/src/java/Ref.hxx +++ b/src/java/Ref.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -49,23 +49,25 @@ namespace Java { /** * The local reference is obtained by the caller. */ - LocalRef(JNIEnv *_env, T _value):env(_env), value(_value) { + LocalRef(JNIEnv *_env, T _value) noexcept + :env(_env), value(_value) + { assert(env != nullptr); assert(value != nullptr); } - ~LocalRef() { + ~LocalRef() noexcept { env->DeleteLocalRef(value); } LocalRef(const LocalRef &other) = delete; LocalRef &operator=(const LocalRef &other) = delete; - T Get() const { + T Get() const noexcept { return value; } - operator T() const { + operator T() const noexcept { return value; } }; @@ -84,14 +86,16 @@ namespace Java { */ GlobalRef() = default; - GlobalRef(JNIEnv *env, T _value):value(_value) { + GlobalRef(JNIEnv *env, T _value) noexcept + :value(_value) + { assert(env != nullptr); assert(value != nullptr); value = (T)env->NewGlobalRef(value); } - ~GlobalRef() { + ~GlobalRef() noexcept { GetEnv()->DeleteGlobalRef(value); } @@ -102,17 +106,17 @@ namespace Java { * Sets the object, ignoring the previous value. This is only * allowed once after the default constructor was used. */ - void Set(JNIEnv *env, T _value) { + void Set(JNIEnv *env, T _value) noexcept { assert(_value != nullptr); value = (T)env->NewGlobalRef(_value); } - T Get() const { + T Get() const noexcept { return value; } - operator T() const { + operator T() const noexcept { return value; } }; @@ -129,12 +133,12 @@ namespace Java { T value; public: - constexpr TrivialRef() {}; + TrivialRef() = default; TrivialRef(const TrivialRef &other) = delete; TrivialRef &operator=(const TrivialRef &other) = delete; - bool IsDefined() const { + bool IsDefined() const noexcept { return value != nullptr; } @@ -142,7 +146,7 @@ namespace Java { * Obtain a global reference on the specified object and store it. * This object must not be set already. */ - void Set(JNIEnv *env, T _value) { + void Set(JNIEnv *env, T _value) noexcept { assert(value == nullptr); assert(_value != nullptr); @@ -152,7 +156,7 @@ namespace Java { /** * Release the global reference and clear this object. */ - void Clear(JNIEnv *env) { + void Clear(JNIEnv *env) noexcept { assert(value != nullptr); env->DeleteGlobalRef(value); @@ -163,16 +167,16 @@ namespace Java { * Release the global reference and clear this object. It is * allowed to call this method without ever calling Set(). */ - void ClearOptional(JNIEnv *env) { + void ClearOptional(JNIEnv *env) noexcept { if (value != nullptr) Clear(env); } - T Get() const { + T Get() const noexcept { return value; } - operator T() const { + operator T() const noexcept { return value; } }; diff --git a/src/java/String.cxx b/src/java/String.cxx index 238d9a16b..899f670c4 100644 --- a/src/java/String.cxx +++ b/src/java/String.cxx @@ -32,7 +32,7 @@ char * Java::String::CopyTo(JNIEnv *env, jstring value, - char *buffer, size_t max_size) + char *buffer, size_t max_size) noexcept { const char *p = env->GetStringUTFChars(value, nullptr); if (p == nullptr) diff --git a/src/java/String.hxx b/src/java/String.hxx index 725be69c4..6cf39b240 100644 --- a/src/java/String.hxx +++ b/src/java/String.hxx @@ -42,10 +42,10 @@ namespace Java { */ class String : public LocalRef<jstring> { public: - String(JNIEnv *env, jstring value) + String(JNIEnv *env, jstring value) noexcept :LocalRef<jstring>(env, value) {} - String(JNIEnv *_env, const char *_value) + String(JNIEnv *_env, const char *_value) noexcept :LocalRef<jstring>(_env, _env->NewStringUTF(_value)) {} /** @@ -56,7 +56,7 @@ namespace Java { * nullptr on error */ static char *CopyTo(JNIEnv *env, jstring value, - char *buffer, size_t max_size); + char *buffer, size_t max_size) noexcept; /** * Copy the value to the specified buffer. Truncates @@ -65,7 +65,8 @@ namespace Java { * @return a pointer to the terminating null byte, * nullptr on error */ - char *CopyTo(JNIEnv *env, char *buffer, size_t max_size) { + char *CopyTo(JNIEnv *env, + char *buffer, size_t max_size) noexcept { return CopyTo(env, Get(), buffer, max_size); } }; |