1
- #include " VMMain .h"
1
+ #include " NativeInterface .h"
2
2
#include < stdio.h>
3
3
#include < string.h>
4
4
#include < eosiolib_native/vm_api.h>
8
8
* Method: sayHello
9
9
* Signature: ()V
10
10
*/
11
- JNIEXPORT void JNICALL Java_VMMain_sayHello (JNIEnv *env, jobject jobj) {
11
+ JNIEXPORT void JNICALL Java_NativeInterface_sayHello (JNIEnv *env, jclass jobj) {
12
12
printf (" ++++++++++++++hello,world\n " );
13
13
}
14
14
15
- JNIEXPORT jbyteArray JNICALL Java_VMMain_get_1code
16
- (JNIEnv *env, jobject o, jlong account) {
15
+ JNIEXPORT jbyteArray JNICALL Java_NativeInterface_get_1code
16
+ (JNIEnv *env, jclass o, jlong account) {
17
+ printf (" ++++Java_NativeInterface_get_1code %llu %d\n " , account, sizeof (jlong));
17
18
if (get_vm_api ()->get_code_type (account) != VM_TYPE_JAVA) {
18
19
return NULL ;
19
20
}
20
21
size_t len = 0 ;
21
22
const char * code = get_vm_api ()->get_code (account, &len);
22
- jbyteArray jarr = env->NewByteArray (10 );
23
+ printf (" +++code size: %d \n " , len);
24
+ jbyteArray jarr = env->NewByteArray (len);
23
25
env->SetByteArrayRegion (jarr, 0 , len, (jbyte*)code);
24
26
return jarr;
25
27
}
@@ -29,8 +31,8 @@ JNIEXPORT jbyteArray JNICALL Java_VMMain_get_1code
29
31
* Method: is_account
30
32
* Signature: (J)Z
31
33
*/
32
- JNIEXPORT jboolean JNICALL Java_VMMain_is_1account
33
- (JNIEnv *, jobject , jlong account){
34
+ JNIEXPORT jboolean JNICALL Java_NativeInterface_is_1account
35
+ (JNIEnv *, jclass , jlong account){
34
36
return is_account ((uint64_t )account);
35
37
}
36
38
@@ -39,23 +41,28 @@ JNIEXPORT jboolean JNICALL Java_VMMain_is_1account
39
41
* Method: s2n
40
42
* Signature: (Ljava/lang/String;)J
41
43
*/
42
- JNIEXPORT jlong JNICALL Java_VMMain_s2n
43
- (JNIEnv *env, jobject o, jstring str){
44
+ JNIEXPORT jlong JNICALL Java_NativeInterface_s2n
45
+ (JNIEnv *env, jclass o, jstring str){
44
46
jboolean isCopy = false ;
45
47
const char * _str = env->GetStringUTFChars (str, &isCopy);
46
48
printf (" +++++++++isCopy %d %s\n " , isCopy, _str);
47
- return get_vm_api ()->string_to_uint64 (_str);
49
+ uint64_t n = get_vm_api ()->string_to_uint64 (_str);
50
+ if (isCopy) {
51
+ env->ReleaseStringUTFChars (str, _str);
52
+ }
53
+ return (jlong)n;
48
54
}
49
55
50
56
/*
51
57
* Class: VMMain
52
58
* Method: n2s
53
59
* Signature: (J)Ljava/lang/String;
54
60
*/
55
- JNIEXPORT jstring JNICALL Java_VMMain_n2s
56
- (JNIEnv *env, jobject o, jlong account){
61
+ JNIEXPORT jstring JNICALL Java_NativeInterface_n2s
62
+ (JNIEnv *env, jclass o, jlong account){
57
63
char name[32 ];
58
64
memset (name, 0 , sizeof (name));
65
+ printf (" +++++Java_NativeInterface_n2s %llu\n " , account);
59
66
get_vm_api ()->uint64_to_string (account, name, sizeof (name));
60
67
return env->NewStringUTF (name);
61
68
}
@@ -65,8 +72,8 @@ JNIEXPORT jstring JNICALL Java_VMMain_n2s
65
72
* Method: action_data_size
66
73
* Signature: ()I
67
74
*/
68
- JNIEXPORT jint JNICALL Java_VMMain_action_1data_1size
69
- (JNIEnv *env, jobject o){
75
+ JNIEXPORT jint JNICALL Java_NativeInterface_action_1data_1size
76
+ (JNIEnv *env, jclass o){
70
77
return action_data_size ();
71
78
}
72
79
@@ -75,13 +82,13 @@ JNIEXPORT jint JNICALL Java_VMMain_action_1data_1size
75
82
* Method: read_action_data
76
83
* Signature: ()[B
77
84
*/
78
- JNIEXPORT jbyteArray JNICALL Java_VMMain_read_1action_1data
79
- (JNIEnv *env, jobject ){
85
+ JNIEXPORT jbyteArray JNICALL Java_NativeInterface_read_1action_1data
86
+ (JNIEnv *env, jclass ){
80
87
uint32_t size = action_data_size ();
81
88
char *buf = new char [size];
82
89
read_action_data (buf, size);
83
90
84
- jbyteArray jarr = env->NewByteArray (10 );
91
+ jbyteArray jarr = env->NewByteArray (size );
85
92
env->SetByteArrayRegion (jarr, 0 , size, (jbyte*) buf);
86
93
delete[] buf;
87
94
return jarr;
@@ -92,8 +99,8 @@ JNIEXPORT jbyteArray JNICALL Java_VMMain_read_1action_1data
92
99
* Method: require_recipient
93
100
* Signature: (J)V
94
101
*/
95
- JNIEXPORT void JNICALL Java_VMMain_require_1recipient
96
- (JNIEnv *, jobject , jlong account){
102
+ JNIEXPORT void JNICALL Java_NativeInterface_require_1recipient
103
+ (JNIEnv *, jclass , jlong account){
97
104
require_recipient (account);
98
105
}
99
106
@@ -102,8 +109,8 @@ JNIEXPORT void JNICALL Java_VMMain_require_1recipient
102
109
* Method: require_auth
103
110
* Signature: (J)V
104
111
*/
105
- JNIEXPORT void JNICALL Java_VMMain_require_1auth
106
- (JNIEnv *, jobject , jlong account){
112
+ JNIEXPORT void JNICALL Java_NativeInterface_require_1auth
113
+ (JNIEnv *, jclass , jlong account){
107
114
require_auth (account);
108
115
}
109
116
@@ -112,8 +119,8 @@ JNIEXPORT void JNICALL Java_VMMain_require_1auth
112
119
* Method: db_store_i64
113
120
* Signature: (JJJJ[B)I
114
121
*/
115
- JNIEXPORT jint JNICALL Java_VMMain_db_1store_1i64
116
- (JNIEnv *env, jobject , jlong scope, jlong table_id, jlong payer, jlong id, jbyteArray jdata){
122
+ JNIEXPORT jint JNICALL Java_NativeInterface_db_1store_1i64
123
+ (JNIEnv *env, jclass , jlong scope, jlong table_id, jlong payer, jlong id, jbyteArray jdata){
117
124
118
125
jsize len = env->GetArrayLength (jdata);
119
126
char * buf = new char [len];
@@ -129,8 +136,8 @@ JNIEXPORT jint JNICALL Java_VMMain_db_1store_1i64
129
136
* Method: db_update_i64
130
137
* Signature: (I[B)V
131
138
*/
132
- JNIEXPORT void JNICALL Java_VMMain_db_1update_1i64
133
- (JNIEnv *env, jobject , jint itr, jlong payer, jbyteArray jdata){
139
+ JNIEXPORT void JNICALL Java_NativeInterface_db_1update_1i64
140
+ (JNIEnv *env, jclass , jint itr, jlong payer, jbyteArray jdata){
134
141
135
142
jsize len = env->GetArrayLength (jdata);
136
143
char * buf = new char [len];
@@ -145,8 +152,8 @@ JNIEXPORT void JNICALL Java_VMMain_db_1update_1i64
145
152
* Method: db_remove_i64
146
153
* Signature: (I)V
147
154
*/
148
- JNIEXPORT void JNICALL Java_VMMain_db_1remove_1i64
149
- (JNIEnv *, jobject , jint itr){
155
+ JNIEXPORT void JNICALL Java_NativeInterface_db_1remove_1i64
156
+ (JNIEnv *, jclass , jint itr){
150
157
db_remove_i64 (itr);
151
158
}
152
159
@@ -155,16 +162,16 @@ JNIEXPORT void JNICALL Java_VMMain_db_1remove_1i64
155
162
* Method: db_get_i64
156
163
* Signature: (I)[B
157
164
*/
158
- JNIEXPORT jbyteArray JNICALL Java_VMMain_db_1get_1i64
159
- (JNIEnv *env, jobject o, jint itr){
165
+ JNIEXPORT jbyteArray JNICALL Java_NativeInterface_db_1get_1i64
166
+ (JNIEnv *env, jclass o, jint itr){
160
167
int size = db_get_i64 (itr, nullptr , 0 );
161
168
if (size == 0 ) {
162
169
return NULL ;
163
170
}
164
171
char *buf = new char [size];
165
172
db_get_i64 (itr, buf, size);
166
173
167
- jbyteArray jarr = env->NewByteArray (10 );
174
+ jbyteArray jarr = env->NewByteArray (size );
168
175
env->SetByteArrayRegion (jarr, 0 , size, (jbyte*) buf);
169
176
return jarr;
170
177
}
@@ -174,8 +181,8 @@ JNIEXPORT jbyteArray JNICALL Java_VMMain_db_1get_1i64
174
181
* Method: db_next_i64
175
182
* Signature: (I)J
176
183
*/
177
- JNIEXPORT jlong JNICALL Java_VMMain_db_1next_1i64
178
- (JNIEnv *, jobject , jint itr){
184
+ JNIEXPORT jlong JNICALL Java_NativeInterface_db_1next_1i64
185
+ (JNIEnv *, jclass , jint itr){
179
186
uint64_t primary = 0 ;
180
187
return db_next_i64 (itr, &primary);
181
188
}
@@ -185,8 +192,8 @@ JNIEXPORT jlong JNICALL Java_VMMain_db_1next_1i64
185
192
* Method: db_previous_i64
186
193
* Signature: (I)J
187
194
*/
188
- JNIEXPORT jlong JNICALL Java_VMMain_db_1previous_1i64
189
- (JNIEnv *, jobject , jint itr){
195
+ JNIEXPORT jlong JNICALL Java_NativeInterface_db_1previous_1i64
196
+ (JNIEnv *, jclass , jint itr){
190
197
uint64_t primary = 0 ;
191
198
return db_previous_i64 (itr, &primary);
192
199
}
@@ -196,8 +203,8 @@ JNIEXPORT jlong JNICALL Java_VMMain_db_1previous_1i64
196
203
* Method: db_find_i64
197
204
* Signature: (JJJJ)I
198
205
*/
199
- JNIEXPORT jint JNICALL Java_VMMain_db_1find_1i64
200
- (JNIEnv *, jobject , jlong code, jlong scope, jlong table_id, jlong id){
206
+ JNIEXPORT jint JNICALL Java_NativeInterface_db_1find_1i64
207
+ (JNIEnv *, jclass , jlong code, jlong scope, jlong table_id, jlong id){
201
208
return db_find_i64 (code, scope, table_id, id);
202
209
}
203
210
@@ -206,8 +213,8 @@ JNIEXPORT jint JNICALL Java_VMMain_db_1find_1i64
206
213
* Method: db_lowerbound_i64
207
214
* Signature: (JJJJ)I
208
215
*/
209
- JNIEXPORT jint JNICALL Java_VMMain_db_1lowerbound_1i64
210
- (JNIEnv *, jobject , jlong code, jlong scope, jlong table_id, jlong id){
216
+ JNIEXPORT jint JNICALL Java_NativeInterface_db_1lowerbound_1i64
217
+ (JNIEnv *, jclass , jlong code, jlong scope, jlong table_id, jlong id){
211
218
return db_lowerbound_i64 (code, scope, table_id, id);
212
219
}
213
220
@@ -216,8 +223,8 @@ JNIEXPORT jint JNICALL Java_VMMain_db_1lowerbound_1i64
216
223
* Method: db_upperbound_i64
217
224
* Signature: (JJJJ)I
218
225
*/
219
- JNIEXPORT jint JNICALL Java_VMMain_db_1upperbound_1i64
220
- (JNIEnv *, jobject , jlong code, jlong scope, jlong table_id, jlong id){
226
+ JNIEXPORT jint JNICALL Java_NativeInterface_db_1upperbound_1i64
227
+ (JNIEnv *, jclass , jlong code, jlong scope, jlong table_id, jlong id){
221
228
return db_upperbound_i64 (code, scope, table_id, id);
222
229
}
223
230
@@ -226,7 +233,7 @@ JNIEXPORT jint JNICALL Java_VMMain_db_1upperbound_1i64
226
233
* Method: db_end_i64
227
234
* Signature: ()I
228
235
*/
229
- JNIEXPORT jint JNICALL Java_VMMain_db_1end_1i64
230
- (JNIEnv *, jobject , jlong code, jlong scope, jlong table_id){
236
+ JNIEXPORT jint JNICALL Java_NativeInterface_db_1end_1i64
237
+ (JNIEnv *, jclass , jlong code, jlong scope, jlong table_id){
231
238
return db_end_i64 (code, scope, table_id);
232
239
}
0 commit comments