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

Mapping a struct return type #49

Open
castortech opened this issue Apr 30, 2018 · 4 comments
Open

Mapping a struct return type #49

castortech opened this issue Apr 30, 2018 · 4 comments

Comments

@castortech
Copy link
Contributor

I have a C function that returns a struct such as (and also other variants)

@JniClass(flags = { STRUCT, TYPEDEF })
public static class MDBX_aah_result_t {
	@JniField(cast = "MDBX_aah_t")
	public long aah;
	@JniField(cast = "MDBX_error_t")
	public int err;
}

That doesn't seem to be supported as per the following error:

#error Warning: bad return type. :public static final native JNI$MDBX_aah_result_t JNI.mdbx_aa_open(long,java.lang.String,long,long,long)

while the documentation states:

Structure and Union arguments/return values

So what is the best way to handle this. Was thinking of returning a byte array but concerned that since many member types can have varying size that would force me to capture many sizeof.

@acheong08
Copy link

@castortech Have you been able to work around this? Also hitting the same issue

@acheong08
Copy link

I just needed a coordinate (x,z). I did this unholy fuck:

long long getNearestStructure(int structType, int x, int z, uint64_t seed, int mc, int searchSize) {
...
return ((long long)bestPos.x << 32) | (bestPos.z & 0xffffffffL);
}
long result = getNearestStructure(structType, x, z, seed, mc_version, searchSize);
		if (result == 0) {
			return null;
		}
		Pos pos = new Pos();
		pos.x = (int) (result >> 32);
		pos.z = (int) (result & 0xFFFFFFFF);
		return pos;

@castortech
Copy link
Contributor Author

@castortech Have you been able to work around this? Also hitting the same issue

Hacked my way around it as well.

@gptlang
Copy link

gptlang commented Jan 15, 2024

Hacked my way around it as well.

May I ask how you did it? My workarounds don't feel very elegant

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

3 participants