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

java.lang.RuntimeException: Unaligned pointer access #72

Open
rhz opened this issue Jul 14, 2015 · 0 comments
Open

java.lang.RuntimeException: Unaligned pointer access #72

rhz opened this issue Jul 14, 2015 · 0 comments

Comments

@rhz
Copy link

rhz commented Jul 14, 2015

Hi, I get this error when trying to access a field of a pointer to a struct returned from C function call. The C code is the following:

#include <stdio.h>

typedef struct S {
  int a;
  double b;
} S;

S* printHello(S* s) {
  printf("Hello!\n");
  return(s);
}

I'm compiling it with gcc -Wall -g -fPIC -c f.c -o f.o and then gcc -shared -o libf.so f.o. To put it in the the jar I do java -jar ~/src/java/JNAerator/jnaerator/target/jnaerator-0.13-SNAPSHOT-shaded.jar -runtime BridJ -mode Jar f.c libf.so. Gcc version is 5.1.0.
The Scala code I'm calling the function from is:

package test

object Test {
  def main(args: Array[String]): Unit = {
    import functions._
    import org.bridj.Pointer._
    val s = (new S).a(1).b(2.0)
    println(s.a)
    println(s.b)
    println()
    val p = pointerTo(s)
    println(p.get.a)
    println(p.get.b)
    println()
    val q = FunctionsLibrary.printHello(p)
    println(q.get.a)
    println(q.get.b)
  }
}

The error is raised by line println(q.get.a). If I change the code to print the values in s it doesn't print them for some reason. Also, if I return the int or double in s, I get random values.

Cheers,
Ricardo

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

1 participant