weikipeng / javacpp

Automatically exported from code.google.com/p/javacpp
GNU General Public License v2.0
0 stars 0 forks source link

Generated jini-cpp file Syntax Errors #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Happens every time. Transcript:

[bill@lab-guard1-4600 jni]$ javac -cp javacpp.jar Tps.java
[bill@lab-guard1-4600 jni]$ java -jar javacpp.jar Tps
Generating source file: /home/bill/jni/jniTps.cpp
Building library file: /home/bill/jni/linux-x86/libjniTps.so
g++ -I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/include 
-I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/include/linux 
/home/bill/jni/jniTps.cpp -march=i686 -m32 -Wall -O3 -fPIC -shared -s -o 
/home/bill/jni/linux-x86/libjniTps.so 
/home/bill/jni/jniTps.cpp: In function ‘jint JNI_OnLoad(JavaVM*, void*)’:
/home/bill/jni/jniTps.cpp:163: warning: dereferencing type-punned pointer will 
break strict-aliasing rules
/home/bill/jni/jniTps.cpp: In function ‘void JNI_OnUnload(JavaVM*, void*)’:
/home/bill/jni/jniTps.cpp:250: warning: dereferencing type-punned pointer will 
break strict-aliasing rules
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_init(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:961: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_cleanup(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:994: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_startLog(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:1011: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_stopLog(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:1028: error: expected ‘,’ or ‘;’ before 
‘)’ token
/home/bill/jni/jniTps.cpp: In function ‘jboolean 
Java_Tps_00024HmiToTps_closeLog(JNIEnv*, _jobject*)’:
/home/bill/jni/jniTps.cpp:1045: error: expected ‘,’ or ‘;’ before 
‘)’ token

What is the expected output? What do you see instead?

A clean cpp file that I don't have to remove parenthesis from to get g++ to 
work.

What version of the product are you using? On what operating system?

rhel kernel 2.6.18-308.1.1.el5  on x86 32-bit single cpu
OpenJDK 1.6.0_22
javacpp 20120512

Please provide any additional information below.

Once the cpp is fixed the Java -> cpp works perfectly.

Original issue reported on code.google.com by wtrib...@gmail.com on 24 May 2012 at 1:19

Attachments:

GoogleCodeExporter commented 9 years ago
Ah, I see... We shouldn't use @ByVal, etc. on primitive types (remove that and 
it will fix your errors), but using them shouldn't produce incorrect code 
either. I'll be fixing this, thanks for reporting!

Original comment by samuel.a...@gmail.com on 24 May 2012 at 1:26

GoogleCodeExporter commented 9 years ago
I was just aping the example, and I did not want to make things complicated by 
passing references. I will gladly remove the @ByVal stuff! Thanks for getting 
back to me so fast.

Original comment by wtrib...@gmail.com on 24 May 2012 at 6:16

GoogleCodeExporter commented 9 years ago
Ok, I've fixed that in the latest release! Primitives types can't be passed by 
reference since the Java language doesn't support that: They are always by 
value. To map C++ references, we have to use a Pointer subclass (e.g.: 
BoolPointer if your bool were returned by reference) or an array type (but 
since those require their capacity to be known before creating them and because 
they can't be mapped to native memory, they don't always work), annotated with 
@ByRef obviously.

Anyway, the fact that you could get this running the way you wanted it just by 
"aping" the examples in the README.txt file is a good indication of how 
effective this approach can be. Great to hear that!

Original comment by samuel.a...@gmail.com on 27 May 2012 at 12:27