Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
f28dda56
Commit
f28dda56
authored
Aug 24, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dict.__delitem__, and fix a bug where delitems weren't interacting with exceptions properly
parent
a262a1d1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
16 deletions
+37
-16
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+1
-2
src/runtime/dict.cpp
src/runtime/dict.cpp
+19
-0
test/tests/dict.py
test/tests/dict.py
+17
-14
No files found.
src/codegen/irgen/irgenerator.cpp
View file @
f28dda56
...
...
@@ -1436,8 +1436,7 @@ private:
emitter
.
createPatchpoint
(
pp
,
(
void
*
)
pyston
::
delitem
,
llvm_args
,
exc_info
);
}
else
{
emitter
.
getBuilder
()
->
CreateCall2
(
g
.
funcs
.
delitem
,
converted_target
->
getValue
(),
converted_slice
->
getValue
());
emitter
.
createCall2
(
exc_info
,
g
.
funcs
.
delitem
,
converted_target
->
getValue
(),
converted_slice
->
getValue
());
}
converted_target
->
decvref
(
emitter
);
...
...
src/runtime/dict.cpp
View file @
f28dda56
...
...
@@ -119,6 +119,24 @@ Box* dictSetitem(BoxedDict* self, Box* k, Box* v) {
return
None
;
}
Box
*
dictDelitem
(
BoxedDict
*
self
,
Box
*
k
)
{
assert
(
self
->
cls
==
dict_cls
);
auto
it
=
self
->
d
.
find
(
k
);
if
(
it
==
self
->
d
.
end
())
{
BoxedString
*
s
=
reprOrNull
(
k
);
if
(
s
)
raiseExcHelper
(
KeyError
,
"%s"
,
s
->
s
.
c_str
());
else
raiseExcHelper
(
KeyError
,
""
);
}
self
->
d
.
erase
(
it
);
return
None
;
}
Box
*
dictPop
(
BoxedDict
*
self
,
Box
*
k
,
Box
*
d
)
{
assert
(
self
->
cls
==
dict_cls
);
...
...
@@ -268,6 +286,7 @@ void setupDict() {
dict_cls
->
giveAttr
(
"__getitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictGetitem
,
UNKNOWN
,
2
)));
dict_cls
->
giveAttr
(
"__setitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictSetitem
,
NONE
,
3
)));
dict_cls
->
giveAttr
(
"__delitem__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictDelitem
,
UNKNOWN
,
2
)));
dict_cls
->
giveAttr
(
"__contains__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictContains
,
BOXED_BOOL
,
2
)));
dict_cls
->
giveAttr
(
"__nonzero__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
dictNonzero
,
BOXED_BOOL
,
1
)));
...
...
test/tests/dict.py
View file @
f28dda56
...
...
@@ -72,29 +72,32 @@ print sorted(dict((('a', 1), ('b', 2)), b=3)) == sorted(dict((['a', 1], ('b', 3)
try
:
print
dict
([
1
,
2
],
[
2
,
3
])
except
TypeError
,
e
:
print
'dict expected at most 1 arg'
else
:
raise
print
e
try
:
print
dict
([(
1
,
2
),
42
])
except
TypeError
,
e
:
print
'cannot convert dictionary update sequence element #1 to a sequence'
else
:
raise
print
e
try
:
# invalid tuple len
print
dict
([(
10
,
20
),
(
1
,
2
,
3
)])
except
TypeError
,
e
:
print
'dictionary update sequence element #1 has length 3; 2 is required'
else
:
raise
except
ValueError
,
e
:
print
e
try
:
# invalid list len
print
dict
([[
10
,
20
],
[
1
,
2
,
3
]])
except
TypeError
,
e
:
print
'dictionary update sequence element #1 has length 3; 2 is required'
else
:
raise
except
ValueError
,
e
:
print
e
d
=
{
i
:
i
**
2
for
i
in
xrange
(
10
)}
print
sorted
(
d
.
items
())
del
d
[
2
]
print
d
.
__delitem__
(
4
)
print
sorted
(
d
.
items
())
try
:
del
d
[
2
]
except
KeyError
,
e
:
print
e
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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