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
ca6d75f1
Commit
ca6d75f1
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Small simplifications in tuple and list accessors.
parent
4abff750
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
py/obj.c
+4
-12
4 additions, 12 deletions
py/obj.c
py/objtuple.c
+2
-6
2 additions, 6 deletions
py/objtuple.c
py/objzip.c
+8
-9
8 additions, 9 deletions
py/objzip.c
py/runtime.c
+5
-7
5 additions, 7 deletions
py/runtime.c
with
19 additions
and
34 deletions
py/obj.c
+
4
−
12
View file @
ca6d75f1
...
...
@@ -319,18 +319,10 @@ void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
}
void
mp_obj_get_array_fixed_n
(
mp_obj_t
o
,
mp_uint_t
len
,
mp_obj_t
**
items
)
{
if
(
MP_OBJ_IS_TYPE
(
o
,
&
mp_type_tuple
)
||
MP_OBJ_IS_TYPE
(
o
,
&
mp_type_list
))
{
mp_uint_t
seq_len
;
if
(
MP_OBJ_IS_TYPE
(
o
,
&
mp_type_tuple
))
{
mp_obj_tuple_get
(
o
,
&
seq_len
,
items
);
}
else
{
mp_obj_list_get
(
o
,
&
seq_len
,
items
);
}
if
(
seq_len
!=
len
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"requested length %d but object has length %d"
,
len
,
seq_len
));
}
}
else
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_TypeError
,
"object '%s' is not a tuple or list"
,
mp_obj_get_type_str
(
o
)));
mp_uint_t
seq_len
;
mp_obj_get_array
(
o
,
&
seq_len
,
items
);
if
(
seq_len
!=
len
)
{
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_ValueError
,
"requested length %d but object has length %d"
,
len
,
seq_len
));
}
}
...
...
This diff is collapsed.
Click to expand it.
py/objtuple.c
+
2
−
6
View file @
ca6d75f1
...
...
@@ -241,12 +241,8 @@ mp_obj_t mp_obj_new_tuple(mp_uint_t n, const mp_obj_t *items) {
void
mp_obj_tuple_get
(
mp_obj_t
self_in
,
mp_uint_t
*
len
,
mp_obj_t
**
items
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp_type_tuple
));
mp_obj_tuple_t
*
self
=
self_in
;
if
(
len
)
{
*
len
=
self
->
len
;
}
if
(
items
)
{
*
items
=
&
self
->
items
[
0
];
}
*
len
=
self
->
len
;
*
items
=
&
self
->
items
[
0
];
}
void
mp_obj_tuple_del
(
mp_obj_t
self_in
)
{
...
...
This diff is collapsed.
Click to expand it.
py/objzip.c
+
8
−
9
View file @
ca6d75f1
...
...
@@ -31,11 +31,12 @@
#include
"misc.h"
#include
"qstr.h"
#include
"obj.h"
#include
"objtuple.h"
#include
"runtime.h"
typedef
struct
_mp_obj_zip_t
{
mp_obj_base_t
base
;
in
t
n_iters
;
mp_uint_
t
n_iters
;
mp_obj_t
iters
[];
}
mp_obj_zip_t
;
...
...
@@ -45,7 +46,7 @@ STATIC mp_obj_t zip_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
mp_obj_zip_t
*
o
=
m_new_obj_var
(
mp_obj_zip_t
,
mp_obj_t
,
n_args
);
o
->
base
.
type
=
&
mp_type_zip
;
o
->
n_iters
=
n_args
;
for
(
in
t
i
=
0
;
i
<
n_args
;
i
++
)
{
for
(
mp_uint_
t
i
=
0
;
i
<
n_args
;
i
++
)
{
o
->
iters
[
i
]
=
mp_getiter
(
args
[
i
]);
}
return
o
;
...
...
@@ -54,22 +55,20 @@ STATIC mp_obj_t zip_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
STATIC
mp_obj_t
zip_iternext
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
mp_type_zip
));
mp_obj_zip_t
*
self
=
self_in
;
mp_obj_t
*
items
;
if
(
self
->
n_iters
==
0
)
{
return
MP_OBJ_STOP_ITERATION
;
}
mp_obj_t
o
=
mp_obj_new_tuple
(
self
->
n_iters
,
NULL
);
mp_obj_tuple_get
(
o
,
NULL
,
&
items
);
mp_obj_tuple_t
*
tuple
=
mp_obj_new_tuple
(
self
->
n_iters
,
NULL
);
for
(
in
t
i
=
0
;
i
<
self
->
n_iters
;
i
++
)
{
for
(
mp_uint_
t
i
=
0
;
i
<
self
->
n_iters
;
i
++
)
{
mp_obj_t
next
=
mp_iternext
(
self
->
iters
[
i
]);
if
(
next
==
MP_OBJ_STOP_ITERATION
)
{
mp_obj_tuple_del
(
o
);
mp_obj_tuple_del
(
tuple
);
return
MP_OBJ_STOP_ITERATION
;
}
items
[
i
]
=
next
;
tuple
->
items
[
i
]
=
next
;
}
return
o
;
return
tuple
;
}
const
mp_obj_type_t
mp_type_zip
=
{
...
...
This diff is collapsed.
Click to expand it.
py/runtime.c
+
5
−
7
View file @
ca6d75f1
...
...
@@ -34,6 +34,7 @@
#include
"qstr.h"
#include
"obj.h"
#include
"objtuple.h"
#include
"objlist.h"
#include
"objmodule.h"
#include
"parsenum.h"
#include
"runtime0.h"
...
...
@@ -769,21 +770,18 @@ void mp_unpack_ex(mp_obj_t seq_in, mp_uint_t num_in, mp_obj_t *items) {
}
items
[
num_left
+
num_right
+
1
-
1
-
seq_len
]
=
item
;
}
mp_obj_t
rest
=
mp_obj_new_list
(
0
,
NULL
);
mp_obj_
list_
t
*
rest
=
mp_obj_new_list
(
0
,
NULL
);
while
((
item
=
mp_iternext
(
iterable
))
!=
MP_OBJ_STOP_ITERATION
)
{
mp_obj_list_append
(
rest
,
item
);
}
mp_uint_t
rest_len
;
mp_obj_t
*
rest_items
;
mp_obj_list_get
(
rest
,
&
rest_len
,
&
rest_items
);
if
(
rest_len
<
num_right
)
{
if
(
rest
->
len
<
num_right
)
{
goto
too_short
;
}
items
[
num_right
]
=
rest
;
for
(
mp_uint_t
i
=
0
;
i
<
num_right
;
i
++
)
{
items
[
num_right
-
1
-
i
]
=
rest
_
items
[
rest
_
len
-
num_right
+
i
];
items
[
num_right
-
1
-
i
]
=
rest
->
items
[
rest
->
len
-
num_right
+
i
];
}
mp_obj_list_set_len
(
rest
,
rest
_
len
-
num_right
);
mp_obj_list_set_len
(
rest
,
rest
->
len
-
num_right
);
}
return
;
...
...
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