Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
7244a144
Commit
7244a144
authored
Jan 12, 2014
by
John R. Lenton
Browse files
oops, nasty off-by-one in set_copy
parent
be790f94
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objset.c
View file @
7244a144
...
...
@@ -27,6 +27,10 @@ static mp_obj_t set_it_iternext(mp_obj_t self_in);
void
set_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
)
{
mp_obj_set_t
*
self
=
self_in
;
if
(
self
->
set
.
used
==
0
)
{
print
(
env
,
"set()"
);
return
;
}
bool
first
=
true
;
print
(
env
,
"{"
);
for
(
int
i
=
0
;
i
<
self
->
set
.
alloc
;
i
++
)
{
...
...
@@ -122,7 +126,7 @@ static mp_obj_t set_copy(mp_obj_t self_in) {
mp_obj_set_t
*
other
=
m_new_obj
(
mp_obj_set_t
);
other
->
base
.
type
=
&
set_type
;
mp_set_init
(
&
other
->
set
,
self
->
set
.
alloc
);
mp_set_init
(
&
other
->
set
,
self
->
set
.
alloc
-
1
);
other
->
set
.
used
=
self
->
set
.
used
;
memcpy
(
other
->
set
.
table
,
self
->
set
.
table
,
self
->
set
.
alloc
*
sizeof
(
mp_obj_t
));
...
...
tests/basics/tests/set_binop.py
View file @
7244a144
def
r
(
s
):
l
=
list
(
s
)
l
.
sort
()
print
(
l
)
s
=
{
1
,
2
}
t
=
{
2
,
3
}
r
(
s
|
t
)
r
(
s
^
t
)
r
(
s
&
t
)
r
(
s
-
t
)
u
=
s
.
copy
()
u
|=
t
r
(
u
)
u
=
s
.
copy
()
u
^=
t
r
(
u
)
u
=
s
.
copy
()
u
&=
t
r
(
u
)
u
=
s
.
copy
()
u
-=
t
r
(
u
)
return
l
sets
=
[
set
(),
{
1
},
{
1
,
2
},
{
1
,
2
,
3
},
{
2
,
3
},
{
2
,
3
,
5
},
{
5
},
{
7
}]
for
s
in
sets
:
for
t
in
sets
:
print
(
s
,
'|'
,
t
,
'='
,
r
(
s
|
t
))
print
(
s
,
'^'
,
t
,
'='
,
r
(
s
^
t
))
print
(
s
,
'&'
,
t
,
'='
,
r
(
s
&
t
))
print
(
s
,
'-'
,
t
,
'='
,
r
(
s
-
t
))
u
=
s
.
copy
()
u
|=
t
print
(
s
,
"|="
,
t
,
'-->'
,
r
(
u
))
u
=
s
.
copy
()
u
^=
t
print
(
s
,
"^="
,
t
,
'-->'
,
r
(
u
))
u
=
s
.
copy
()
u
&=
t
print
(
s
,
"&="
,
t
,
"-->"
,
r
(
u
))
u
=
s
.
copy
()
u
-=
t
print
(
s
,
"-="
,
t
,
"-->"
,
r
(
u
))
print
(
s
==
t
)
print
(
s
!=
t
)
print
(
s
>
t
)
print
(
s
>=
t
)
print
(
s
<
t
)
print
(
s
<=
t
)
print
(
s
,
'=='
,
t
,
'='
,
s
==
t
)
print
(
s
,
'!='
,
t
,
'='
,
s
!=
t
)
print
(
s
,
'>'
,
t
,
'='
,
s
>
t
)
print
(
s
,
'>='
,
t
,
'='
,
s
>=
t
)
print
(
s
,
'<'
,
t
,
'='
,
s
<
t
)
print
(
s
,
'<='
,
t
,
'='
,
s
<=
t
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment