java -> pascal parameter transfer is not working when using void (procedure) type on Android x86
Original Reporter info from Mantis: simonsayz
-
Reporter name: simon,choi
Original Reporter info from Mantis: simonsayz
- Reporter name: simon,choi
Description:
Android Arm is working correctly.
Android x86 is not working when using void type
On Java
int rst = tester.pTest(123); // OK
tester.pTest2(345); // Not OK
On Pascal
Function pTest (env: PJNIEnv; this: jobject; value : integer): integer; cdecl;
begin
// value is 123
end;
Procedure pTest2 (env: PJNIEnv; this: jobject; value : integer);
begin
// Error
// Always "zero"
end;
Steps to reproduce:
//-------------------------------------------------------------
// x86.pas
//-------------------------------------------------------------
library x86;
{$mode delphi}
{$packrecords c}
{$R *.res}
uses
sysutils,classes,math,ctypes,jni;
const
cJavaClass = 'com/kredix/Tester';
cFuncPrefix = 'Java_com_kredix_Tester_';
// pascal call java ----------------------------------------------------------
Function jTest (env:PJNIEnv;this:jobject;value : integer) : integer;
Const
_cFuncName = 'jTest';
_cFuncSig = '(I)I';
Var
_jClass : jClass;
_jMethod : jMethodID;
_jParam : jValue;
begin
_jClass := env^.FindClass ( env, cJavaClass );
_jMethod := env^.GetMethodID( env, _jClass, _cFuncName, _cFuncSig);
_jParam.i := value;
Result := env^.CallIntMethodA(env,this,_jMethod,@_jParam);
end;
// java call pascal -----------------------------------------------------------
Function pTest (env: PJNIEnv; this: jobject; value : integer): integer; cdecl;
Var
p2j : integer;
begin
p2j := jTest(env,this,value); // result := result + 100;
result := p2j+1; // (123 + 100) + 1 = 224
end;
// java call pascal -----------------------------------------------------------
Procedure pTest2 (env: PJNIEnv; this: jobject; value : integer);
begin
// Error --------------------------------------------------------------------
// Andoid Arm OK, But Android X86 always received value = "0"
//
// When x86 ,
// Java-> Pascal (Void Type: Procedure) : Parameter(s) is always zero
// But Function type is OK
// --------------------------------------------------------------------------
If value = 0 then Halt;
end;
exports
JNI_OnLoad name 'JNI_OnLoad',
JNI_OnUnload name 'JNI_OnUnload',
pTest name cFuncPrefix+'pTest',
pTest2 name cFuncPrefix+'pTest2';
end.
//-------------------------------------------------------------
// App.java
//-------------------------------------------------------------
package com.kredix;
import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class App extends Activity {
public Tester tester;
@Override
public void onCreate(Bundle savedInstanceState) {
//
super.onCreate(savedInstanceState);
//
tester = new Tester();
RelativeLayout appLayout = new RelativeLayout(this);
this.setContentView(appLayout);
// Create Button , W,H 400,100
RelativeLayout.LayoutParams lparams1 = new RelativeLayout.LayoutParams(400,100);
lparams1.setMargins ( 50, 50,0,0); // L,T,
Button button1 = new Button(this);
button1.setText("test1");
appLayout.addView(button1,lparams1);
// Button Event
OnClickListener onClickListener1 = new OnClickListener() {
public void onClick(View view) {
//---------------------------------------------------------------------
// Error
//---------------------------------------------------------------------
// Parameter Can't transfer to Pascal from Java (On X86),
// Always zero, But On Arm CPU, It's ok
//---------------------------------------------------------------------
tester.pTest2(345);
// It works x86,arm on android
int rst = tester.pTest(123);
String str = Integer.toString(rst);
Toast.makeText(getApplicationContext(),str, Toast.LENGTH_SHORT).show();
}
};
button1.setOnClickListener(onClickListener1);
}
}
//-------------------------------------------------------------
// Testeer.java
//-------------------------------------------------------------
// http://blog.naver.com/simonsayz
// simonsayz@naver.com
package com.kredix;
import android.app.Activity;
import android.util.Log;
import android.graphics.Bitmap;
public class Tester {
// Load Library
static { System.loadLibrary("tester"); }
public native int pTest (int value);
public native pTest2(int value);
public int jTest (int value ) { return(value + 100); }
}
Mantis conversion info:
- Mantis ID: 25445
- OS: android
- OS Build: 4.3
- Build: trunk revision 26257
- Platform: i386
- Version: 2.7.1