Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
4e7bde8c
Commit
4e7bde8c
authored
9 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
unix/modjni: Factor out py2jvalue() function.
parent
9d6128ac
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
unix/modjni.c
+28
-19
28 additions, 19 deletions
unix/modjni.c
with
28 additions
and
19 deletions
unix/modjni.c
+
28
−
19
View file @
4e7bde8c
...
@@ -163,14 +163,13 @@ STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
...
@@ -163,14 +163,13 @@ STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
mp_printf
(
print
,
"<jmethod '%s'>"
,
qstr_str
(
self
->
name
));
mp_printf
(
print
,
"<jmethod '%s'>"
,
qstr_str
(
self
->
name
));
}
}
#define MATCH(s, static) ((!strncmp(s, static, sizeof(static) - 1)) && (s += sizeof(static) - 1))
#define
I
MATCH(s, static) ((!strncmp(s, static, sizeof(static) - 1)) && (s += sizeof(static) - 1))
#define CHECK_TYPE(java_type_name) \
#define CHECK_TYPE(java_type_name) \
if (strncmp(arg_types, java_type_name, sizeof(java_type_name) - 1) != 0) { \
if (strncmp(arg_type, java_type_name, sizeof(java_type_name) - 1) != 0) { \
found = false; \
return false; \
break; \
} \
} \
arg_type
s
+= sizeof(java_type_name) - 1;
arg_type += sizeof(java_type_name) - 1;
STATIC
const
char
*
strprev
(
const
char
*
s
,
char
c
)
{
STATIC
const
char
*
strprev
(
const
char
*
s
,
char
c
)
{
while
(
*
s
!=
c
)
{
while
(
*
s
!=
c
)
{
...
@@ -179,6 +178,27 @@ STATIC const char *strprev(const char *s, char c) {
...
@@ -179,6 +178,27 @@ STATIC const char *strprev(const char *s, char c) {
return
s
;
return
s
;
}
}
STATIC
bool
py2jvalue
(
const
char
**
jtypesig
,
mp_obj_t
arg
,
jvalue
*
out
)
{
const
char
*
arg_type
=
*
jtypesig
;
mp_obj_type_t
*
type
=
mp_obj_get_type
(
arg
);
if
(
type
==
&
mp_type_str
)
{
if
(
IMATCH
(
arg_type
,
"java.lang.String"
)
||
IMATCH
(
arg_type
,
"java.lang.Object"
))
{
out
->
l
=
JJ
(
NewStringUTF
,
mp_obj_str_get_str
(
arg
));
}
else
{
return
false
;
}
}
else
if
(
type
==
&
mp_type_int
)
{
CHECK_TYPE
(
"long"
);
out
->
j
=
mp_obj_get_int
(
arg
);
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"arg type not supported"
));
}
*
jtypesig
=
arg_type
;
return
true
;
}
STATIC
mp_obj_t
call_method
(
jobject
obj
,
const
char
*
name
,
jarray
methods
,
bool
is_constr
,
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
STATIC
mp_obj_t
call_method
(
jobject
obj
,
const
char
*
name
,
jarray
methods
,
bool
is_constr
,
mp_uint_t
n_args
,
const
mp_obj_t
*
args
)
{
jvalue
jargs
[
n_args
];
jvalue
jargs
[
n_args
];
// printf("methods=%p\n", methods);
// printf("methods=%p\n", methods);
...
@@ -209,20 +229,8 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool
...
@@ -209,20 +229,8 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool
bool
found
=
true
;
bool
found
=
true
;
for
(
int
i
=
0
;
i
<
n_args
;
i
++
)
{
for
(
int
i
=
0
;
i
<
n_args
;
i
++
)
{
mp_obj_t
arg
=
args
[
i
];
if
(
!
py2jvalue
(
&
arg_types
,
args
[
i
],
&
jargs
[
i
]))
{
mp_obj_type_t
*
type
=
mp_obj_get_type
(
arg
);
goto
next_method
;
if
(
type
==
&
mp_type_str
)
{
// CHECK_TYPE("java.lang.String");
if
(
MATCH
(
arg_types
,
"java.lang.String"
)
||
MATCH
(
arg_types
,
"java.lang.Object"
))
{
jargs
[
i
].
l
=
JJ
(
NewStringUTF
,
mp_obj_str_get_str
(
arg
));
}
else
{
found
=
false
;
}
}
else
if
(
type
==
&
mp_type_int
)
{
CHECK_TYPE
(
"long"
);
jargs
[
i
].
j
=
mp_obj_get_int
(
arg
);
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"arg type not supported"
));
}
}
if
(
*
arg_types
==
','
)
{
if
(
*
arg_types
==
','
)
{
...
@@ -269,6 +277,7 @@ ret_string:;
...
@@ -269,6 +277,7 @@ ret_string:;
}
}
}
}
next_method:
JJ
(
ReleaseStringUTFChars
,
name_o
,
decl
);
JJ
(
ReleaseStringUTFChars
,
name_o
,
decl
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment