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
cd2be948
Commit
cd2be948
authored
May 19, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PyWrapperDescr_Type, allow cls->tp_descr_get, allow overwriting attributes inside PyType_Ready
parent
15e6f7d6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
5 deletions
+64
-5
from_cpython/Include/descrobject.h
from_cpython/Include/descrobject.h
+2
-0
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+1
-2
src/capi/types.h
src/capi/types.h
+1
-1
src/runtime/capi.cpp
src/runtime/capi.cpp
+1
-2
test/test_extension/slots_test.c
test/test_extension/slots_test.c
+54
-0
test/tests/capi_slots.py
test/tests/capi_slots.py
+5
-0
No files found.
from_cpython/Include/descrobject.h
View file @
cd2be948
...
...
@@ -82,6 +82,8 @@ PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
#endif
// (Pyston TODO: add #defines to our names)
PyAPI_DATA
(
PyTypeObject
*
)
wrapperdescr_cls
;
#define PyWrapperDescr_Type (*wrapperdescr_cls)
PyAPI_FUNC
(
PyObject
*
)
PyDescr_NewMethod
(
PyTypeObject
*
,
PyMethodDef
*
)
PYSTON_NOEXCEPT
;
PyAPI_FUNC
(
PyObject
*
)
PyDescr_NewClassMethod
(
PyTypeObject
*
,
PyMethodDef
*
)
PYSTON_NOEXCEPT
;
...
...
src/capi/typeobject.cpp
View file @
cd2be948
...
...
@@ -2706,7 +2706,6 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
RELEASE_ASSERT
(
cls
->
tp_flags
&
Py_TPFLAGS_CHECKTYPES
,
"Pyston doesn't yet support non-checktypes behavior"
);
}
RELEASE_ASSERT
(
cls
->
tp_descr_get
==
NULL
,
""
);
RELEASE_ASSERT
(
cls
->
tp_descr_set
==
NULL
,
""
);
RELEASE_ASSERT
(
cls
->
tp_free
==
NULL
||
cls
->
tp_free
==
PyObject_Del
||
cls
->
tp_free
==
PyObject_GC_Del
,
""
);
RELEASE_ASSERT
(
cls
->
tp_is_gc
==
NULL
,
""
);
...
...
@@ -2750,7 +2749,7 @@ extern "C" int PyType_Ready(PyTypeObject* cls) noexcept {
}
for
(
PyMethodDef
*
method
=
cls
->
tp_methods
;
method
&&
method
->
ml_name
;
++
method
)
{
cls
->
giveAttr
(
method
->
ml_name
,
new
BoxedMethodDescriptor
(
method
,
cls
)
);
cls
->
setattr
(
method
->
ml_name
,
new
BoxedMethodDescriptor
(
method
,
cls
),
NULL
);
}
for
(
PyMemberDef
*
member
=
cls
->
tp_members
;
member
&&
member
->
name
;
++
member
)
{
...
...
src/capi/types.h
View file @
cd2be948
...
...
@@ -34,7 +34,7 @@ struct wrapper_def {
// exists in CPython: PyObject *name_strobj
};
extern
BoxedClass
*
capifunc_cls
,
*
wrapperdescr_cls
,
*
wrapperobject_cls
;
extern
"C"
BoxedClass
*
capifunc_cls
,
*
wrapperdescr_cls
,
*
wrapperobject_cls
;
class
BoxedCApiFunction
:
public
Box
{
private:
...
...
src/runtime/capi.cpp
View file @
cd2be948
...
...
@@ -50,11 +50,10 @@ extern "C" bool _PyObject_CheckBuffer(PyObject* obj) noexcept {
extern
"C"
{
int
Py_Py3kWarningFlag
;
}
BoxedClass
*
capifunc_cls
;
BoxedClass
*
wrapperdescr_cls
,
*
wrapperobject_cls
;
}
Box
*
BoxedWrapperDescriptor
::
__get__
(
BoxedWrapperDescriptor
*
self
,
Box
*
inst
,
Box
*
owner
)
{
RELEASE_ASSERT
(
self
->
cls
==
wrapperdescr_cls
,
""
);
...
...
test/test_extension/slots_test.c
View file @
cd2be948
...
...
@@ -573,6 +573,55 @@ static PyTypeObject slots_tester_nullreturngetattr = {
0
,
/* tp_free */
};
static
PyObject
*
descr_get_func
(
PyObject
*
obj
,
PyObject
*
inst
,
PyObject
*
owner
)
{
printf
(
"Inside descr_get_func:
\n
"
);
return
PyInt_FromLong
(
42
);
}
static
PyTypeObject
slots_tester_descrget
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"slots_test.slots_tester_descr_get"
,
/* tp_name */
sizeof
(
PyObject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
/* methods */
0
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_call */
0
,
/* tp_str */
PyObject_GenericGetAttr
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/* tp_flags */
0
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
descr_get_func
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
0
,
/* tp_free */
};
// Tests the correctness of the CAPI slots when the attributes get set in Python code:
static
PyObject
*
call_funcs
(
PyObject
*
_module
,
PyObject
*
args
)
{
...
...
@@ -787,6 +836,10 @@ initslots_test(void)
res
=
PyType_Ready
(
&
slots_tester_nullreturngetattr
);
if
(
res
<
0
)
return
;
res
=
PyType_Ready
(
&
slots_tester_descrget
);
if
(
res
<
0
)
return
;
// Not sure if the result of PyInt_FromLong needs to be decref'd
PyDict_SetItemString
(
slots_tester_seq
.
tp_dict
,
"set_through_tpdict"
,
PyInt_FromLong
(
123
));
...
...
@@ -797,4 +850,5 @@ initslots_test(void)
PyModule_AddObject
(
m
,
"SlotsTesterSub"
,
(
PyObject
*
)
&
slots_tester_sub
);
PyModule_AddObject
(
m
,
"SlotsTesterNonsubclassable"
,
(
PyObject
*
)
&
slots_tester_nonsubclassable
);
PyModule_AddObject
(
m
,
"SlotsTesterNullReturnGetAttr"
,
(
PyObject
*
)
&
slots_tester_nullreturngetattr
);
PyModule_AddObject
(
m
,
"SlotsTesterDescrGet"
,
(
PyObject
*
)
&
slots_tester_descrget
);
}
test/tests/capi_slots.py
View file @
cd2be948
...
...
@@ -217,3 +217,8 @@ C.__get__ = lambda *args: None
slots_test
.
call_funcs
(
C
())
del
C
.
__get__
slots_test
.
call_funcs
(
C
())
# test if __get__'s called
class
C
(
object
):
val
=
slots_test
.
SlotsTesterDescrGet
()
print
C
().
val
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