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
9ded34ef
Commit
9ded34ef
authored
Apr 16, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add apply(), PyDict_Values(), PyDict_Items()
parent
c5a3212a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
2 deletions
+59
-2
from_cpython/Include/pyport.h
from_cpython/Include/pyport.h
+25
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+16
-0
src/runtime/dict.cpp
src/runtime/dict.cpp
+14
-2
test/tests/builtins.py
test/tests/builtins.py
+4
-0
No files found.
from_cpython/Include/pyport.h
View file @
9ded34ef
...
...
@@ -320,6 +320,31 @@ typedef ssize_t Py_ssize_t;
#endif
#endif
/* uintptr_t is the C9X name for an unsigned integral type such that a
* legitimate void* can be cast to uintptr_t and then back to void* again
* without loss of information. Similarly for intptr_t, wrt a signed
* integral type.
*/
#ifdef HAVE_UINTPTR_T
typedef
uintptr_t
Py_uintptr_t
;
typedef
intptr_t
Py_intptr_t
;
#elif SIZEOF_VOID_P <= SIZEOF_INT
typedef
unsigned
int
Py_uintptr_t
;
typedef
int
Py_intptr_t
;
#elif SIZEOF_VOID_P <= SIZEOF_LONG
typedef
unsigned
long
Py_uintptr_t
;
typedef
long
Py_intptr_t
;
#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
typedef
unsigned
PY_LONG_LONG
Py_uintptr_t
;
typedef
PY_LONG_LONG
Py_intptr_t
;
#else
# error "Python needs a typedef for Py_uintptr_t in pyport.h."
#endif
/* HAVE_UINTPTR_T */
#if defined(_MSC_VER)
#define Py_MEMCPY(target, source, length) do { \
size_t i_, n_ = (length); \
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
9ded34ef
...
...
@@ -973,6 +973,18 @@ Box* builtinCmp(Box* lhs, Box* rhs) {
throwCAPIException
();
}
Box
*
builtinApply
(
Box
*
func
,
Box
*
args
,
Box
*
keywords
)
{
if
(
!
PyTuple_Check
(
args
))
{
if
(
!
PySequence_Check
(
args
))
raiseExcHelper
(
TypeError
,
"apply() arg 2 expected sequence, found %s"
,
getTypeName
(
args
));
args
=
PySequence_Tuple
(
args
);
checkAndThrowCAPIException
();
}
if
(
keywords
&&
!
PyDict_Check
(
keywords
))
raiseExcHelper
(
TypeError
,
"apply() arg 3 expected dictionary, found %s"
,
getTypeName
(
keywords
));
return
runtimeCall
(
func
,
ArgPassSpec
(
0
,
0
,
true
,
keywords
!=
NULL
),
args
,
keywords
,
NULL
,
NULL
,
NULL
);
}
void
setupBuiltins
()
{
builtins_module
=
createModule
(
"__builtin__"
,
"__builtin__"
,
"Built-in functions, exceptions, and other objects.
\n\n
Noteworthy: None is "
...
...
@@ -1005,6 +1017,10 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"all"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
all
,
BOXED_BOOL
,
1
),
"all"
));
builtins_module
->
giveAttr
(
"any"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
any
,
BOXED_BOOL
,
1
),
"any"
));
builtins_module
->
giveAttr
(
"apply"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
builtinApply
,
UNKNOWN
,
3
,
1
,
false
,
false
),
"apply"
,
{
NULL
}));
repr_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
),
"repr"
);
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
...
...
src/runtime/dict.cpp
View file @
9ded34ef
...
...
@@ -96,20 +96,32 @@ Box* dictKeys(BoxedDict* self) {
return
rtn
;
}
extern
"C"
PyObject
*
PyDict_Keys
(
PyObject
*
mp
)
noexcept
{
static
PyObject
*
dict_helper
(
PyObject
*
mp
,
std
::
function
<
Box
*
(
BoxedDict
*
)
>
f
)
noexcept
{
if
(
mp
==
NULL
||
!
PyDict_Check
(
mp
))
{
PyErr_BadInternalCall
();
return
NULL
;
}
try
{
return
dictKeys
(
static_cast
<
BoxedDict
*>
(
mp
));
return
f
(
static_cast
<
BoxedDict
*>
(
mp
));
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
return
NULL
;
}
}
extern
"C"
PyObject
*
PyDict_Keys
(
PyObject
*
mp
)
noexcept
{
return
dict_helper
(
mp
,
dictKeys
);
}
extern
"C"
PyObject
*
PyDict_Values
(
PyObject
*
mp
)
noexcept
{
return
dict_helper
(
mp
,
dictValues
);
}
extern
"C"
PyObject
*
PyDict_Items
(
PyObject
*
mp
)
noexcept
{
return
dict_helper
(
mp
,
dictItems
);
}
Box
*
dictViewKeys
(
BoxedDict
*
self
)
{
if
(
!
isSubclass
(
self
->
cls
,
dict_cls
))
{
raiseExcHelper
(
TypeError
,
"descriptor 'viewkeys' requires a 'dict' object but received a '%s'"
,
...
...
test/tests/builtins.py
View file @
9ded34ef
...
...
@@ -109,3 +109,7 @@ print round(0.5), round(-0.5)
print
list
(
iter
(
xrange
(
100
).
__iter__
().
next
,
20
))
print
bytearray
(
xrange
(
256
))
l
=
[
2
,
1
,
3
]
print
apply
(
sorted
,
[
l
])
print
apply
(
sorted
,
[
l
],
{
"reverse"
:
True
})
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