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
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
ed22e9ba
Commit
ed22e9ba
authored
9 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
unix/modjni: Move type analysis logic to new_jobject(), for reuse.
parent
dcbe936c
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
+15
-18
15 additions, 18 deletions
unix/modjni.c
with
15 additions
and
18 deletions
unix/modjni.c
+
15
−
18
View file @
ed22e9ba
...
...
@@ -205,12 +205,22 @@ STATIC const mp_obj_type_t jobject_type = {
};
STATIC
mp_obj_t
new_jobject
(
jobject
jo
)
{
if
(
JJ
(
IsInstanceOf
,
jo
,
String_class
))
{
const
char
*
s
=
JJ
(
GetStringUTFChars
,
jo
,
NULL
);
mp_obj_t
ret
=
mp_obj_new_str
(
s
,
strlen
(
s
),
false
);
JJ
(
ReleaseStringUTFChars
,
jo
,
s
);
return
ret
;
}
else
if
(
JJ
(
IsInstanceOf
,
jo
,
Class_class
))
{
return
new_jclass
(
jo
);
}
else
{
mp_obj_jobject_t
*
o
=
m_new_obj
(
mp_obj_jobject_t
);
o
->
base
.
type
=
&
jobject_type
;
o
->
obj
=
jo
;
return
o
;
}
}
// jmethod
...
...
@@ -272,31 +282,18 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) {
#define MATCH(s, static) (!strncmp(s, static, sizeof(static) - 1))
STATIC
mp_obj_t
jvalue2py
(
const
char
*
jtypesig
,
jobject
arg
)
{
const
char
*
org_jtype
=
jtypesig
;
mp_obj_t
ret
;
if
(
arg
==
NULL
||
MATCH
(
jtypesig
,
"void"
))
{
return
mp_const_none
;
}
else
if
(
MATCH
(
jtypesig
,
"boolean"
))
{
return
mp_obj_new_bool
((
bool
)
arg
);
}
else
if
(
MATCH
(
jtypesig
,
"int"
))
{
return
mp_obj_new_int
((
mp_int_t
)
arg
);
}
else
if
(
MATCH
(
jtypesig
,
"java.lang.String"
))
{
ret_string:
;
const
char
*
s
=
JJ
(
GetStringUTFChars
,
arg
,
NULL
);
ret
=
mp_obj_new_str
(
s
,
strlen
(
s
),
false
);
JJ
(
ReleaseStringUTFChars
,
arg
,
s
);
return
ret
;
}
else
{
while
(
*
jtypesig
!=
' '
&&
*
jtypesig
)
{
if
(
*
jtypesig
==
'.'
)
{
// Non-primitive, object type
if
(
JJ
(
IsInstanceOf
,
arg
,
String_class
))
{
goto
ret_string
;
}
else
if
(
JJ
(
IsInstanceOf
,
arg
,
Class_class
))
{
return
new_jclass
(
arg
);
}
else
{
return
new_jobject
(
arg
);
}
}
jtypesig
++
;
}
}
...
...
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