forked from zplizzi/tensorflow-fast-rcnn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java: Bugfix: Avoid segfault when a Tensor is used after being close()d.
There were two bugs: - The string constant kNullPointerException had a typo in its value - The scalar value accessors weren't checking for a valid handle Fixed those, added tests and moved the utility function throwException to its own file since I plan to use that in JNI files for the other Java classes in the future. Another step in the journey that is zplizzi#5 Change: 141091613
- Loading branch information
1 parent
bdfb8ff
commit 502675b
Showing
5 changed files
with
98 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include <stdarg.h> | ||
|
||
#include "tensorflow/c/c_api.h" | ||
#include "tensorflow/java/src/main/native/exception_jni.h" | ||
|
||
const char kIllegalArgumentException[] = "java/lang/IllegalArgumentException"; | ||
const char kIllegalStateException[] = "java/lang/IllegalStateException"; | ||
const char kNullPointerException[] = "java/lang/NullPointerException"; | ||
|
||
void throwException(JNIEnv* env, const char* clazz, const char* fmt, ...) { | ||
va_list args; | ||
va_start(args, fmt); | ||
char* message = nullptr; | ||
if (vasprintf(&message, fmt, args) >= 0) { | ||
env->ThrowNew(env->FindClass(clazz), message); | ||
} else { | ||
env->ThrowNew(env->FindClass(clazz), ""); | ||
} | ||
va_end(args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#ifndef TENSORFLOW_JAVA_EXCEPTION_JNI_H_ | ||
#define TENSORFLOW_JAVA_EXCEPTION_JNI_H_ | ||
|
||
#include <jni.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern const char kIllegalArgumentException[]; | ||
extern const char kIllegalStateException[]; | ||
extern const char kNullPointerException[]; | ||
|
||
void throwException(JNIEnv* env, const char* clazz, const char* fmt, ...); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif // __cplusplus | ||
#endif // TENSORFLOW_JAVA_EXCEPTION_JNI_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters