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
ff39eb26
Commit
ff39eb26
authored
Jan 28, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement PyDict_Next
parent
d8b4aafb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletion
+38
-1
src/runtime/dict.cpp
src/runtime/dict.cpp
+38
-1
No files found.
src/runtime/dict.cpp
View file @
ff39eb26
...
...
@@ -237,7 +237,44 @@ 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
{
Py_FatalError
(
"unimplemented"
);
assert
(
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
// the form of a Py_ssize_t* -- ie they allocate a Py_ssize_t on their stack, and let us use
// it.
//
// We want to store an unordered_map::iterator in that. In my glibc it would fit, but to keep
// things a little bit more portable, allocate separate storage for the iterator, and store the
// pointer to this storage in the Py_ssize_t slot.
//
// Results in lots of indirection unfortunately. If it becomes an issue we can try to switch
// to storing the iterator directly in the stack slot.
typedef
BoxedDict
::
DictMap
::
iterator
iterator
;
static_assert
(
sizeof
(
Py_ssize_t
)
==
sizeof
(
iterator
*
),
""
);
iterator
**
it_ptr
=
reinterpret_cast
<
iterator
**>
(
ppos
);
// Clients are supposed to zero-initialize *ppos:
if
(
*
it_ptr
==
NULL
)
{
*
it_ptr
=
(
iterator
*
)
malloc
(
sizeof
(
iterator
));
**
it_ptr
=
self
->
d
.
begin
();
}
iterator
*
it
=
*
it_ptr
;
if
(
*
it
==
self
->
d
.
end
())
{
free
(
it
);
return
0
;
}
*
pkey
=
(
*
it
)
->
first
;
*
pvalue
=
(
*
it
)
->
second
;
++
(
*
it
);
return
1
;
}
extern
"C"
PyObject
*
PyDict_GetItemString
(
PyObject
*
dict
,
const
char
*
key
)
noexcept
{
...
...
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