Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refined Generator.java to fix a flaky error #784

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Fix `Generator` flakiness caused by calls to `Class.getDeclaredMethods()` ([pull #784](https://github.com/bytedeco/javacpp/pull/784))
* Add minimal mappings for `std::chrono` from C++11 ([pull #766](https://github.com/bytedeco/javacpp/pull/766))
* Let `Parser` annotate Java constructors with `@Deprecated` when appropriate ([pull #757](https://github.com/bytedeco/javacpp/pull/757))
* Add to `InfoMap.defaults` more names that are reserved in Java, but not in C++ ([pull #757](https://github.com/bytedeco/javacpp/pull/757))
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/bytedeco/javacpp/tools/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ boolean methods(Class<?> cls) {
c = c.getSuperclass();
}
boolean[] callbackAllocators = new boolean[methods.length];
Method[] functionMethods = functionMethods(cls, callbackAllocators);
Method[] functionMethods = functionMethods(cls, methods, callbackAllocators);
boolean firstCallback = true;
for (int i = 0; i < methods.length; i++) {
if (!Loader.checkPlatform(methods[i].getAnnotation(Platform.class), properties)) {
Expand Down Expand Up @@ -3636,11 +3636,10 @@ static String functionClassName(Class<?> cls) {
return name != null ? name.value()[0] : "JavaCPP_" + mangle(cls.getName());
}

static Method[] functionMethods(Class<?> cls, boolean[] callbackAllocators) {
static Method[] functionMethods(Class<?> cls, Method[] methods, boolean[] callbackAllocators) {
if (!FunctionPointer.class.isAssignableFrom(cls)) {
return null;
}
Method[] methods = cls.getDeclaredMethods();
Method[] functionMethods = new Method[3];
for (int i = 0; i < methods.length; i++) {
String methodName = methods[i].getName();
Expand Down Expand Up @@ -4386,7 +4385,7 @@ String[] cppTypeName(Class<?> type, Annotation[] annotations) {
} else if (type.isPrimitive()) {
prefix = type.getName();
} else if (FunctionPointer.class.isAssignableFrom(type)) {
Method[] functionMethods = functionMethods(type, null);
Method[] functionMethods = functionMethods(type, type.getDeclaredMethods(), null);
saudet marked this conversation as resolved.
Show resolved Hide resolved
String[] prefixSuffix = cppFunctionTypeName(functionMethods);
if (prefixSuffix != null) {
return prefixSuffix;
Expand Down
Loading