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
f22be4eb
Commit
f22be4eb
authored
9 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
unix/modjni: jobject.__str__/__repr__: Return Java .toString() value.
parent
34f26ea8
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
+16
-7
16 additions, 7 deletions
unix/modjni.c
with
16 additions
and
7 deletions
unix/modjni.c
+
16
−
7
View file @
f22be4eb
...
...
@@ -48,7 +48,7 @@ static jmethodID Class_getField_mid;
static
jmethodID
Class_getMethods_mid
;
static
jmethodID
Class_getConstructors_mid
;
static
jmethodID
Method_getName_mid
;
static
jmethodID
Method
_toString_mid
;
static
jmethodID
Object
_toString_mid
;
static
jclass
List_class
;
static
jmethodID
List_get_mid
;
...
...
@@ -180,10 +180,17 @@ STATIC mp_obj_t new_jclass(jclass jc) {
// jobject
STATIC
void
jobject_print
(
const
mp_print_t
*
print
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
(
void
)
kind
;
mp_obj_jobject_t
*
self
=
self_in
;
// Variable value printed as cast to int
mp_printf
(
print
,
"<jobject @%p>"
,
self
->
obj
);
if
(
kind
==
PRINT_REPR
)
{
mp_printf
(
print
,
"<jobject @%p
\"
"
,
self
->
obj
);
}
jobject
str_o
=
JJ
(
CallObjectMethod
,
self
->
obj
,
Object_toString_mid
);
const
char
*
str
=
JJ
(
GetStringUTFChars
,
str_o
,
NULL
);
mp_printf
(
print
,
str
);
JJ
(
ReleaseStringUTFChars
,
str_o
,
str
);
if
(
kind
==
PRINT_REPR
)
{
mp_printf
(
print
,
"
\"
>"
);
}
}
STATIC
void
jobject_attr
(
mp_obj_t
self_in
,
qstr
attr_in
,
mp_obj_t
*
dest
)
{
...
...
@@ -358,7 +365,7 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool
jsize
num_methods
=
JJ
(
GetArrayLength
,
methods
);
for
(
int
i
=
0
;
i
<
num_methods
;
i
++
)
{
jobject
meth
=
JJ
(
GetObjectArrayElement
,
methods
,
i
);
jobject
name_o
=
JJ
(
CallObjectMethod
,
meth
,
Method
_toString_mid
);
jobject
name_o
=
JJ
(
CallObjectMethod
,
meth
,
Object
_toString_mid
);
const
char
*
decl
=
JJ
(
GetStringUTFChars
,
name_o
,
NULL
);
const
char
*
arg_types
=
strchr
(
decl
,
'('
)
+
1
;
//const char *arg_types_end = strchr(arg_types, ')');
...
...
@@ -500,6 +507,10 @@ STATIC void create_jvm() {
jclass
method_class
=
JJ
(
FindClass
,
"java/lang/reflect/Method"
);
String_class
=
JJ
(
FindClass
,
"java/lang/String"
);
jclass
Object_class
=
JJ
(
FindClass
,
"java/lang/Object"
);
Object_toString_mid
=
JJ
(
GetMethodID
,
Object_class
,
"toString"
,
"()Ljava/lang/String;"
);
Class_getField_mid
=
(
*
env
)
->
GetMethodID
(
env
,
Class_class
,
"getField"
,
"(Ljava/lang/String;)Ljava/lang/reflect/Field;"
);
Class_getMethods_mid
=
(
*
env
)
->
GetMethodID
(
env
,
Class_class
,
"getMethods"
,
...
...
@@ -508,8 +519,6 @@ STATIC void create_jvm() {
"()[Ljava/lang/reflect/Constructor;"
);
Method_getName_mid
=
(
*
env
)
->
GetMethodID
(
env
,
method_class
,
"getName"
,
"()Ljava/lang/String;"
);
Method_toString_mid
=
(
*
env
)
->
GetMethodID
(
env
,
method_class
,
"toString"
,
"()Ljava/lang/String;"
);
List_class
=
JJ
(
FindClass
,
"java/util/List"
);
List_get_mid
=
JJ
(
GetMethodID
,
List_class
,
"get"
,
...
...
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