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
cc87a036
Commit
cc87a036
authored
Jun 20, 2016
by
Kevin Modzelewski
Committed by
GitHub
Jun 20, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1251 from Daetalus/new_api_nexedi
Add some helper API to Pyston.
parents
4dd4b5b3
3eb3e5f9
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
85 additions
and
17 deletions
+85
-17
Makefile
Makefile
+1
-1
from_cpython/Include/code.h
from_cpython/Include/code.h
+5
-1
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+9
-7
src/runtime/code.cpp
src/runtime/code.cpp
+6
-0
src/runtime/frame.cpp
src/runtime/frame.cpp
+1
-0
src/runtime/set.cpp
src/runtime/set.cpp
+8
-0
test/integration/numpy_test.py
test/integration/numpy_test.py
+24
-6
test/test_extension/CMakeLists.txt
test/test_extension/CMakeLists.txt
+2
-2
test/test_extension/api_test.c
test/test_extension/api_test.c
+22
-0
test/test_extension/setup.py
test/test_extension/setup.py
+1
-0
test/tests/set.expected
test/tests/set.expected
+1
-0
test/tests/set.py
test/tests/set.py
+5
-0
No files found.
Makefile
View file @
cc87a036
...
...
@@ -969,7 +969,7 @@ bench_exceptions:
zsh
-c
'ulimit -m
$(MAX_MEM_KB)
; time ./bench_exceptions'
rm
bench_exceptions
TEST_EXT_MODULE_NAMES
:=
basic_test descr_test slots_test
TEST_EXT_MODULE_NAMES
:=
basic_test descr_test slots_test
type_test api_test
TEST_EXT_MODULE_SRCS
:=
$
(
TEST_EXT_MODULE_NAMES:%
=
test
/test_extension/%.c
)
TEST_EXT_MODULE_OBJS
:=
$
(
TEST_EXT_MODULE_NAMES:%
=
test
/test_extension/%.pyston.so
)
...
...
from_cpython/Include/code.h
View file @
cc87a036
...
...
@@ -74,7 +74,10 @@ PyAPI_DATA(PyTypeObject*) code_cls;
#define PyCode_Type (*code_cls)
#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
// Pyston change: disable this macro.
// In Pyston the PyCodeObject is just an opaque pointer, get its size
// directly will cause error.
// #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
/* Public interface */
PyAPI_FUNC
(
PyCodeObject
*
)
PyCode_New
(
...
...
@@ -95,6 +98,7 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int) PYSTON_NOEXCEPT;
PyAPI_FUNC
(
int
)
PyCode_GetArgCount
(
PyCodeObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
BORROWED
(
PyObject
*
))
PyCode_GetFilename
(
PyCodeObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
BORROWED
(
PyObject
*
))
PyCode_GetName
(
PyCodeObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
int
)
PyCode_HasFreeVars
(
PyCodeObject
*
)
PYSTON_NOEXCEPT
;
/* for internal use only */
#define _PyCode_GETCODEPTR(co, pp) \
...
...
src/capi/typeobject.cpp
View file @
cc87a036
...
...
@@ -702,15 +702,17 @@ static long slot_tp_hash(PyObject* self) noexcept {
PyObject
*
slot_tp_call
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
noexcept
{
STAT_TIMER
(
t0
,
"us_timer_slot_tpcall"
,
SLOT_AVOIDABILITY
(
self
));
try
{
Py_FatalError
(
"this function is untested"
);
static
PyObject
*
call_str
;
PyObject
*
meth
=
lookup_method
(
self
,
"__call__"
,
&
call_str
);
PyObject
*
res
;
// TODO: runtime ICs?
return
runtimeCall
(
self
,
ArgPassSpec
(
0
,
0
,
true
,
true
),
args
,
kwds
,
NULL
,
NULL
,
NULL
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
if
(
meth
==
NULL
)
return
NULL
;
}
res
=
PyObject_Call
(
meth
,
args
,
kwds
);
Py_DECREF
(
meth
);
return
res
;
}
static
const
char
*
name_op
[]
=
{
...
...
src/runtime/code.cpp
View file @
cc87a036
...
...
@@ -200,11 +200,17 @@ extern "C" BORROWED(PyObject*) PyCode_GetFilename(PyCodeObject* op) noexcept {
RELEASE_ASSERT
(
PyCode_Check
((
Box
*
)
op
),
""
);
return
BoxedCode
::
filename
((
Box
*
)
op
,
NULL
);
}
extern
"C"
BORROWED
(
PyObject
*
)
PyCode_GetName
(
PyCodeObject
*
op
)
noexcept
{
RELEASE_ASSERT
(
PyCode_Check
((
Box
*
)
op
),
""
);
return
BoxedCode
::
name
((
Box
*
)
op
,
NULL
);
}
extern
"C"
int
PyCode_HasFreeVars
(
PyCodeObject
*
_code
)
noexcept
{
BoxedCode
*
code
=
(
BoxedCode
*
)
_code
;
return
code
->
f
->
source
->
getScopeInfo
()
->
takesClosure
()
?
1
:
0
;
}
void
setupCode
()
{
code_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedCode
),
false
,
"code"
,
false
,
...
...
src/runtime/frame.cpp
View file @
cc87a036
...
...
@@ -351,6 +351,7 @@ extern "C" PyFrameObject* PyFrame_New(PyThreadState* tstate, PyCodeObject* code,
extern
"C"
BORROWED
(
PyObject
*
)
PyFrame_GetGlobals
(
PyFrameObject
*
f
)
noexcept
{
return
BoxedFrame
::
globals
((
Box
*
)
f
,
NULL
);
}
extern
"C"
BORROWED
(
PyObject
*
)
PyFrame_GetCode
(
PyFrameObject
*
f
)
noexcept
{
return
BoxedFrame
::
code
((
Box
*
)
f
,
NULL
);
}
...
...
src/runtime/set.cpp
View file @
cc87a036
...
...
@@ -457,6 +457,14 @@ extern "C" int PySet_Add(PyObject* set, PyObject* key) noexcept {
}
}
extern
"C"
Py_ssize_t
PySet_Size
(
PyObject
*
anyset
)
noexcept
{
if
(
!
PyAnySet_Check
(
anyset
))
{
PyErr_BadInternalCall
();
return
-
1
;
}
BoxedSet
*
self
=
(
BoxedSet
*
)
anyset
;
return
self
->
s
.
size
();
}
Box
*
setClear
(
BoxedSet
*
self
)
{
RELEASE_ASSERT
(
isSubclass
(
self
->
cls
,
set_cls
),
""
);
...
...
test/integration/numpy_test.py
View file @
cc87a036
import
os
import
sys
import
subprocess
import
shutil
"""
Using this test file.
...
...
@@ -64,6 +63,7 @@ SRC_DIR = ENV_NAME
PYTHON_EXE
=
os
.
path
.
abspath
(
ENV_NAME
+
"/bin/python"
)
CYTHON_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
SRC_DIR
,
"cython-0.22"
))
NUMPY_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
SRC_DIR
,
"numpy"
))
SCIPY_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
SRC_DIR
,
"scipy"
))
print_progress_header
(
"Setting up Cython..."
)
if
not
os
.
path
.
exists
(
CYTHON_DIR
):
...
...
@@ -77,7 +77,6 @@ if not os.path.exists(CYTHON_DIR):
subprocess
.
check_call
([
"patch"
,
"-p1"
,
"--input="
+
PATCH_FILE
],
cwd
=
CYTHON_DIR
)
print
">>> Applied Cython patch"
try
:
subprocess
.
check_call
([
PYTHON_EXE
,
"setup.py"
,
"install"
],
cwd
=
CYTHON_DIR
)
subprocess
.
check_call
([
PYTHON_EXE
,
"-c"
,
"import Cython"
],
cwd
=
CYTHON_DIR
)
...
...
@@ -86,6 +85,10 @@ if not os.path.exists(CYTHON_DIR):
else
:
print
">>> Cython already installed."
env
=
os
.
environ
CYTHON_BIN_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
ENV_NAME
+
"/bin"
))
env
[
"PATH"
]
=
CYTHON_BIN_DIR
+
":"
+
env
[
"PATH"
]
print_progress_header
(
"Cloning up NumPy..."
)
if
not
os
.
path
.
exists
(
NUMPY_DIR
):
url
=
"https://github.com/numpy/numpy"
...
...
@@ -94,10 +97,6 @@ else:
print
">>> NumPy already installed."
try
:
env
=
os
.
environ
CYTHON_BIN_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
ENV_NAME
+
"/bin"
))
env
[
"PATH"
]
=
CYTHON_BIN_DIR
+
":"
+
env
[
"PATH"
]
print_progress_header
(
"Setting up NumPy..."
)
subprocess
.
check_call
([
PYTHON_EXE
,
"setup.py"
,
"build"
],
cwd
=
NUMPY_DIR
,
env
=
env
)
...
...
@@ -109,6 +108,25 @@ except:
raise
print_progress_header
(
"Cloning up SciPy..."
)
if
not
os
.
path
.
exists
(
SCIPY_DIR
):
url
=
"https://github.com/scipy/scipy"
# subprocess.check_call(["git", "clone", "--depth", "1", "--branch", "v0.17.1", url], cwd=SRC_DIR)
else
:
print
">>> SciPy already installed."
try
:
print_progress_header
(
"Setting up SciPy..."
)
# subprocess.check_call([PYTHON_EXE, "setup.py", "build"], cwd=SCIPY_DIR, env=env)
print_progress_header
(
"Installing SciPy..."
)
# subprocess.check_call([PYTHON_EXE, "setup.py", "install"], cwd=SCIPY_DIR, env=env)
except
:
subprocess
.
check_call
([
"rm"
,
"-rf"
,
SCIPY_DIR
+
"/build"
])
subprocess
.
check_call
([
"rm"
,
"-rf"
,
SCIPY_DIR
+
"/dist"
])
raise
# From Wikipedia
script
=
"""
import numpy as np
...
...
test/test_extension/CMakeLists.txt
View file @
cc87a036
add_custom_command
(
OUTPUT
${
CMAKE_CURRENT_BINARY_DIR
}
/build/lib.linux-x86_64-2.7/basic_test.so
COMMAND python setup.py build --build-lib
${
CMAKE_CURRENT_BINARY_DIR
}
/build/lib.linux-x86_64-2.7
DEPENDS basic_test.c descr_test.c slots_test.c type_test.c
DEPENDS basic_test.c descr_test.c slots_test.c type_test.c
api_test.c
WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
)
add_custom_command
(
OUTPUT
${
CMAKE_CURRENT_BINARY_DIR
}
/basic_test.pyston.so
COMMAND
${
CMAKE_BINARY_DIR
}
/pyston setup.py build --build-lib
${
CMAKE_CURRENT_BINARY_DIR
}
DEPENDS pyston copy_stdlib copy_libpyston basic_test.c descr_test.c slots_test.c type_test.c
DEPENDS pyston copy_stdlib copy_libpyston basic_test.c descr_test.c slots_test.c type_test.c
api_test.c
WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
)
add_custom_target
(
ext_cpython DEPENDS
${
CMAKE_CURRENT_BINARY_DIR
}
/build/lib.linux-x86_64-2.7/basic_test.so
)
...
...
test/test_extension/api_test.c
0 → 100644
View file @
cc87a036
#include <Python.h>
static
PyObject
*
set_size
(
PyObject
*
self
,
PyObject
*
so
)
{
return
Py_BuildValue
(
"i"
,
PySet_Size
(
so
));
}
static
PyMethodDef
TestMethods
[]
=
{
{
"set_size"
,
set_size
,
METH_O
,
"Get set size by PySet_Size."
},
{
NULL
,
NULL
,
0
,
NULL
}
/* Sentinel */
};
PyMODINIT_FUNC
initapi_test
(
void
)
{
PyObject
*
m
;
m
=
Py_InitModule
(
"api_test"
,
TestMethods
);
if
(
m
==
NULL
)
return
;
}
test/test_extension/setup.py
View file @
cc87a036
...
...
@@ -7,6 +7,7 @@ extensions = [
Extension
(
"descr_test"
,
sources
=
[
"descr_test.c"
]),
Extension
(
"slots_test"
,
sources
=
[
"slots_test.c"
]),
Extension
(
"type_test"
,
sources
=
[
"type_test.c"
]),
Extension
(
"api_test"
,
sources
=
[
"api_test.c"
]),
]
def
relpath
(
fn
):
...
...
test/tests/set.expected
View file @
cc87a036
...
...
@@ -539,3 +539,4 @@ calling __hash__
False
set([1L]) set([1]) set([1]) set([1L])
set([1])
4
test/tests/set.py
View file @
cc87a036
...
...
@@ -269,3 +269,8 @@ print {1, 1L}, {1L, 1}, set([1, 1L]), set([1L, 1])
s
=
{
1
}
s
.
add
(
1L
)
print
s
from
api_test
import
set_size
s
=
set
([
1
,
2
,
3
,
4
])
print
(
set_size
(
s
))
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