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
1b8e76b8
Commit
1b8e76b8
authored
10 years ago
by
stijn
Committed by
Damien George
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
py: Cleanup duplication in instance_is_callable/instance_call.
parent
c1832fd2
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
py/objtype.c
+12
-16
12 additions, 16 deletions
py/objtype.c
with
12 additions
and
16 deletions
py/objtype.c
+
12
−
16
View file @
1b8e76b8
...
@@ -595,9 +595,9 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
...
@@ -595,9 +595,9 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
}
}
}
}
bool
mp_obj_instance_
is
_call
able
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
mp_obj_instance_
get
_call
(
mp_obj_t
self_in
)
{
mp_obj_instance_t
*
self
=
self_in
;
mp_obj_instance_t
*
self
=
self_in
;
mp_obj_t
member
[
2
]
=
{
MP_OBJ_NULL
};
mp_obj_t
member
[
2
]
=
{
MP_OBJ_NULL
,
MP_OBJ_NULL
};
struct
class_lookup_data
lookup
=
{
struct
class_lookup_data
lookup
=
{
.
obj
=
self
,
.
obj
=
self
,
.
attr
=
MP_QSTR___call__
,
.
attr
=
MP_QSTR___call__
,
...
@@ -606,21 +606,16 @@ bool mp_obj_instance_is_callable(mp_obj_t self_in) {
...
@@ -606,21 +606,16 @@ bool mp_obj_instance_is_callable(mp_obj_t self_in) {
.
is_type
=
false
,
.
is_type
=
false
,
};
};
mp_obj_class_lookup
(
&
lookup
,
self
->
base
.
type
);
mp_obj_class_lookup
(
&
lookup
,
self
->
base
.
type
);
return
member
[
0
]
!=
MP_OBJ_NULL
;
return
member
[
0
];
}
bool
mp_obj_instance_is_callable
(
mp_obj_t
self_in
)
{
return
mp_obj_instance_get_call
(
self_in
)
!=
MP_OBJ_NULL
;
}
}
mp_obj_t
mp_obj_instance_call
(
mp_obj_t
self_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
mp_obj_t
mp_obj_instance_call
(
mp_obj_t
self_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
mp_obj_instance_t
*
self
=
self_in
;
mp_obj_t
call
=
mp_obj_instance_get_call
(
self_in
);
mp_obj_t
member
[
2
]
=
{
MP_OBJ_NULL
,
MP_OBJ_NULL
};
if
(
call
==
MP_OBJ_NULL
)
{
struct
class_lookup_data
lookup
=
{
.
obj
=
self
,
.
attr
=
MP_QSTR___call__
,
.
meth_offset
=
offsetof
(
mp_obj_type_t
,
call
),
.
dest
=
member
,
.
is_type
=
false
,
};
mp_obj_class_lookup
(
&
lookup
,
self
->
base
.
type
);
if
(
member
[
0
]
==
MP_OBJ_NULL
)
{
if
(
MICROPY_ERROR_REPORTING
==
MICROPY_ERROR_REPORTING_TERSE
)
{
if
(
MICROPY_ERROR_REPORTING
==
MICROPY_ERROR_REPORTING_TERSE
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_TypeError
,
"object not callable"
));
"object not callable"
));
...
@@ -629,10 +624,11 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw
...
@@ -629,10 +624,11 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw
"'%s' object is not callable"
,
mp_obj_get_type_str
(
self_in
)));
"'%s' object is not callable"
,
mp_obj_get_type_str
(
self_in
)));
}
}
}
}
if
(
member
[
0
]
==
MP_OBJ_SENTINEL
)
{
mp_obj_instance_t
*
self
=
self_in
;
if
(
call
==
MP_OBJ_SENTINEL
)
{
return
mp_call_function_n_kw
(
self
->
subobj
[
0
],
n_args
,
n_kw
,
args
);
return
mp_call_function_n_kw
(
self
->
subobj
[
0
],
n_args
,
n_kw
,
args
);
}
}
mp_obj_t
meth
=
mp_obj_new_bound_meth
(
member
[
0
]
,
self
);
mp_obj_t
meth
=
mp_obj_new_bound_meth
(
call
,
self
);
return
mp_call_function_n_kw
(
meth
,
n_args
,
n_kw
,
args
);
return
mp_call_function_n_kw
(
meth
,
n_args
,
n_kw
,
args
);
}
}
...
...
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