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
c3f1126e
Commit
c3f1126e
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Fix logic bugs in object attribute/method extraction.
parent
6022d9d4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/objtype.c
+30
-49
30 additions, 49 deletions
py/objtype.c
py/runtime.c
+5
-2
5 additions, 2 deletions
py/runtime.c
with
35 additions
and
51 deletions
py/objtype.c
+
30
−
49
View file @
c3f1126e
...
...
@@ -30,24 +30,13 @@ STATIC mp_obj_t mp_obj_new_class(mp_obj_t class) {
STATIC
mp_obj_t
mp_obj_class_lookup
(
const
mp_obj_type_t
*
type
,
qstr
attr
)
{
for
(;;)
{
if
(
type
->
locals_dict
!=
NULL
)
{
// search locals_dict (the dynamically created set of methods/attributes)
// search locals_dict (the set of methods/attributes)
assert
(
MP_OBJ_IS_TYPE
(
type
->
locals_dict
,
&
dict_type
));
// Micro Python restriction, for now
mp_map_t
*
locals_map
=
mp_obj_dict_get_map
(
type
->
locals_dict
);
mp_map_elem_t
*
elem
=
mp_map_lookup
(
locals_map
,
MP_OBJ_NEW_QSTR
(
attr
),
MP_MAP_LOOKUP
);
if
(
elem
!=
NULL
)
{
return
elem
->
value
;
}
/*
} else if (type->methods != NULL) {
// search methods (the const set of methods)
for (const mp_method_t *meth = type->methods; meth->name != MP_QSTR_NULL; meth++) {
if (meth->name == attr) {
return (mp_obj_t)meth->fun;
}
}
*/
}
// attribute not found, keep searching base classes
...
...
@@ -220,8 +209,6 @@ STATIC void class_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
}
mp_obj_t
member
=
mp_obj_class_lookup
(
self
->
base
.
type
,
attr
);
if
(
member
!=
MP_OBJ_NULL
)
{
if
(
mp_obj_is_callable
(
member
))
{
// class member is callable so build a bound method
// check if the methods are functions, static or class methods
// see http://docs.python.org/3.3/howto/descriptor.html
// TODO check that this is the correct place to have this logic
...
...
@@ -232,12 +219,10 @@ STATIC void class_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
// return a bound method, with self being the type of this object
dest
[
0
]
=
((
mp_obj_static_class_method_t
*
)
member
)
->
fun
;
dest
[
1
]
=
mp_obj_get_type
(
self_in
);
}
else
{
}
else
if
(
mp_obj_is_callable
(
member
))
{
// return a bound method, with self being this object
dest
[
0
]
=
member
;
dest
[
1
]
=
self_in
;
}
return
;
}
else
{
// class member is a value, so just return that value
dest
[
0
]
=
member
;
...
...
@@ -425,8 +410,6 @@ STATIC void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
mp_obj_t
member
=
mp_obj_class_lookup
((
mp_obj_type_t
*
)
items
[
i
],
attr
);
if
(
member
!=
MP_OBJ_NULL
)
{
// XXX this and the code in class_load_attr need to be factored out
if
(
mp_obj_is_callable
(
member
))
{
// class member is callable so build a bound method
// check if the methods are functions, static or class methods
// see http://docs.python.org/3.3/howto/descriptor.html
// TODO check that this is the correct place to have this logic
...
...
@@ -437,17 +420,15 @@ STATIC void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
// return a bound method, with self being the type of this object
dest
[
0
]
=
((
mp_obj_static_class_method_t
*
)
member
)
->
fun
;
dest
[
1
]
=
mp_obj_get_type
(
self
->
obj
);
}
else
{
}
if
(
mp_obj_is_callable
(
member
))
{
// return a bound method, with self being this object
dest
[
0
]
=
member
;
dest
[
1
]
=
self
->
obj
;
}
return
;
}
else
{
// class member is a value, so just return that value
dest
[
0
]
=
member
;
return
;
}
return
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
py/runtime.c
+
5
−
2
View file @
c3f1126e
...
...
@@ -859,10 +859,13 @@ STATIC void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
// return a bound method, with self being the type of this object
dest
[
0
]
=
((
mp_obj_static_class_method_t
*
)
elem
->
value
)
->
fun
;
dest
[
1
]
=
mp_obj_get_type
(
base
);
}
else
{
}
else
if
(
mp_obj_is_callable
(
elem
->
value
))
{
// return a bound method, with self being this object
dest
[
0
]
=
(
mp_obj_t
)
elem
->
value
;
dest
[
0
]
=
elem
->
value
;
dest
[
1
]
=
base
;
}
else
{
// class member is a value, so just return that value
dest
[
0
]
=
elem
->
value
;
}
}
}
...
...
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