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
fe3cc5bb
Commit
fe3cc5bb
authored
8 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py/modstruct: Use more compact mp_raise_ValueError function.
Saves a few bytes of code size.
parent
3b5affa0
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/modstruct.c
+5
-5
5 additions, 5 deletions
py/modstruct.c
with
5 additions
and
5 deletions
py/modstruct.c
+
5
−
5
View file @
fe3cc5bb
...
@@ -114,7 +114,7 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
...
@@ -114,7 +114,7 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
mp_uint_t
align
;
mp_uint_t
align
;
size_t
sz
=
mp_binary_get_size
(
fmt_type
,
*
fmt
,
&
align
);
size_t
sz
=
mp_binary_get_size
(
fmt_type
,
*
fmt
,
&
align
);
if
(
sz
==
0
)
{
if
(
sz
==
0
)
{
nlr
_raise
(
mp_obj_new_exception_msg
(
&
mp_type
_ValueError
,
"unsupported format"
)
)
;
mp
_raise_ValueError
(
"unsupported format"
);
}
}
while
(
cnt
--
)
{
while
(
cnt
--
)
{
// Apply alignment
// Apply alignment
...
@@ -149,7 +149,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
...
@@ -149,7 +149,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
// negative offsets are relative to the end of the buffer
// negative offsets are relative to the end of the buffer
offset
=
bufinfo
.
len
+
offset
;
offset
=
bufinfo
.
len
+
offset
;
if
(
offset
<
0
)
{
if
(
offset
<
0
)
{
nlr
_raise
(
mp_obj_new_exception_msg
(
&
mp_type
_ValueError
,
"buffer too small"
)
)
;
mp
_raise_ValueError
(
"buffer too small"
);
}
}
}
}
p
+=
offset
;
p
+=
offset
;
...
@@ -164,7 +164,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
...
@@ -164,7 +164,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
sz
=
get_fmt_num
(
&
fmt
);
sz
=
get_fmt_num
(
&
fmt
);
}
}
if
(
p
+
sz
>
end_p
)
{
if
(
p
+
sz
>
end_p
)
{
nlr
_raise
(
mp_obj_new_exception_msg
(
&
mp_type
_ValueError
,
"buffer too small"
)
)
;
mp
_raise_ValueError
(
"buffer too small"
);
}
}
mp_obj_t
item
;
mp_obj_t
item
;
if
(
*
fmt
==
's'
)
{
if
(
*
fmt
==
's'
)
{
...
@@ -197,7 +197,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, byte* end_p, siz
...
@@ -197,7 +197,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, byte* end_p, siz
sz
=
get_fmt_num
(
&
fmt
);
sz
=
get_fmt_num
(
&
fmt
);
}
}
if
(
p
+
sz
>
end_p
)
{
if
(
p
+
sz
>
end_p
)
{
nlr
_raise
(
mp_obj_new_exception_msg
(
&
mp_type
_ValueError
,
"buffer too small"
)
)
;
mp
_raise_ValueError
(
"buffer too small"
);
}
}
if
(
*
fmt
==
's'
)
{
if
(
*
fmt
==
's'
)
{
...
@@ -240,7 +240,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) {
...
@@ -240,7 +240,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) {
// negative offsets are relative to the end of the buffer
// negative offsets are relative to the end of the buffer
offset
=
(
mp_int_t
)
bufinfo
.
len
+
offset
;
offset
=
(
mp_int_t
)
bufinfo
.
len
+
offset
;
if
(
offset
<
0
)
{
if
(
offset
<
0
)
{
nlr
_raise
(
mp_obj_new_exception_msg
(
&
mp_type
_ValueError
,
"buffer too small"
)
)
;
mp
_raise_ValueError
(
"buffer too small"
);
}
}
}
}
byte
*
p
=
(
byte
*
)
bufinfo
.
buf
;
byte
*
p
=
(
byte
*
)
bufinfo
.
buf
;
...
...
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