[pypy-commit] pypy better-PyDict_Next: add w_userdata argument to attach() and percolate out to PyDict_Next
mattip
pypy.commits at gmail.com
Sat Dec 10 16:35:17 EST 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: better-PyDict_Next
Changeset: r89005:2241edc5516e
Date: 2016-12-10 18:17 +0200
http://bitbucket.org/pypy/pypy/changeset/2241edc5516e/
Log: add w_userdata argument to attach() and percolate out to PyDict_Next
diff --git a/pypy/module/cpyext/bufferobject.py b/pypy/module/cpyext/bufferobject.py
--- a/pypy/module/cpyext/bufferobject.py
+++ b/pypy/module/cpyext/bufferobject.py
@@ -31,7 +31,7 @@
dealloc=buffer_dealloc,
realize=buffer_realize)
-def buffer_attach(space, py_obj, w_obj):
+def buffer_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyBufferObject with the given (str) buffer object.
"""
diff --git a/pypy/module/cpyext/bytesobject.py b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -73,7 +73,7 @@
py_str.c_ob_sstate = rffi.cast(rffi.INT, 0) # SSTATE_NOT_INTERNED
return py_str
-def bytes_attach(space, py_obj, w_obj):
+def bytes_attach(space, py_obj, w_obj, w_userdata=None):
"""
Copy RPython string object contents to a PyBytesObject. The
c_ob_sval must not be modified.
diff --git a/pypy/module/cpyext/complexobject.py b/pypy/module/cpyext/complexobject.py
--- a/pypy/module/cpyext/complexobject.py
+++ b/pypy/module/cpyext/complexobject.py
@@ -29,7 +29,7 @@
attach=complex_attach,
realize=complex_realize)
-def complex_attach(space, py_obj, w_obj):
+def complex_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyComplexObject with the given complex object. The
value must not be modified.
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -28,7 +28,7 @@
dealloc=dict_dealloc,
realize=dict_realize)
-def dict_attach(space, py_obj, w_obj):
+def dict_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyDictObject with the given dict object.
"""
@@ -264,17 +264,13 @@
if pkey:
pkey[0] = as_pyobj(space, w_key)
if pvalue:
+ w_type = None
if isinstance(w_value, GetSetProperty):
strategy = w_dict.get_strategy()
# for translation
assert isinstance(strategy, ClassDictStrategy)
w_type = strategy.unerase(w_dict.get_storage())
- assert space.isinstance_w(w_type, space.w_type)
- #XXX Could this by calling a make_typedescr(GetSetProperty),
- # but how to feed in w_type?
- py_getsetdef = make_GetSet(space, w_value)
- w_value = W_GetSetPropertyEx(py_getsetdef, w_type)
- pvalue[0] = as_pyobj(space, w_value)
+ pvalue[0] = as_pyobj(space, w_value, w_type)
return 1
@specialize.memo()
diff --git a/pypy/module/cpyext/floatobject.py b/pypy/module/cpyext/floatobject.py
--- a/pypy/module/cpyext/floatobject.py
+++ b/pypy/module/cpyext/floatobject.py
@@ -22,7 +22,7 @@
attach=float_attach,
realize=float_realize)
-def float_attach(space, py_obj, w_obj):
+def float_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyFloatObject with the given float object. The
value must not be modified.
diff --git a/pypy/module/cpyext/frameobject.py b/pypy/module/cpyext/frameobject.py
--- a/pypy/module/cpyext/frameobject.py
+++ b/pypy/module/cpyext/frameobject.py
@@ -30,7 +30,7 @@
dealloc=frame_dealloc,
realize=frame_realize)
-def frame_attach(space, py_obj, w_obj):
+def frame_attach(space, py_obj, w_obj, w_userdata=None):
"Fills a newly allocated PyFrameObject with a frame object"
frame = space.interp_w(PyFrame, w_obj)
py_frame = rffi.cast(PyFrameObject, py_obj)
diff --git a/pypy/module/cpyext/funcobject.py b/pypy/module/cpyext/funcobject.py
--- a/pypy/module/cpyext/funcobject.py
+++ b/pypy/module/cpyext/funcobject.py
@@ -51,7 +51,7 @@
PyMethod_Check, PyMethod_CheckExact = build_type_checkers("Method", Method)
PyCode_Check, PyCode_CheckExact = build_type_checkers("Code", PyCode)
-def function_attach(space, py_obj, w_obj):
+def function_attach(space, py_obj, w_obj, w_userdata=None):
py_func = rffi.cast(PyFunctionObject, py_obj)
assert isinstance(w_obj, Function)
py_func.c_func_name = make_ref(space, space.wrap(w_obj.name))
@@ -63,7 +63,7 @@
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
-def code_attach(space, py_obj, w_obj):
+def code_attach(space, py_obj, w_obj, w_userdata=None):
py_code = rffi.cast(PyCodeObject, py_obj)
assert isinstance(w_obj, PyCode)
py_code.c_co_name = make_ref(space, space.wrap(w_obj.co_name))
diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py
--- a/pypy/module/cpyext/intobject.py
+++ b/pypy/module/cpyext/intobject.py
@@ -24,7 +24,7 @@
attach=int_attach,
realize=int_realize)
-def int_attach(space, py_obj, w_obj):
+def int_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyIntObject with the given int object. The
value must not be modified.
diff --git a/pypy/module/cpyext/methodobject.py b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -44,7 +44,7 @@
attach=cfunction_attach,
dealloc=cfunction_dealloc)
-def cfunction_attach(space, py_obj, w_obj):
+def cfunction_attach(space, py_obj, w_obj, w_userdata=None):
assert isinstance(w_obj, W_PyCFunctionObject)
py_func = rffi.cast(PyCFunctionObject, py_obj)
py_func.c_m_ml = w_obj.ml
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -63,7 +63,7 @@
pyobj.c_ob_type = pytype
return pyobj
- def attach(self, space, pyobj, w_obj):
+ def attach(self, space, pyobj, w_obj, w_userdata=None):
pass
def realize(self, space, obj):
@@ -115,8 +115,8 @@
tp_dealloc.api_func.get_wrapper(space))
if tp_attach:
- def attach(self, space, pyobj, w_obj):
- tp_attach(space, pyobj, w_obj)
+ def attach(self, space, pyobj, w_obj, w_userdata=None):
+ tp_attach(space, pyobj, w_obj, w_userdata)
if tp_realize:
def realize(self, space, ref):
@@ -156,7 +156,7 @@
class InvalidPointerException(Exception):
pass
-def create_ref(space, w_obj):
+def create_ref(space, w_obj, w_userdata=None):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
@@ -177,7 +177,7 @@
assert py_obj.c_ob_refcnt > rawrefcount.REFCNT_FROM_PYPY
py_obj.c_ob_refcnt -= 1
#
- typedescr.attach(space, py_obj, w_obj)
+ typedescr.attach(space, py_obj, w_obj, w_userdata)
return py_obj
def track_reference(space, py_obj, w_obj):
@@ -232,7 +232,7 @@
assert isinstance(w_type, W_TypeObject)
return get_typedescr(w_type.layout.typedef).realize(space, ref)
-def as_pyobj(space, w_obj):
+def as_pyobj(space, w_obj, w_userdata=None):
"""
Returns a 'PyObject *' representing the given intepreter object.
This doesn't give a new reference, but the returned 'PyObject *'
@@ -244,7 +244,7 @@
assert not is_pyobj(w_obj)
py_obj = rawrefcount.from_obj(PyObject, w_obj)
if not py_obj:
- py_obj = create_ref(space, w_obj)
+ py_obj = create_ref(space, w_obj, w_userdata)
return py_obj
else:
return lltype.nullptr(PyObject.TO)
diff --git a/pypy/module/cpyext/pytraceback.py b/pypy/module/cpyext/pytraceback.py
--- a/pypy/module/cpyext/pytraceback.py
+++ b/pypy/module/cpyext/pytraceback.py
@@ -28,7 +28,7 @@
dealloc=traceback_dealloc)
-def traceback_attach(space, py_obj, w_obj):
+def traceback_attach(space, py_obj, w_obj, w_userdata=None):
py_traceback = rffi.cast(PyTracebackObject, py_obj)
traceback = space.interp_w(PyTraceback, w_obj)
if traceback.next is None:
diff --git a/pypy/module/cpyext/sliceobject.py b/pypy/module/cpyext/sliceobject.py
--- a/pypy/module/cpyext/sliceobject.py
+++ b/pypy/module/cpyext/sliceobject.py
@@ -25,7 +25,7 @@
attach=slice_attach,
dealloc=slice_dealloc)
-def slice_attach(space, py_obj, w_obj):
+def slice_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PySliceObject with the given slice object. The
fields must not be modified.
diff --git a/pypy/module/cpyext/tupleobject.py b/pypy/module/cpyext/tupleobject.py
--- a/pypy/module/cpyext/tupleobject.py
+++ b/pypy/module/cpyext/tupleobject.py
@@ -63,7 +63,7 @@
p[i] = lltype.nullptr(PyObject.TO)
return py_obj
-def tuple_attach(space, py_obj, w_obj):
+def tuple_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyTupleObject with the given tuple object. The
buffer must not be modified.
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -174,7 +174,7 @@
realize=methoddescr_realize,
)
-def memberdescr_attach(space, py_obj, w_obj):
+def memberdescr_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyMemberDescrObject with the given W_MemberDescr
object. The values must not be modified.
@@ -193,17 +193,21 @@
track_reference(space, obj, w_obj)
return w_obj
-def getsetdescr_attach(space, py_obj, w_obj):
+def getsetdescr_attach(space, py_obj, w_obj, w_userdata=None):
"""
Fills a newly allocated PyGetSetDescrObject with the given W_GetSetPropertyEx
object. The values must not be modified.
"""
py_getsetdescr = rffi.cast(PyGetSetDescrObject, py_obj)
+ if isinstance(w_obj, GetSetProperty):
+ py_getsetdef = make_GetSet(space, w_obj)
+ assert space.isinstance_w(w_userdata, space.w_type)
+ w_obj = W_GetSetPropertyEx(py_getsetdef, w_userdata)
# XXX assign to d_dname, d_type?
assert isinstance(w_obj, W_GetSetPropertyEx)
py_getsetdescr.c_d_getset = w_obj.getset
-def methoddescr_attach(space, py_obj, w_obj):
+def methoddescr_attach(space, py_obj, w_obj, w_userdata=None):
py_methoddescr = rffi.cast(PyMethodDescrObject, py_obj)
# XXX assign to d_dname, d_type?
assert isinstance(w_obj, W_PyCFunctionObject)
@@ -702,7 +706,7 @@
return rffi.cast(PyObject, heaptype)
-def type_attach(space, py_obj, w_type):
+def type_attach(space, py_obj, w_type, w_userdata=None):
"""
Fills a newly allocated PyTypeObject from an existing type.
"""
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -62,7 +62,7 @@
py_uni.c_defenc = lltype.nullptr(PyObject.TO)
return py_uni
-def unicode_attach(space, py_obj, w_obj):
+def unicode_attach(space, py_obj, w_obj, w_userdata=None):
"Fills a newly allocated PyUnicodeObject with a unicode string"
py_unicode = rffi.cast(PyUnicodeObject, py_obj)
py_unicode.c_length = len(space.unicode_w(w_obj))
More information about the pypy-commit
mailing list