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
d0ebb755
Commit
d0ebb755
authored
Mar 05, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make dict more subclassing friendly
parent
64df7a60
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
7 deletions
+19
-7
src/runtime/dict.cpp
src/runtime/dict.cpp
+4
-4
src/runtime/inline/dict.cpp
src/runtime/inline/dict.cpp
+4
-3
test/tests/dict_subclassing.py
test/tests/dict_subclassing.py
+11
-0
No files found.
src/runtime/dict.cpp
View file @
d0ebb755
...
...
@@ -191,7 +191,7 @@ extern "C" PyObject* PyDict_New() noexcept {
// The performance should hopefully be comparable to the CPython fast case, since we can use
// runtimeICs.
extern
"C"
int
PyDict_SetItem
(
PyObject
*
mp
,
PyObject
*
_key
,
PyObject
*
_item
)
noexcept
{
ASSERT
(
mp
->
cls
==
dict_cls
||
mp
->
cls
==
attrwrapper_cls
,
"%s"
,
getTypeName
(
mp
));
ASSERT
(
isSubclass
(
mp
->
cls
,
dict_cls
)
||
mp
->
cls
==
attrwrapper_cls
,
"%s"
,
getTypeName
(
mp
));
assert
(
mp
);
Box
*
b
=
static_cast
<
Box
*>
(
mp
);
...
...
@@ -219,7 +219,7 @@ extern "C" int PyDict_SetItemString(PyObject* mp, const char* key, PyObject* ite
}
extern
"C"
PyObject
*
PyDict_GetItem
(
PyObject
*
dict
,
PyObject
*
key
)
noexcept
{
ASSERT
(
dict
->
cls
==
dict_cls
||
dict
->
cls
==
attrwrapper_cls
,
"%s"
,
getTypeName
(
dict
));
ASSERT
(
isSubclass
(
dict
->
cls
,
dict_cls
)
||
dict
->
cls
==
attrwrapper_cls
,
"%s"
,
getTypeName
(
dict
));
try
{
return
getitem
(
dict
,
key
);
}
catch
(
ExcInfo
e
)
{
...
...
@@ -230,7 +230,7 @@ extern "C" PyObject* PyDict_GetItem(PyObject* dict, PyObject* key) noexcept {
}
extern
"C"
int
PyDict_Next
(
PyObject
*
op
,
Py_ssize_t
*
ppos
,
PyObject
**
pkey
,
PyObject
**
pvalue
)
noexcept
{
assert
(
op
->
cls
==
dict_cls
);
assert
(
isSubclass
(
op
->
cls
,
dict_cls
)
);
BoxedDict
*
self
=
static_cast
<
BoxedDict
*>
(
op
);
// Callers of PyDict_New() provide a pointer to some storage for this function to use, in
...
...
@@ -430,7 +430,7 @@ extern "C" Box* dictNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
}
void
dictMerge
(
BoxedDict
*
self
,
Box
*
other
)
{
if
(
other
->
cls
==
dict_cls
)
{
if
(
isSubclass
(
other
->
cls
,
dict_cls
)
)
{
for
(
const
auto
&
p
:
static_cast
<
BoxedDict
*>
(
other
)
->
d
)
self
->
d
[
p
.
first
]
=
p
.
second
;
return
;
...
...
src/runtime/inline/dict.cpp
View file @
d0ebb755
...
...
@@ -15,6 +15,7 @@
#include <cstring>
#include "runtime/dict.h"
#include "runtime/objmodel.h"
namespace
pyston
{
...
...
@@ -23,19 +24,19 @@ BoxedDictIterator::BoxedDictIterator(BoxedDict* d, IteratorType type)
}
Box
*
dictIterKeys
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_cls
);
assert
(
isSubclass
(
s
->
cls
,
dict_cls
)
);
BoxedDict
*
self
=
static_cast
<
BoxedDict
*>
(
s
);
return
new
BoxedDictIterator
(
self
,
BoxedDictIterator
::
KeyIterator
);
}
Box
*
dictIterValues
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_cls
);
assert
(
isSubclass
(
s
->
cls
,
dict_cls
)
);
BoxedDict
*
self
=
static_cast
<
BoxedDict
*>
(
s
);
return
new
BoxedDictIterator
(
self
,
BoxedDictIterator
::
ValueIterator
);
}
Box
*
dictIterItems
(
Box
*
s
)
{
assert
(
s
->
cls
==
dict_cls
);
assert
(
isSubclass
(
s
->
cls
,
dict_cls
)
);
BoxedDict
*
self
=
static_cast
<
BoxedDict
*>
(
s
);
return
new
BoxedDictIterator
(
self
,
BoxedDictIterator
::
ItemIterator
);
}
...
...
test/tests/dict_subclassing.py
0 → 100644
View file @
d0ebb755
class
MyDict
(
dict
):
pass
d
=
MyDict
()
d
[
1
]
=
2
print
d
.
keys
()
print
d
.
values
()
print
d
.
items
()
print
list
(
d
.
iterkeys
())
print
list
(
d
.
itervalues
())
print
list
(
d
.
iteritems
())
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