iface.c 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <iface.h>
  4. void check (JNIEnv *);
  5. void check(JNIEnv *env)
  6. {
  7. if ((*env)->ExceptionCheck(env) != JNI_FALSE)
  8. {
  9. fprintf(stderr, "UNEXPECTED EXCEPTION\n");
  10. exit(-1);
  11. }
  12. }
  13. void
  14. Java_iface_doCalls (JNIEnv *env, jobject self, jobject other)
  15. {
  16. jclass iface_class, comparable_class;
  17. jmethodID iface_meth, comparable_meth;
  18. jvalue args[1];
  19. iface_class = (*env)->FindClass(env, "iface");
  20. check (env);
  21. comparable_class = (*env)->FindClass (env, "mycomp");
  22. check (env);
  23. iface_meth = (*env)->GetMethodID (env, iface_class, "compareTo",
  24. "(Ljava/lang/Object;)I");
  25. check (env);
  26. comparable_meth = (*env)->GetMethodID (env, comparable_class, "compareTo",
  27. "(Ljava/lang/Object;)I");
  28. check (env);
  29. args[0].l = other;
  30. (*env)->CallObjectMethodA (env, self, iface_meth, args);
  31. check (env);
  32. (*env)->CallObjectMethodA (env, self, comparable_meth, args);
  33. check (env);
  34. }