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

"JavaMathBigDecimal_initWithLong_(self, val)" declaration not available in "BigDecimal.h" causing compilation error #2323

Closed
parveen-bhatia opened this issue May 8, 2024 · 6 comments
Assignees

Comments

@parveen-bhatia
Copy link

Hi, we are using j2objc tag 3.0.0 and able to transpile our's project using it. But the generated code fails with below error as JavaMathBigDecimal_initWithLong_(self, val) method declaration is not available in j2objc/dist/include/java/math/BigDecimal.h. However with past versions, we saw that method declaration was available in BigDecimal.h.

error: call to undeclared function 'JavaMathBigDecimal_initWithLong_'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  JavaMathBigDecimal_initWithLong_(self, val);
  ^

.../BigNumber.m:983:3: note: did you mean 'JavaMathBigDecimal_initWithInt_'?
In file included from .../BigNumber.m:15:
In file included from .../BigNumber.h:22:
../../build/j2objc/dist/include/java/math/BigDecimal.h:1931:24: note: 'JavaMathBigDecimal_initWithInt_' declared here
FOUNDATION_EXPORT void JavaMathBigDecimal_initWithInt_(JavaMathBigDecimal *self, jint val);
                       ^
1 error generated.
** BUILD FAILED **

We are passing OTHER_CFLAGS = -Wno-error=implicit-function-declaration as a workaround for now. But please let us know if it can be fixed.

@parveen-bhatia parveen-bhatia changed the title "JavaMathBigDecimal_initWithLong_(self, val)" declaration not available in "j2objc/dist/include/java/math/BigDecimal.h" causing compilation error "JavaMathBigDecimal_initWithLong_(self, val)" declaration not available in "BigDecimal.h" causing compilation error May 8, 2024
@parveen-bhatia
Copy link
Author

Basically this method JavaMathBigDecimal_initWithLong_(j2objc/dist/include/java/math/BigDecimal.h) was available in previous versions of j2objc. But now this method is not declared/defined with latest master. But translator generates code which links to this method which doesn't exist. I was able to force compiler to pass through that using OTHER_CFLAGS = -Wno-error=implicit-function-declaration. But later found that linker is not able to find the symbol JavaMathBigDecimal_initWithLong_ as it doesn't exist. Looks a bug with j2objc tried both 3.0.0 and latest master. Is there any workaround to fix this ?

@tomball
Copy link
Collaborator

tomball commented May 14, 2024

You need to update the function name to JavaMathBigDecimal_initWithLongLong_, as the signature of this constructor was fixed in this commit.

The issue is that since j2objc defines a Java long as an iOS long long, and since Java number classes extend NSNumber, Java long parameters and return values need to match NSNumber's long long type. That commit updated the translator to generate the correct NSNumber constructor overrides, which caused the function name change.

If changing this function name in your project is difficult, it should be easy to #define JavaMathBigDecimal_initWithLong_ JavaMathBigDecimal_initWithLongLong_.

@tomball tomball closed this as completed May 14, 2024
@parveen-bhatia
Copy link
Author

@tomball thanks for the clarifications. Basically, we have class defined in java public class BigNumber extends BigDecimal implements Comparable<BigDecimal> and when it is transpiled to BigNumber.m then it generates code which refers to JavaMathBigDecimal_initWithLong_ method which is not defined. As this is the part of translated code not the original one. Do you think this is bug with the transpiler itself ?

@tomball
Copy link
Collaborator

tomball commented May 14, 2024

It may be a translator issue. In Java, how does your class invoke the BigNumber(long) constructor? The NumberMethodRewriter checks method declaration and class instance creation (constructor invocation) calls, but I can imagine that code making super method and constructor invocations wouldn't work.

If you can, please reply with the Java method snippet(s) that have the incorrect function call in their ObjC translation(s). Feel free to rename any proprietary names, as it's just the specific BigNumber constructor call(s) that need to be turned into regression tests.

@tomball tomball reopened this May 14, 2024
@tomball tomball self-assigned this May 14, 2024
@parveen-bhatia
Copy link
Author

yes, we are calling super, below is the snippet

public class BigNumber extends BigDecimal implements Comparable<BigDecimal> {
....
...

  public BigNumber(long val) {
    super(val);
  }

  public BigNumber(long val, MathContext mc) {
    super(val, mc);
  }
}

And translator is converting it to below snippet.

void XYZBigNumber_initWithLongLong_(XYZBigNumber *self, jlong val) {
  JavaMathBigDecimal_initWithLong_(self, val); // Causes error: call to undeclared function 'JavaMathBigDecimal_initWithLong_
}

XYZBigNumber *new_XYZBigNumber_initWithLongLong_(jlong val) {
  J2OBJC_NEW_IMPL(XYZBigNumber, initWithLongLong_, val)
}

XYZBigNumber *create_XYZBigNumber_initWithLongLong_(jlong val) {
  J2OBJC_CREATE_IMPL(XYZBigNumber, initWithLongLong_, val)
}

void XYZBigNumber_initWithLong_withJavaMathMathContext_(XYZBigNumber *self, jlong val, JavaMathMathContext *mc) {
  JavaMathBigDecimal_initWithLong_withJavaMathMathContext_(self, val, mc);
}

copybara-service bot pushed a commit that referenced this issue May 15, 2024
…er subclasses.

PiperOrigin-RevId: 633996893
copybara-service bot pushed a commit that referenced this issue May 15, 2024
…er subclasses.

PiperOrigin-RevId: 633996893
copybara-service bot pushed a commit that referenced this issue May 15, 2024
…er subclasses.

PiperOrigin-RevId: 634115851
@tomball
Copy link
Collaborator

tomball commented May 16, 2024

Fixed, thanks for the bug report.

@tomball tomball closed this as completed May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants