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
6a12233c
Commit
6a12233c
authored
Oct 20, 2016
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
7f52a9ad
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
268 additions
and
37 deletions
+268
-37
CMakeLists.txt
CMakeLists.txt
+1
-1
Makefile
Makefile
+2
-10
from_cpython/CMakeLists.txt
from_cpython/CMakeLists.txt
+1
-1
from_cpython/Include/object.h
from_cpython/Include/object.h
+4
-1
from_cpython/Include/py_curses.h
from_cpython/Include/py_curses.h
+1
-1
from_cpython/Lib/distutils/unixccompiler.py
from_cpython/Lib/distutils/unixccompiler.py
+4
-0
from_cpython/Lib/test/test_ioctl.py
from_cpython/Lib/test/test_ioctl.py
+1
-0
from_cpython/Lib/test/test_urllib2net.py
from_cpython/Lib/test/test_urllib2net.py
+1
-0
from_cpython/setup.py
from_cpython/setup.py
+26
-14
src/capi/object.cpp
src/capi/object.cpp
+48
-1
src/runtime/builtin_modules/sys.cpp
src/runtime/builtin_modules/sys.cpp
+16
-0
src/runtime/descr.cpp
src/runtime/descr.cpp
+3
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+143
-1
src/runtime/types.cpp
src/runtime/types.cpp
+11
-3
test/tests/capi_slots.py
test/tests/capi_slots.py
+1
-0
test/tests/curses_test.py
test/tests/curses_test.py
+1
-0
test/tests/extension.py
test/tests/extension.py
+1
-0
test/tests/multiline_repl.py
test/tests/multiline_repl.py
+1
-4
test/tests/type_creation.py
test/tests/type_creation.py
+1
-0
test/tests/type_flags.py
test/tests/type_flags.py
+1
-0
No files found.
CMakeLists.txt
View file @
6a12233c
...
...
@@ -273,7 +273,7 @@ if(ENABLE_OPROFILE)
endif
()
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
-Wall -Wextra -Werror -Wreturn-type -Wno-sign-compare -Wno-unused -Wno-unused-parameter -fno-omit-frame-pointer -g"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
CMAKE_C_FLAGS
}
-std=c++11 -fno-rtti -fexceptions -fvisibility-inlines-hidden -ffunction-sections -fdata-sections -Woverloaded-virtual -Wno-invalid-offsetof -Wcast-qual -Wno-sign-conversion -Wnon-virtual-dtor -Winit-self -Wmissing-include-dirs -Wstrict-overflow=5 -Wpointer-arith -Wtype-limits -Wwrite-strings -Wempty-body -Waggregate-return -Wmissing-field-initializers -Wredundant-decls -Winline -Wint-to-pointer-cast -Wlong-long -Wvla -Wno-attributes -g"
)
set
(
CMAKE_CXX_FLAGS
"$
ENV{CPPFLAGS}
$
{
CMAKE_CXX_FLAGS
}
${
CMAKE_C_FLAGS
}
-std=c++11 -fno-rtti -fexceptions -fvisibility-inlines-hidden -ffunction-sections -fdata-sections -Woverloaded-virtual -Wno-invalid-offsetof -Wcast-qual -Wno-sign-conversion -Wnon-virtual-dtor -Winit-self -Wmissing-include-dirs -Wstrict-overflow=5 -Wpointer-arith -Wtype-limits -Wwrite-strings -Wempty-body -Waggregate-return -Wmissing-field-initializers -Wredundant-decls -Winline -Wint-to-pointer-cast -Wlong-long -Wvla -Wno-attributes -g"
)
set
(
CLANG_FLAGS
"
${
CLANG_FLAGS
}
-Wimplicit-int -Wstrict-prototypes -Wold-style-definition -Wnested-externs -Wpointer-to-int-cast -Wno-mismatched-tags -Wno-extern-c-compat"
)
if
(
"
${
CMAKE_CXX_COMPILER_ID
}
"
STREQUAL
"Clang"
)
...
...
Makefile
View file @
6a12233c
...
...
@@ -24,9 +24,6 @@ CPYTHON := python
ENABLE_VALGRIND
:=
0
GDB
:=
gdb
# If you followed the old install instructions:
# GCC_DIR := $(DEPS_DIR)/gcc-4.8.2-install
GCC_DIR
:=
/usr
GTEST_DIR
:=
$(DEPS_DIR)
/gtest-1.7.0
USE_DEBUG_LIBUNWIND
:=
0
...
...
@@ -76,8 +73,8 @@ TOOLS_DIR := ./tools
TEST_DIR
:=
$(
abspath
./test
)
TESTS_DIR
:=
$(
abspath
./test/tests
)
GPP
:=
$(GCC_DIR)
/bin/
g++
GCC
:=
$(GCC_DIR)
/bin/
gcc
GPP
:=
g++
GCC
:=
gcc
ifeq
($(V),1)
VERBOSE
:=
1
...
...
@@ -155,11 +152,6 @@ COMMON_LDFLAGS += `pkg-config tinfo 2>/dev/null && pkg-config tinfo --libs || ec
# TODO should probably do the linking before MCJIT
COMMON_LDFLAGS
+=
-Wl
,-E
# We get multiple shared libraries (libstdc++, libgcc_s) from the gcc installation:
ifneq
($(GCC_DIR),/usr)
COMMON_LDFLAGS
+=
-Wl
,-rpath
$(GCC_DIR)
/lib64
endif
ifneq
($(USE_DEBUG_LIBUNWIND),0)
COMMON_LDFLAGS
+=
-L
$(DEPS_DIR)
/libunwind-trunk-debug-install/lib
...
...
from_cpython/CMakeLists.txt
View file @
6a12233c
...
...
@@ -161,7 +161,7 @@ file(GLOB_RECURSE STDPARSER_SRCS Parser
tokenizer.c
)
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-type-limits -Wno-unused-result -Wno-strict-aliasing -DPy_BUILD_CORE"
)
set
(
CMAKE_C_FLAGS
"$
ENV{CPPFLAGS}
$
{
CMAKE_C_FLAGS
}
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-type-limits -Wno-unused-result -Wno-strict-aliasing -DPy_BUILD_CORE"
)
add_library
(
FROM_CPYTHON OBJECT
${
STDMODULE_SRCS
}
${
STDOBJECT_SRCS
}
${
STDPYTHON_SRCS
}
${
STDPARSER_SRCS
}
)
add_dependencies
(
FROM_CPYTHON copy_stdlib
)
...
...
from_cpython/Include/object.h
View file @
6a12233c
...
...
@@ -433,7 +433,7 @@ typedef PyObject *(*allocfunc)(PyTypeObject *, Py_ssize_t);
/* Type attribute cache version tag. Added in version 2.6 */
\
/* Pyston change: change uint to 64bit uint
unsigned int tp_version_tag; */
\
PY_UINT64_T
tp_version_tag; \
uint64_t
tp_version_tag; \
\
/* Pyston changes: added these fields */
\
...
...
@@ -539,6 +539,9 @@ PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC
(
int
)
PyObject_SetAttr
(
PyObject
*
,
PyObject
*
,
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
int
)
PyObject_HasAttr
(
PyObject
*
,
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
**
)
_PyObject_GetDictPtr
(
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
*
)
PyObject_GetDict
(
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
void
)
PyObject_ClearDict
(
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
void
)
PyObject_SetDict
(
PyObject
*
,
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
*
)
PyObject_SelfIter
(
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
*
)
_PyObject_NextNotImplemented
(
PyObject
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
*
)
PyObject_GenericGetAttr
(
PyObject
*
,
PyObject
*
)
PYSTON_NOEXCEPT
;
...
...
from_cpython/Include/py_curses.h
View file @
6a12233c
...
...
@@ -50,7 +50,7 @@
#include <curses.h>
#ifdef HAVE_TERM_H
/* for tigetstr, which is not declared in SysV curses */
#include <term.h>
//
#include <term.h>
#endif
#endif
...
...
from_cpython/Lib/distutils/unixccompiler.py
View file @
6a12233c
...
...
@@ -246,6 +246,7 @@ class UnixCCompiler(CCompiler):
shared_f
=
self
.
library_filename
(
lib
,
lib_type
=
'shared'
)
dylib_f
=
self
.
library_filename
(
lib
,
lib_type
=
'dylib'
)
static_f
=
self
.
library_filename
(
lib
,
lib_type
=
'static'
)
non_pyston_shared_f
=
'.'
.
join
(
shared_f
.
split
(
'.'
)[:
-
2
]
+
[
'so'
])
if
sys
.
platform
==
'darwin'
:
# On OSX users can specify an alternate SDK using
...
...
@@ -262,6 +263,7 @@ class UnixCCompiler(CCompiler):
for
dir
in
dirs
:
shared
=
os
.
path
.
join
(
dir
,
shared_f
)
non_pyston_shared
=
os
.
path
.
join
(
dir
,
non_pyston_shared_f
)
dylib
=
os
.
path
.
join
(
dir
,
dylib_f
)
static
=
os
.
path
.
join
(
dir
,
static_f
)
...
...
@@ -281,6 +283,8 @@ class UnixCCompiler(CCompiler):
return
dylib
elif
os
.
path
.
exists
(
shared
):
return
shared
elif
os
.
path
.
exists
(
non_pyston_shared
):
return
non_pyston_shared
elif
os
.
path
.
exists
(
static
):
return
static
...
...
from_cpython/Lib/test/test_ioctl.py
View file @
6a12233c
# expected: fail
import
array
import
unittest
from
test.test_support
import
run_unittest
,
import_module
,
get_attribute
...
...
from_cpython/Lib/test/test_urllib2net.py
View file @
6a12233c
# expected: fail
import
unittest
from
test
import
test_support
from
test.test_urllib2
import
sanepathname2url
...
...
from_cpython/setup.py
View file @
6a12233c
...
...
@@ -743,6 +743,8 @@ class PyBuildExt(build_ext):
missing
.
extend
([
'imageop'
])
# readline
lib_dirs
+=
os
.
getenv
(
'LIBRARY_PATH'
,
''
).
split
(
os
.
pathsep
)
do_readline
=
self
.
compiler
.
find_library_file
(
lib_dirs
,
'readline'
)
readline_termcap_library
=
""
curses_library
=
""
...
...
@@ -1402,17 +1404,19 @@ class PyBuildExt(build_ext):
# provided by the ncurses library.
panel_library
=
'panel'
curses_incs
=
None
inc_dirs
+=
os
.
getenv
(
'CPATH'
,
''
).
split
(
os
.
pathsep
)
if
curses_library
.
startswith
(
'ncurses'
):
if
curses_library
==
'ncursesw'
:
# Bug 1464056: If _curses.so links with ncursesw,
# _curses_panel.so must link with panelw.
panel_library
=
'panelw'
curses_libs
=
[
curses_library
]
curses_incs
=
find_file
(
'curses.h'
,
inc_dirs
,
curses_incs
=
find_file
(
'curses.h'
,
[]
,
[
os
.
path
.
join
(
d
,
'ncursesw'
)
for
d
in
inc_dirs
])
exts
.
append
(
Extension
(
'_curses'
,
sources
=
map
(
relpath
,
[
"Modules/_cursesmodule.c"
,
]),
exts
.
append
(
Extension
(
'_curses'
,
sources
=
map
(
relpath
,
[
"Modules/_cursesmodule.c"
,
]),
include_dirs
=
curses_incs
,
libraries
=
curses_libs
)
)
elif
curses_library
==
'curses'
and
host_platform
!=
'darwin'
:
...
...
@@ -2075,8 +2079,7 @@ class PyBuildExt(build_ext):
srcdir
=
sysconfig
.
get_config_var
(
'srcdir'
)
ffi_builddir
=
os
.
path
.
join
(
self
.
build_temp
,
'libffi'
)
ffi_srcdir
=
os
.
path
.
abspath
(
os
.
path
.
join
(
srcdir
,
'Modules'
,
'_ctypes'
,
'libffi'
))
ffi_srcdir
=
os
.
path
.
abspath
(
os
.
path
.
join
(
srcdir
,
relpath
(
"../../from_cpython/Modules/_ctypes/libffi"
)))
ffi_configfile
=
os
.
path
.
join
(
ffi_builddir
,
'fficonfig.py'
)
from
distutils.dep_util
import
newer_group
...
...
@@ -2088,8 +2091,10 @@ class PyBuildExt(build_ext):
ffi_configfile
):
from
distutils.dir_util
import
mkpath
mkpath
(
ffi_builddir
)
config_args
=
[
arg
for
arg
in
sysconfig
.
get_config_var
(
"CONFIG_ARGS"
).
split
()
if
((
'--host='
in
arg
)
or
(
'--build='
in
arg
))]
# Pyston change: we don't support config var yet
# config_args = [arg for arg in sysconfig.get_config_var("CONFIG_ARGS").split()
# if (('--host=' in arg) or ('--build=' in arg))]
config_args
=
[]
if
not
self
.
verbose
:
config_args
.
append
(
"-q"
)
...
...
@@ -2111,8 +2116,10 @@ class PyBuildExt(build_ext):
self
.
compiler
.
src_extensions
.
append
(
'.S'
)
include_dirs
=
[
os
.
path
.
join
(
ffi_builddir
,
'include'
),
ffi_builddir
,
[]
,
os
.
path
.
join
(
ffi_srcdir
,
'src'
)]
print
(
"In configuration!!!!!!!!!!"
)
print
(
include_dirs
)
extra_compile_args
=
fficonfig
[
'ffi_cflags'
].
split
()
ext
.
sources
.
extend
(
os
.
path
.
join
(
ffi_srcdir
,
f
)
for
f
in
...
...
@@ -2156,6 +2163,11 @@ class PyBuildExt(build_ext):
elif
host_platform
.
startswith
(
'hp-ux'
):
extra_link_args
.
append
(
'-fPIC'
)
print
(
"Is everything OK?"
)
print
(
"***********************************"
)
print
(
include_dirs
)
print
(
sources
)
print
(
depends
)
ext
=
Extension
(
'_ctypes'
,
include_dirs
=
include_dirs
,
extra_compile_args
=
extra_compile_args
,
...
...
@@ -2176,11 +2188,8 @@ class PyBuildExt(build_ext):
# in /usr/include/ffi
inc_dirs
.
append
(
'/usr/include/ffi'
)
# Pyston change: still hard code the ffi include dir
# because we don't support this variable configuration in get_config_var yet
ffi_inc
=
[
'/usr/include/x86_64-linux-gnu'
]
# ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
if
not
ffi_inc
or
ffi_inc
[
0
]
==
''
:
ffi_inc
=
[
sysconfig
.
get_config_var
(
"LIBFFI_INCLUDEDIR"
)]
if
not
ffi_inc
[
0
]
or
ffi_inc
[
0
]
==
''
:
ffi_inc
=
find_file
(
'ffi.h'
,
[],
inc_dirs
)
if
ffi_inc
is
not
None
:
ffi_h
=
ffi_inc
[
0
]
+
'/ffi.h'
...
...
@@ -2199,6 +2208,9 @@ class PyBuildExt(build_ext):
ffi_lib
=
lib_name
break
print
(
"ffi in----------------------"
)
print
(
ffi_inc
)
print
(
ffi_lib
)
if
ffi_inc
and
ffi_lib
:
ext
.
include_dirs
.
extend
(
ffi_inc
)
ext
.
libraries
.
append
(
ffi_lib
)
...
...
src/capi/object.cpp
View file @
6a12233c
...
...
@@ -609,11 +609,58 @@ extern "C" PyObject** _PyObject_GetDictPtr(PyObject* obj) noexcept {
}
return
(
PyObject
**
)((
char
*
)
obj
+
dictoffset
);
}
else
{
// Box* attrwrapper = tp->getAttrWrapper();
// Box* new_dict = unwrapAttrWrapper(attrwrapper);
// return (PyObject**)(&new_dict);
// return (PyObject**)&unwrapAttrWrapper(attrwrapper);
// auto new_dict = PyDict_New();
// PyDict_Update(new_dict, attrwrapper);
// return (PyObject**)&new_dict;
// HCAttrs* hcattrs = obj->getHCAttrsPtr();
// HiddenClass* hcls = hcattrs->hcls;
// int offset = hcls->getAsSingletonOrNormal()->getAttrwrapperOffset();
// if (offset != -1) {
// AttrWrapper* wrapper = (AttrWrapper*)(hcattrs->attr_list->attrs[offset]);
// BoxedDict*
// BoxedDict* dict = (BoxedDict*)AttrWrapper::copy(obj);
// convertAttrwrapperToPrivateDict(wrapper);
// return &wrapper;
// return wrapper->getUnderlying();
// }
fatalOrError
(
PyExc_NotImplementedError
,
"unimplemented for hcattrs"
);
return
nullptr
;
}
}
extern
"C"
PyObject
*
PyObject_GetDict
(
PyObject
*
obj
)
noexcept
{
PyTypeObject
*
tp
=
Py_TYPE
(
obj
);
if
(
!
tp
->
instancesHaveHCAttrs
())
{
return
obj
->
getDict
();
}
else
{
Box
*
attrwrapper
=
obj
->
getAttrWrapper
();
convertAttrwrapperToPrivateDict
(
attrwrapper
);
return
unwrapAttrWrapper
(
attrwrapper
);
}
}
extern
"C"
void
PyObject_ClearDict
(
PyObject
*
obj
)
noexcept
{
obj
->
clearAttrsForDealloc
();
}
extern
"C"
void
PyObject_SetDict
(
PyObject
*
obj
,
PyObject
*
dict
)
noexcept
{
PyObject
*
d_key
,
*
d_value
;
Py_ssize_t
i
=
0
;
while
(
PyDict_Next
(
dict
,
&
i
,
&
d_key
,
&
d_value
))
{
if
(
PyString_CheckExact
(
d_key
))
{
Py_INCREF
(
d_key
);
PyString_InternInPlace
(
&
d_key
);
Py_DECREF
(
d_key
);
}
if
(
PyObject_SetAttr
(
obj
,
d_key
,
d_value
)
<
0
)
return
;
}
}
/* These methods are used to control infinite recursion in repr, str, print,
etc. Container objects that may recursively contain themselves,
e.g. builtin dictionaries and lists, should used Py_ReprEnter() and
...
...
@@ -1148,7 +1195,7 @@ extern "C" void _Py_NegativeRefcount(const char* fname, int lineno, PyObject* op
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"%s:%i object at %p has negative ref count "
"%"
PY_FORMAT_SIZE_T
"d.
\033
[40mwatch -l *(long*)%p
\033
[0m"
,
fname
,
lineno
,
op
,
op
->
ob_refcnt
,
&
op
->
ob_refcnt
);
Py_FatalError
(
buf
);
//
Py_FatalError(buf);
}
#endif
/* Py_REF_DEBUG */
...
...
src/runtime/builtin_modules/sys.cpp
View file @
6a12233c
...
...
@@ -50,6 +50,8 @@ int _Py_QnewFlag = 0;
// this flag is one of the few levers we have to avoid hitting those paths.
int
Py_DontWriteBytecodeFlag
=
1
;
int
Py_NoUserSiteDirectory
=
0
;
int
_Py_Ticker
=
0
;
int
_Py_CheckInterval
=
100
;
}
Box
*
sysExcInfo
()
{
...
...
@@ -430,6 +432,18 @@ size_t _PySys_GetSizeOf(PyObject* o) {
return
(
size_t
)
size
;
}
static
PyObject
*
sys_setcheckinterval
(
PyObject
*
self
,
PyObject
*
args
)
noexcept
{
if
(
!
PyArg_ParseTuple
(
args
,
"i:setcheckinterval"
,
&
_Py_CheckInterval
))
return
NULL
;
_Py_Ticker
=
_Py_CheckInterval
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
sys_getcheckinterval
(
PyObject
*
self
,
PyObject
*
args
)
noexcept
{
return
PyInt_FromLong
(
_Py_CheckInterval
);
}
static
PyObject
*
sys_getsizeof
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
noexcept
{
static
const
char
*
kwlist
[]
=
{
"object"
,
"default"
,
0
};
size_t
size
;
...
...
@@ -545,6 +559,8 @@ static PyMethodDef sys_methods[] = {
{
"excepthook"
,
sys_excepthook
,
METH_VARARGS
,
excepthook_doc
},
{
"displayhook"
,
sys_displayhook
,
METH_O
,
displayhook_doc
},
{
"_clear_type_cache"
,
sys_clear_type_cache
,
METH_NOARGS
,
sys_clear_type_cache__doc__
},
{
"setcheckinterval"
,
sys_setcheckinterval
,
METH_VARARGS
,
NULL
},
{
"getcheckinterval"
,
sys_getcheckinterval
,
METH_NOARGS
,
NULL
},
{
"getrefcount"
,
(
PyCFunction
)
sys_getrefcount
,
METH_O
,
getrefcount_doc
},
{
"getsizeof"
,
(
PyCFunction
)
sys_getsizeof
,
METH_VARARGS
|
METH_KEYWORDS
,
getsizeof_doc
},
};
...
...
src/runtime/descr.cpp
View file @
6a12233c
...
...
@@ -252,6 +252,9 @@ Box* methodDescrTppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPassSpec a
rewrite_args
->
obj
->
addAttrGuard
(
offsetof
(
PyMethodDescrObject
,
d_method
),
(
intptr_t
)
self
->
d_method
);
}
if
(
call_flags
==
METH_KEYWORDS
)
call_flags
=
(
METH_VARARGS
|
METH_KEYWORDS
);
ParamReceiveSpec
paramspec
(
0
,
0
,
false
,
false
);
Box
**
defaults
=
NULL
;
if
(
call_flags
==
METH_NOARGS
)
{
...
...
src/runtime/objmodel.cpp
View file @
6a12233c
...
...
@@ -632,6 +632,138 @@ endlabel:
*/
}
static
PyTypeObject
*
get_builtin_base_with_dict
(
PyTypeObject
*
type
)
{
while
(
type
->
tp_base
!=
NULL
)
{
if
(
type
->
tp_dictoffset
!=
0
&&
!
(
type
->
tp_flags
&
Py_TPFLAGS_HEAPTYPE
))
return
type
;
type
=
type
->
tp_base
;
}
return
NULL
;
}
static
PyObject
*
subtype_dict
(
PyObject
*
obj
,
void
*
context
)
{
PyObject
**
dictptr
;
PyObject
*
dict
;
PyTypeObject
*
base
;
base
=
get_builtin_base_with_dict
(
obj
->
cls
);
if
(
base
!=
NULL
)
{
descrgetfunc
func
;
PyObject
*
descr
=
get_dict_descriptor
(
base
);
if
(
descr
==
NULL
)
{
raise_dict_descr_error
(
obj
);
return
NULL
;
}
func
=
descr
->
cls
->
tp_descr_get
;
if
(
func
==
NULL
)
{
raise_dict_descr_error
(
obj
);
return
NULL
;
}
return
func
(
descr
,
obj
,
(
PyObject
*
)(
obj
->
cls
));
}
dictptr
=
_PyObject_GetDictPtr
(
obj
);
if
(
dictptr
==
NULL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
"This object has no __dict__"
);
return
NULL
;
}
dict
=
*
dictptr
;
if
(
dict
==
NULL
)
*
dictptr
=
dict
=
PyDict_New
();
Py_XINCREF
(
dict
);
return
dict
;
}
static
int
subtype_setdict
(
PyObject
*
obj
,
PyObject
*
value
,
void
*
context
)
{
PyObject
**
dictptr
;
PyObject
*
dict
;
PyTypeObject
*
base
;
base
=
get_builtin_base_with_dict
(
obj
->
cls
);
if
(
base
!=
NULL
)
{
descrsetfunc
func
;
PyObject
*
descr
=
get_dict_descriptor
(
base
);
if
(
descr
==
NULL
)
{
raise_dict_descr_error
(
obj
);
return
-
1
;
}
func
=
descr
->
cls
->
tp_descr_set
;
if
(
func
==
NULL
)
{
raise_dict_descr_error
(
obj
);
return
-
1
;
}
return
func
(
descr
,
obj
,
value
);
}
dictptr
=
_PyObject_GetDictPtr
(
obj
);
if
(
dictptr
==
NULL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
"This object has no __dict__"
);
return
-
1
;
}
if
(
value
!=
NULL
&&
!
PyDict_Check
(
value
))
{
PyErr_Format
(
PyExc_TypeError
,
"__dict__ must be set to a dictionary, "
"not a '%.200s'"
,
Py_TYPE
(
value
)
->
tp_name
);
return
-
1
;
}
dict
=
*
dictptr
;
Py_XINCREF
(
value
);
*
dictptr
=
value
;
Py_XDECREF
(
dict
);
return
0
;
}
static
PyObject
*
subtype_getweakref
(
PyObject
*
obj
,
void
*
context
)
{
PyObject
**
weaklistptr
;
PyObject
*
result
;
if
(
Py_TYPE
(
obj
)
->
tp_weaklistoffset
==
0
)
{
PyErr_SetString
(
PyExc_AttributeError
,
"This object has no __weakref__"
);
return
NULL
;
}
assert
(
Py_TYPE
(
obj
)
->
tp_weaklistoffset
>
0
);
assert
(
Py_TYPE
(
obj
)
->
tp_weaklistoffset
+
sizeof
(
PyObject
*
)
<=
(
size_t
)(
Py_TYPE
(
obj
)
->
tp_basicsize
));
weaklistptr
=
(
PyObject
**
)
((
char
*
)
obj
+
Py_TYPE
(
obj
)
->
tp_weaklistoffset
);
if
(
*
weaklistptr
==
NULL
)
result
=
Py_None
;
else
result
=
*
weaklistptr
;
Py_INCREF
(
result
);
return
result
;
}
/* Three variants on the subtype_getsets list. */
static
PyGetSetDef
subtype_getsets_full
[]
=
{
{
"__dict__"
,
subtype_dict
,
subtype_setdict
,
PyDoc_STR
(
"dictionary for instance variables (if defined)"
)},
{
"__weakref__"
,
subtype_getweakref
,
NULL
,
PyDoc_STR
(
"list of weak references to the object (if defined)"
)},
{
0
}
};
static
PyGetSetDef
subtype_getsets_dict_only
[]
=
{
{
"__dict__"
,
subtype_dict
,
subtype_setdict
,
PyDoc_STR
(
"dictionary for instance variables (if defined)"
)},
{
0
}
};
static
PyGetSetDef
subtype_getsets_weakref_only
[]
=
{
{
"__weakref__"
,
subtype_getweakref
,
NULL
,
PyDoc_STR
(
"list of weak references to the object (if defined)"
)},
{
0
}
};
void
BoxedClass
::
freeze
()
{
assert
(
!
is_constant
);
assert
(
tp_name
);
// otherwise debugging will be very hard
...
...
@@ -1485,7 +1617,8 @@ void Box::setattr(BoxedString* attr, BORROWED(Box*) val, SetattrRewriteArgs* rew
if
(
rewrite_args
)
rewrite_args
->
obj
->
addAttrGuard
(
offsetof
(
Box
,
cls
),
(
intptr_t
)
cls
);
RELEASE_ASSERT
(
attr
->
s
()
!=
none_str
||
this
==
builtins_module
,
"can't assign to None"
);
// RELEASE_ASSERT(attr->s() != none_str || this == builtins_module, "attr is %s", attr->s().data());
// RELEASE_ASSERT(attr->s() != none_str || this == builtins_module, "can't assign to None");
if
(
cls
->
instancesHaveHCAttrs
())
{
HCAttrs
*
attrs
=
getHCAttrsPtr
();
...
...
@@ -7108,6 +7241,15 @@ Box* _typeNew(BoxedClass* metatype, BoxedString* name, BoxedTuple* bases, BoxedD
RELEASE_ASSERT
(
classes
.
back
()
==
made
,
""
);
classes
.
pop_back
();
if
(
weaklist_offset
&&
attrs_offset
)
made
->
tp_getset
=
subtype_getsets_full
;
else
(
weaklist_offset
&&
attrs_offset
)
made
->
tp_getset
=
subtype_getsets_weakref_only
;
else
if
(
!
weaklist_offset
&&
attrs_offset
)
made
->
tp_getset
=
subtype_getsets_dict_only
;
else
made
->
tp_getset
=
NULL
;
if
(
boxedSlots
)
{
// Set ht_slots
BoxedTuple
*
slotsTuple
=
BoxedTuple
::
create
(
final_slot_names
.
size
());
...
...
src/runtime/types.cpp
View file @
6a12233c
...
...
@@ -768,8 +768,8 @@ static Box* objectNewNoArgs(BoxedClass* cls) noexcept {
#ifndef NDEBUG
static
BoxedString
*
new_str
=
getStaticString
(
"__new__"
);
static
BoxedString
*
init_str
=
getStaticString
(
"__init__"
);
assert
(
typeLookup
(
cls
,
new_str
)
==
typeLookup
(
object_cls
,
new_str
)
&&
typeLookup
(
cls
,
init_str
)
!=
typeLookup
(
object_cls
,
init_str
));
// assert(typeLookup(cls, new_str) == typeLookup(object_cls, new_str));
assert
(
typeLookup
(
cls
,
init_str
)
!=
typeLookup
(
object_cls
,
init_str
));
#endif
return
new
(
cls
)
Box
();
}
...
...
@@ -2364,7 +2364,9 @@ public:
}
void
convertToPrivateDict
()
{
RELEASE_ASSERT
(
!
private_dict
,
""
);
if
(
private_dict
)
return
;
// RELEASE_ASSERT(!private_dict, "");
RELEASE_ASSERT
(
b
,
""
);
private_dict
=
(
BoxedDict
*
)
AttrWrapper
::
copy
(
this
);
assert
(
PyDict_CheckExact
(
private_dict
));
...
...
@@ -3656,6 +3658,12 @@ extern "C" PyObject* PyObject_Init(PyObject* op, PyTypeObject* tp) noexcept {
if
(
op
==
NULL
)
return
PyErr_NoMemory
();
// Pyston change: register the type if the type is not yet registered
if
(
unlikely
(
tp
->
tp_dict
==
NULL
))
{
int
ret
=
PyType_Ready
(
tp
);
assert
(
ret
==
0
);
}
assert
(
tp
);
Py_TYPE
(
op
)
=
tp
;
...
...
test/tests/capi_slots.py
View file @
6a12233c
# skip-if: True
import
slots_test
for
i
in
xrange
(
3
):
...
...
test/tests/curses_test.py
View file @
6a12233c
# expected: fail
import
curses
,
sys
try
:
...
...
test/tests/extension.py
View file @
6a12233c
# skip-if: True
import
basic_test
print
type
(
basic_test
)
...
...
test/tests/multiline_repl.py
View file @
6a12233c
...
...
@@ -20,11 +20,8 @@ def test(s, expected_code=0):
print
r
=
os
.
read
(
fd
,
10240
)
lines
=
r
.
split
(
'
\
n
'
)
while
not
(
lines
[
0
].
startswith
(
'
Python'
)
or
lines
[
0
].
startswith
(
'Pyston
'
)):
while
not
(
lines
[
0
].
startswith
(
'
>>>'
)
or
lines
[
0
].
startswith
(
'>>
'
)):
lines
.
pop
(
0
)
if
lines
[
0
].
startswith
(
'Python'
):
lines
.
pop
(
0
)
lines
.
pop
(
0
)
# Filter out syntax error location lines and make carets consistent:
lines
=
[
l
.
replace
(
'>>> '
,
'>> '
)
for
l
in
lines
if
l
.
strip
()
!=
'^'
]
...
...
test/tests/type_creation.py
View file @
6a12233c
# skip-if: True
import
type_test
print
(
"Hello"
)
test/tests/type_flags.py
View file @
6a12233c
# skip-if: True
import
slots_test
HEAPTYPE
=
1
<<
9
...
...
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