[pypy-commit] pypy.org extradoc: update the values

2016-01-22 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r694:50a0e13fff46
Date: 2016-01-22 12:47 +0100
http://bitbucket.org/pypy/pypy.org/changeset/50a0e13fff46/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -9,13 +9,13 @@
 
   $(function() {
 $("#progressbar").progressbar({
-  value: 59.7
+  value: 59.8
});
   });
 
 

-   $62736 of $105000 (59.7%)
+   $62755 of $105000 (59.8%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting Python 3 in 
PyPy.
   Current status:
-we have $7914 left
+we have $7931 left
   in the account. Read proposal
   
   
diff --git a/don4.html b/don4.html
--- a/don4.html
+++ b/don4.html
@@ -17,7 +17,7 @@
2nd call:

-   $30344 of $8 (37.9%)
+   $30354 of $8 (37.9%)


 
@@ -25,7 +25,7 @@
   
   This donation goes towards supporting the 
Transactional Memory in PyPy.
   Current status:
-we have $23076 left
+we have $23084 left
   in the account. Read proposal (2nd 
call)
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy vmprof-newstack: Fix for some tests: don't use .offset directly, call .getoffset()

2016-01-22 Thread arigo
Author: Armin Rigo 
Branch: vmprof-newstack
Changeset: r81918:fba43bc13dda
Date: 2016-01-22 16:41 +0100
http://bitbucket.org/pypy/pypy/changeset/fba43bc13dda/

Log:Fix for some tests: don't use .offset directly, call .getoffset()

diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -857,7 +857,8 @@
 # eax = address in the stack of a 3-words struct vmprof_stack_s
 self.mc.LEA_rs(eax.value, (FRAME_FIXED_SIZE - 4) * WORD)
 # old = current value of vmprof_tl_stack
-self.mc.MOV_rm(old.value, (tloc.value, cintf.vmprof_tl_stack.offset))
+offset = cintf.vmprof_tl_stack.getoffset()
+self.mc.MOV_rm(old.value, (tloc.value, offset))
 # eax->next = old
 self.mc.MOV_mr((eax.value, 0), old.value)
 # eax->value = my esp
@@ -865,7 +866,7 @@
 # eax->kind = VMPROF_JITTED_TAG
 self.mc.MOV_mi((eax.value, WORD * 2), VMPROF_JITTED_TAG)
 # save in vmprof_tl_stack the new eax
-self.mc.MOV_mr((tloc.value, cintf.vmprof_tl_stack.offset), eax.value)
+self.mc.MOV_mr((tloc.value, offset), eax.value)
 
 def _call_footer_vmprof(self):
 from rpython.rlib.rvmprof.rvmprof import cintf
@@ -874,7 +875,8 @@
 # eax = (our local vmprof_tl_stack).next
 self.mc.MOV_rs(eax.value, (FRAME_FIXED_SIZE - 4 + 0) * WORD)
 # save in vmprof_tl_stack the value eax
-self.mc.MOV_mr((edx.value, cintf.vmprof_tl_stack.offset), eax.value)
+offset = cintf.vmprof_tl_stack.getoffset()
+self.mc.MOV_mr((edx.value, offset), eax.value)
 
 def _call_header(self):
 self.mc.SUB_ri(esp.value, FRAME_FIXED_SIZE * WORD)
diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -308,7 +308,7 @@
 offset = CDefinedIntSymbolic('RPY_TLOFS_%s' % self.fieldname,
  default='?')
 offset.loop_invariant = loop_invariant
-self.offset = offset
+self._offset = offset
 
 def getraw():
 if we_are_translated():
@@ -364,7 +364,7 @@
 ThreadLocalField.__init__(self, lltype.Signed, 'tlref%d' % unique_id,
   loop_invariant=loop_invariant)
 setraw = self.setraw
-offset = self.offset
+offset = self._offset
 
 def get():
 if we_are_translated():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy vmprof-newstack: fix

2016-01-22 Thread arigo
Author: Armin Rigo 
Branch: vmprof-newstack
Changeset: r81919:e45af82e0252
Date: 2016-01-22 17:31 +0100
http://bitbucket.org/pypy/pypy/changeset/e45af82e0252/

Log:fix

diff --git a/rpython/jit/codewriter/test/test_jtransform.py 
b/rpython/jit/codewriter/test/test_jtransform.py
--- a/rpython/jit/codewriter/test/test_jtransform.py
+++ b/rpython/jit/codewriter/test/test_jtransform.py
@@ -1332,7 +1332,7 @@
 tlfield = ThreadLocalField(lltype.Signed, 'foobar_test_',
loop_invariant=loop_inv)
 OS_THREADLOCALREF_GET = effectinfo.EffectInfo.OS_THREADLOCALREF_GET
-c = const(tlfield.offset)
+c = const(tlfield.getoffset())
 v = varoftype(lltype.Signed)
 op = SpaceOperation('threadlocalref_get', [c], v)
 cc = FakeBuiltinCallControl()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: update the values

2016-01-24 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r695:13468fc54cb3
Date: 2016-01-24 09:07 +0100
http://bitbucket.org/pypy/pypy.org/changeset/13468fc54cb3/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -15,7 +15,7 @@
 
 

-   $62755 of $105000 (59.8%)
+   $62765 of $105000 (59.8%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting Python 3 in 
PyPy.
   Current status:
-we have $7931 left
+we have $7939 left
   in the account. Read proposal
   
   
diff --git a/don4.html b/don4.html
--- a/don4.html
+++ b/don4.html
@@ -9,7 +9,7 @@
 
   $(function() {
 $("#progressbar").progressbar({
-  value: 37.9
+  value: 38.0
});
   });
 
@@ -17,7 +17,7 @@
2nd call:

-   $30354 of $8 (37.9%)
+   $30379 of $8 (38.0%)


 
@@ -25,7 +25,7 @@
   
   This donation goes towards supporting the 
Transactional Memory in PyPy.
   Current status:
-we have $23084 left
+we have $23106 left
   in the account. Read proposal (2nd 
call)
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: update the values

2016-01-24 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r696:43d71eb8c5e7
Date: 2016-01-24 21:16 +0100
http://bitbucket.org/pypy/pypy.org/changeset/43d71eb8c5e7/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -15,7 +15,7 @@
 
 

-   $62765 of $105000 (59.8%)
+   $62793 of $105000 (59.8%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting Python 3 in 
PyPy.
   Current status:
-we have $7939 left
+we have $7965 left
   in the account. Read proposal
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: in-progress

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81953:3d1f9e7d01e1
Date: 2016-01-26 19:10 +0100
http://bitbucket.org/pypy/pypy/changeset/3d1f9e7d01e1/

Log:in-progress

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
@@ -2,9 +2,11 @@
 
 from pypy.interpreter.baseobjspace import W_Root, SpaceCache
 from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rtyper.extregistry import ExtRegistryEntry
 from pypy.module.cpyext.api import (
 cpython_api, bootstrap_function, PyObject, PyObjectP, ADDR,
-CANNOT_FAIL, Py_TPFLAGS_HEAPTYPE, PyTypeObjectPtr)
+CANNOT_FAIL, Py_TPFLAGS_HEAPTYPE, PyTypeObjectPtr,
+INTERPLEVEL_API)
 from pypy.module.cpyext.state import State
 from pypy.objspace.std.typeobject import W_TypeObject
 from pypy.objspace.std.objectobject import W_ObjectObject
@@ -151,10 +153,9 @@
 def create_ref(space, w_obj, itemcount=0):
 """
 Allocates a PyObject, and fills its fields with info from the given
-intepreter object.
+interpreter object.
 """
-GOES_AWAY
-state = space.fromcache(RefcountState)
+#state = space.fromcache(RefcountState)
 w_type = space.type(w_obj)
 if w_type.is_cpytype():
 py_obj = state.get_from_lifeline(w_obj)
@@ -173,18 +174,16 @@
 """
 Ties together a PyObject and an interpreter object.
 """
-GOES_AWAY
 # XXX looks like a PyObject_GC_TRACK
-ptr = rffi.cast(ADDR, py_obj)
-state = space.fromcache(RefcountState)
+assert py_obj.c_ob_refcnt < rawrefcount.REFCNT_FROM_PYPY
+py_obj.c_ob_refcnt += rawrefcount.REFCNT_FROM_PYPY
 if DEBUG_REFCOUNT:
 debug_refcount("MAKREF", py_obj, w_obj)
+assert w_obj
+assert py_obj
 if not replace:
 assert w_obj not in state.py_objects_w2r
-assert ptr not in state.py_objects_r2w
-state.py_objects_w2r[w_obj] = py_obj
-if ptr: # init_typeobject() bootstraps with NULL references
-state.py_objects_r2w[ptr] = w_obj
+rawrefcount.create_link_pypy(py_obj, w_obj)
 
 def make_ref(space, w_obj):
 """
@@ -232,6 +231,124 @@
 return get_typedescr(w_type.instancetypedef).realize(space, ref)
 
 
+def debug_collect():
+rawrefcount._collect(track_allocation=False)
+
+
+def as_pyobj(space, w_obj):
+"""
+Returns a 'PyObject *' representing the given intepreter object.
+This doesn't give a new reference, but the returned 'PyObject *'
+is valid at least as long as 'w_obj' is.  To be safe, you should
+use keepalive_until_here(w_obj) some time later.
+
+NOTE: get_pyobj_and_incref() is safer.
+"""
+if w_obj is not None:
+assert not is_pyobj(w_obj)
+return XXX
+else:
+return lltype.nullptr(PyObject.TO)
+as_pyobj._always_inline_ = 'try'
+INTERPLEVEL_API['as_pyobj'] = as_pyobj
+
+def pyobj_has_w_obj(pyobj):
+return rawrefcount.to_obj(W_Root, pyobj) is not None
+INTERPLEVEL_API['pyobj_has_w_obj'] = staticmethod(pyobj_has_w_obj)
+
+@specialize.ll()
+def from_pyobj(space, pyobj):
+assert is_pyobj(pyobj)
+if pyobj:
+pyobj = rffi.cast(PyObject, pyobj)
+w_obj = rawrefcount.to_obj(W_Root, pyobj)
+if w_obj is None:
+XXX
+return w_obj
+else:
+return None
+from_pyobj._always_inline_ = 'try'
+INTERPLEVEL_API['from_pyobj'] = from_pyobj
+
+
+def is_pyobj(x):
+if x is None or isinstance(x, W_Root):
+return False
+elif is_PyObject(lltype.typeOf(x)):
+return True
+else:
+raise TypeError(repr(type(x)))
+INTERPLEVEL_API['is_pyobj'] = staticmethod(is_pyobj)
+
+class Entry(ExtRegistryEntry):
+_about_ = is_pyobj
+def compute_result_annotation(self, s_x):
+from rpython.rtyper.llannotation import SomePtr
+return self.bookkeeper.immutablevalue(isinstance(s_x, SomePtr))
+def specialize_call(self, hop):
+hop.exception_cannot_occur()
+return hop.inputconst(lltype.Bool, hop.s_result.const)
+
+@specialize.ll()
+def get_pyobj_and_incref(space, obj):
+"""Increment the reference counter of the PyObject and return it.
+Can be called with either a PyObject or a W_Root.
+"""
+if obj:
+if is_pyobj(obj):
+pyobj = rffi.cast(PyObject, obj)
+else:
+pyobj = as_pyobj(space, obj)
+assert pyobj.c_ob_refcnt > 0
+pyobj.c_ob_refcnt += 1
+if not is_pyobj(obj):
+keepalive_until_here(obj)
+return pyobj
+else:
+return lltype.nullptr(PyObject.TO)
+INTERPLEVEL_API['get_pyobj_and_incref'] = get_pyobj_and_incref
+
+
+@specialize.ll()
+def get_w_obj_and_decref(space, obj):
+"""Decrement the reference counter of the PyObject and return the
+corresponding W_Root object (so the reference count is at least
+REFCNT_FROM_PYPY and cannot be zero).  Can be called with either
+a PyObject or a W_

[pypy-commit] pypy cpyext-gc-support-2: Copy more code from cpyext-gc-support

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81951:23ac4994b18d
Date: 2016-01-26 17:44 +0100
http://bitbucket.org/pypy/pypy/changeset/23ac4994b18d/

Log:Copy more code from cpyext-gc-support

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -192,7 +192,7 @@
 
 class ApiFunction:
 def __init__(self, argtypes, restype, callable, error=_NOT_SPECIFIED,
- c_name=None, gil=None):
+ c_name=None, gil=None, result_borrowed=False):
 self.argtypes = argtypes
 self.restype = restype
 self.functype = lltype.Ptr(lltype.FuncType(argtypes, restype))
@@ -209,17 +209,15 @@
 self.argnames = argnames[1:]
 assert len(self.argnames) == len(self.argtypes)
 self.gil = gil
+self.result_borrowed = result_borrowed
+#
+def get_llhelper(space):
+return llhelper(self.functype, self.get_wrapper(space))
+self.get_llhelper = get_llhelper
 
 def _freeze_(self):
 return True
 
-def get_llhelper(self, space):
-llh = getattr(self, '_llhelper', None)
-if llh is None:
-llh = llhelper(self.functype, self.get_wrapper(space))
-self._llhelper = llh
-return llh
-
 @specialize.memo()
 def get_wrapper(self, space):
 wrapper = getattr(self, '_wrapper', None)
@@ -232,7 +230,7 @@
 return wrapper
 
 def cpython_api(argtypes, restype, error=_NOT_SPECIFIED, external=True,
-gil=None):
+gil=None, result_borrowed=False):
 """
 Declares a function to be exported.
 - `argtypes`, `restype` are lltypes and describe the function signature.
@@ -261,13 +259,15 @@
   rffi.cast(restype, 0) == 0)
 
 def decorate(func):
+func._always_inline_ = 'try'
 func_name = func.func_name
 if external:
 c_name = None
 else:
 c_name = func_name
 api_function = ApiFunction(argtypes, restype, func, error,
-   c_name=c_name, gil=gil)
+   c_name=c_name, gil=gil,
+   result_borrowed=result_borrowed)
 func.api_func = api_function
 
 if external:
@@ -278,6 +278,10 @@
 raise ValueError("function %s has no return value for exceptions"
  % func)
 def make_unwrapper(catch_exception):
+# ZZZ is this whole logic really needed???  It seems to be only
+# for RPython code calling PyXxx() functions directly.  I would
+# think that usually directly calling the function is clean
+# enough now
 names = api_function.argnames
 types_names_enum_ui = unrolling_iterable(enumerate(
 zip(api_function.argtypes,
@@ -289,52 +293,55 @@
 from pypy.module.cpyext.pyobject import make_ref, from_ref
 from pypy.module.cpyext.pyobject import Reference
 newargs = ()
-to_decref = []
+keepalives = ()
 assert len(args) == len(api_function.argtypes)
 for i, (ARG, is_wrapped) in types_names_enum_ui:
 input_arg = args[i]
 if is_PyObject(ARG) and not is_wrapped:
-# build a reference
-if input_arg is None:
-arg = lltype.nullptr(PyObject.TO)
-elif isinstance(input_arg, W_Root):
-ref = make_ref(space, input_arg)
-to_decref.append(ref)
-arg = rffi.cast(ARG, ref)
+# build a 'PyObject *' (not holding a reference)
+if not is_pyobj(input_arg):
+keepalives += (input_arg,)
+arg = rffi.cast(ARG, as_xpyobj(space, input_arg))
+else:
+arg = rffi.cast(ARG, input_arg)
+elif is_PyObject(ARG) and is_wrapped:
+# build a W_Root, possibly from a 'PyObject *'
+if is_pyobj(input_arg):
+arg = from_pyobj(space, input_arg)
 else:
 arg = input_arg
-elif is_PyObject(ARG) and is_wrapped:
-# convert to a wrapped object
-if input_arg is None:
-arg = input_arg
-elif isinstance(input_arg, W_Root):
-arg = input_arg
-else:
-try:
-arg = from_ref(space,
-   rffi.cast(PyObject, input_a

[pypy-commit] pypy cpyext-gc-support-2: more copying

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81952:a6a694f2a019
Date: 2016-01-26 17:51 +0100
http://bitbucket.org/pypy/pypy/changeset/a6a694f2a019/

Log:more copying

diff --git a/pypy/module/cpyext/include/object.h 
b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -17,7 +17,8 @@
 #define staticforward static
 
 #define PyObject_HEAD  \
-long ob_refcnt;   \
+Py_ssize_t ob_refcnt;\
+Py_ssize_t ob_pypy_link; \
 struct _typeobject *ob_type;
 
 #define PyObject_VAR_HEAD  \
@@ -25,7 +26,7 @@
Py_ssize_t ob_size; /* Number of items in variable part */
 
 #define PyObject_HEAD_INIT(type)   \
-   1, type,
+   1, 0, type,
 
 #define PyVarObject_HEAD_INIT(type, size)  \
PyObject_HEAD_INIT(type) size,
@@ -40,19 +41,19 @@
 
 #ifdef PYPY_DEBUG_REFCOUNT
 /* Slow version, but useful for debugging */
-#define Py_INCREF(ob)   (Py_IncRef((PyObject *)ob))
-#define Py_DECREF(ob)   (Py_DecRef((PyObject *)ob))
-#define Py_XINCREF(ob)  (Py_IncRef((PyObject *)ob))
-#define Py_XDECREF(ob)  (Py_DecRef((PyObject *)ob))
+#define Py_INCREF(ob)   (Py_IncRef((PyObject *)(ob)))
+#define Py_DECREF(ob)   (Py_DecRef((PyObject *)(ob)))
+#define Py_XINCREF(ob)  (Py_IncRef((PyObject *)(ob)))
+#define Py_XDECREF(ob)  (Py_DecRef((PyObject *)(ob)))
 #else
 /* Fast version */
-#define Py_INCREF(ob)   (((PyObject *)ob)->ob_refcnt++)
-#define Py_DECREF(ob)   \
+#define Py_INCREF(ob)   (((PyObject *)(ob))->ob_refcnt++)
+#define Py_DECREF(op)   \
 do {\
-if (((PyObject *)ob)->ob_refcnt > 1)\
-((PyObject *)ob)->ob_refcnt--;  \
+if (--((PyObject *)(op))->ob_refcnt != 0)   \
+;   \
 else\
-Py_DecRef((PyObject *)ob);  \
+_Py_Dealloc((PyObject *)(op));  \
 } while (0)
 
 #define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
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
@@ -134,6 +134,9 @@
 #
 # refcounted object support
 
+class InvalidPointerException(Exception):
+pass
+
 DEBUG_REFCOUNT = False
 
 def debug_refcount(*args, **kwargs):
@@ -229,48 +232,13 @@
 return get_typedescr(w_type.instancetypedef).realize(space, ref)
 
 
-# XXX Optimize these functions and put them into macro definitions
+@cpython_api([PyObject], lltype.Void)
+def Py_IncRef(space, obj):
+incref(obj)
+
 @cpython_api([PyObject], lltype.Void)
 def Py_DecRef(space, obj):
-ZZZ
-if not obj:
-return
-assert lltype.typeOf(obj) == PyObject
-
-obj.c_ob_refcnt -= 1
-if DEBUG_REFCOUNT:
-debug_refcount("DECREF", obj, obj.c_ob_refcnt, frame_stackdepth=3)
-if obj.c_ob_refcnt == 0:
-state = space.fromcache(RefcountState)
-ptr = rffi.cast(ADDR, obj)
-if ptr not in state.py_objects_r2w:
-# this is a half-allocated object, lets call the deallocator
-# without modifying the r2w/w2r dicts
-_Py_Dealloc(space, obj)
-else:
-w_obj = state.py_objects_r2w[ptr]
-del state.py_objects_r2w[ptr]
-w_type = space.type(w_obj)
-if not w_type.is_cpytype():
-_Py_Dealloc(space, obj)
-del state.py_objects_w2r[w_obj]
-# if the object was a container for borrowed references
-state.delete_borrower(w_obj)
-else:
-if not we_are_translated() and obj.c_ob_refcnt < 0:
-message = "Negative refcount for obj %s with type %s" % (
-obj, rffi.charp2str(obj.c_ob_type.c_tp_name))
-print >>sys.stderr, message
-assert False, message
-
-@cpython_api([PyObject], lltype.Void)
-def Py_IncRef(space, obj):
-if not obj:
-return
-obj.c_ob_refcnt += 1
-assert obj.c_ob_refcnt > 0
-if DEBUG_REFCOUNT:
-debug_refcount("INCREF", obj, obj.c_ob_refcnt, frame_stackdepth=3)
+decref(space, obj)
 
 @cpython_api([PyObject], lltype.Void)
 def _Py_NewReference(space, obj):
@@ -279,6 +247,7 @@
 assert isinstance(w_type, W_TypeObject)
 get_typedescr(w_type.instancetypedef).realize(space, obj)
 
+@cpython_api([PyObject], lltype.Void)
 def _Py_Dealloc(space, obj):
 from pypy.module.cpyext.api import generic_cpy_call_dont_decref
 pto = obj.c_ob_type
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: in-progress

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81956:20a0b177ddae
Date: 2016-01-26 23:10 +0100
http://bitbucket.org/pypy/pypy/changeset/20a0b177ddae/

Log:in-progress

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -37,6 +37,7 @@
 from py.builtin import BaseException
 from rpython.tool.sourcetools import func_with_new_name
 from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rlib import rawrefcount
 
 DEBUG_WRAPPER = True
 
@@ -825,14 +826,6 @@
 outputfilename=str(udir / "module_cache" / "pypyapi"))
 modulename = py.path.local(eci.libraries[-1])
 
-run_bootstrap_functions(space)
-
-# load the bridge, and init structure
-import ctypes
-bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
-
-space.fromcache(State).install_dll(eci)
-
 def dealloc_trigger():
 print 'dealloc_trigger...'
 while True:
@@ -845,6 +838,14 @@
 return "RETRY"
 rawrefcount.init(dealloc_trigger)
 
+run_bootstrap_functions(space)
+
+# load the bridge, and init structure
+import ctypes
+bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
+
+space.fromcache(State).install_dll(eci)
+
 # populate static data
 for name, (typ, expr) in GLOBALS.iteritems():
 from pypy.module import cpyext# for the eval() below
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
@@ -13,6 +13,8 @@
 from rpython.rlib.objectmodel import specialize, we_are_translated
 from rpython.rlib.rweakref import RWeakKeyDictionary
 from rpython.rtyper.annlowlevel import llhelper
+from rpython.rlib import rawrefcount
+
 
 #
 # type description
@@ -31,12 +33,13 @@
 # similar to PyType_GenericAlloc?
 # except that it's not related to any pypy object.
 
-pytype = rffi.cast(PyTypeObjectPtr, make_ref(space, w_type))
+pytype = get_pyobj_and_incref(space, w_type)
+pytype = rffi.cast(PyTypeObjectPtr, pytype)
+assert pytype
 # Don't increase refcount for non-heaptypes
-if pytype:
-flags = rffi.cast(lltype.Signed, pytype.c_tp_flags)
-if not flags & Py_TPFLAGS_HEAPTYPE:
-Py_DecRef(space, w_type)
+flags = rffi.cast(lltype.Signed, pytype.c_tp_flags)
+if not flags & Py_TPFLAGS_HEAPTYPE:
+Py_DecRef(space, w_type)
 
 if pytype:
 size = pytype.c_tp_basicsize
@@ -158,19 +161,18 @@
 #state = space.fromcache(RefcountState)
 w_type = space.type(w_obj)
 if w_type.is_cpytype():
-py_obj = state.get_from_lifeline(w_obj)
+ZZZ # py_obj = state.get_from_lifeline(w_obj)
 if py_obj:
 Py_IncRef(space, py_obj)
 return py_obj
 
 typedescr = get_typedescr(w_obj.typedef)
 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount)
-if w_type.is_cpytype():
-state.set_lifeline(w_obj, py_obj)
+track_reference(space, py_obj, w_obj)
 typedescr.attach(space, py_obj, w_obj)
 return py_obj
 
-def track_reference(space, py_obj, w_obj, replace=False):
+def track_reference(space, py_obj, w_obj):
 """
 Ties together a PyObject and an interpreter object.
 """
@@ -181,8 +183,6 @@
 debug_refcount("MAKREF", py_obj, w_obj)
 assert w_obj
 assert py_obj
-if not replace:
-assert w_obj not in state.py_objects_w2r
 rawrefcount.create_link_pypy(py_obj, w_obj)
 
 def make_ref(space, w_obj):
@@ -239,14 +239,17 @@
 """
 Returns a 'PyObject *' representing the given intepreter object.
 This doesn't give a new reference, but the returned 'PyObject *'
-is valid at least as long as 'w_obj' is.  To be safe, you should
-use keepalive_until_here(w_obj) some time later.
-
-NOTE: get_pyobj_and_incref() is safer.
+is valid at least as long as 'w_obj' is.  **To be safe, you should
+use keepalive_until_here(w_obj) some time later.**  In case of
+doubt, use the safer get_pyobj_and_incref().
 """
 if w_obj is not None:
 assert not is_pyobj(w_obj)
-return XXX
+py_obj = rawrefcount.from_obj(PyObject, w_obj)
+if not py_obj:
+py_obj = create_ref(space, w_obj)
+#track_reference(space, py_obj, w_obj) -- included with 
create_ref()
+return py_obj
 else:
 return lltype.nullptr(PyObject.TO)
 as_pyobj._always_inline_ = 'try'
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
@@ -311,54 +311,12 @@
realize=type_realize,
dealloc=type_dealloc)
 
-# some types are difficult to create because of

[pypy-commit] pypy cpyext-gc-support-2: fixes, now getting a segfault

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81957:0da7861a5b1a
Date: 2016-01-26 23:35 +0100
http://bitbucket.org/pypy/pypy/changeset/0da7861a5b1a/

Log:fixes, now getting a segfault

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -9,7 +9,7 @@
 from rpython.rtyper.tool import rffi_platform
 from rpython.rtyper.lltypesystem import ll2ctypes
 from rpython.rtyper.annlowlevel import llhelper
-from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.objectmodel import we_are_translated, keepalive_until_here
 from rpython.translator import cdir
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.translator.gensupp import NameManager
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
@@ -11,7 +11,7 @@
 from pypy.objspace.std.typeobject import W_TypeObject
 from pypy.objspace.std.objectobject import W_ObjectObject
 from rpython.rlib.objectmodel import specialize, we_are_translated
-from rpython.rlib.rweakref import RWeakKeyDictionary
+from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rtyper.annlowlevel import llhelper
 from rpython.rlib import rawrefcount
 
@@ -183,7 +183,7 @@
 debug_refcount("MAKREF", py_obj, w_obj)
 assert w_obj
 assert py_obj
-rawrefcount.create_link_pypy(py_obj, w_obj)
+rawrefcount.create_link_pypy(w_obj, py_obj)
 
 def make_ref(space, w_obj):
 """
diff --git a/pypy/module/cpyext/test/test_api.py 
b/pypy/module/cpyext/test/test_api.py
--- a/pypy/module/cpyext/test/test_api.py
+++ b/pypy/module/cpyext/test/test_api.py
@@ -6,6 +6,7 @@
 from pypy.module.cpyext.test.test_cpyext import freeze_refcnts, 
LeakCheckingTest
 PyObject = api.PyObject
 from pypy.interpreter.error import OperationError
+from rpython.rlib import rawrefcount
 import os
 
 @api.cpython_api([PyObject], lltype.Void)
@@ -36,6 +37,9 @@
 cls.api = CAPI()
 CAPI.__dict__.update(api.INTERPLEVEL_API)
 
+print 'DONT_FREE_ANY_MORE'
+rawrefcount._dont_free_any_more()
+
 def raises(self, space, api, expected_exc, f, *args):
 if not callable(f):
 raise Exception("%s is not callable" % (f,))
@@ -49,6 +53,7 @@
 return state.clear_exception()
 
 def setup_method(self, func):
+#return   # ZZZ
 freeze_refcnts(self)
 
 def teardown_method(self, func):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Found the segfault's origin, made more explicit that way (not fixed yet)

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81961:d9a31cd29535
Date: 2016-01-27 00:19 +0100
http://bitbucket.org/pypy/pypy/changeset/d9a31cd29535/

Log:Found the segfault's origin, made more explicit that way (not fixed
yet)

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
@@ -439,6 +439,9 @@
 pto.c_tp_as_mapping = heaptype.c_as_mapping
 pto.c_tp_as_buffer = heaptype.c_as_buffer
 
+pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
+pto.c_tp_itemsize = 0
+
 return rffi.cast(PyObject, heaptype)
 
 def type_attach(space, py_obj, w_type):
@@ -473,8 +476,6 @@
 pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
 else:
 pto.c_tp_name = rffi.str2charp(w_type.name)
-pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
-pto.c_tp_itemsize = 0
 # uninitialized fields:
 # c_tp_print, c_tp_getattr, c_tp_setattr
 # XXX implement
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: probably fixed by moving this part of the code later (this is part of an

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81962:834fd655953d
Date: 2016-01-27 00:26 +0100
http://bitbucket.org/pypy/pypy/changeset/834fd655953d/

Log:probably fixed by moving this part of the code later (this is part
of an attempt at simplifying the bootstrapping logic in
init_typeobject, will see how far this theory goes or if I need to
really reproduce it again)

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
@@ -468,20 +468,13 @@
 PyObject_Del.api_func.get_wrapper(space))
 pto.c_tp_alloc = llhelper(PyType_GenericAlloc.api_func.functype,
 PyType_GenericAlloc.api_func.get_wrapper(space))
-if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
-w_typename = space.getattr(w_type, space.wrap('__name__'))
-heaptype = rffi.cast(PyHeapTypeObject, pto)
-heaptype.c_ht_name = get_pyobj_and_incref(space, w_typename)
-from pypy.module.cpyext.stringobject import PyString_AsString
-pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
-else:
-pto.c_tp_name = rffi.str2charp(w_type.name)
 # uninitialized fields:
 # c_tp_print, c_tp_getattr, c_tp_setattr
 # XXX implement
 # c_tp_compare and the following fields (see 
http://docs.python.org/c-api/typeobj.html )
 w_base = best_base(space, w_type.bases_w)
-pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))
+py_base = get_pyobj_and_incref(space, w_base)
+pto.c_tp_base = rffi.cast(PyTypeObjectPtr, py_base)
 
 finish_type_1(space, pto)
 finish_type_2(space, pto, w_type)
@@ -496,6 +489,16 @@
 if space.is_w(w_type, space.w_object):
 pto.c_tp_new = rffi.cast(newfunc, 1)
 update_all_slots(space, w_type, pto)
+
+if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
+w_typename = space.getattr(w_type, space.wrap('__name__'))
+heaptype = rffi.cast(PyHeapTypeObject, pto)
+heaptype.c_ht_name = get_pyobj_and_incref(space, w_typename)
+from pypy.module.cpyext.stringobject import PyString_AsString
+pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
+else:
+pto.c_tp_name = rffi.str2charp(w_type.name)
+
 pto.c_tp_flags |= Py_TPFLAGS_READY
 return pto
 
@@ -562,8 +565,7 @@
 
 if not py_type.c_tp_base:
 # borrowed reference, but w_object is unlikely to disappear
-base = make_ref(space, space.w_object)
-Py_DecRef(space, base)
+base = as_pyobj(space, space.w_object)
 py_type.c_tp_base = rffi.cast(PyTypeObjectPtr, base)
 
 finish_type_1(space, py_type)
@@ -597,7 +599,7 @@
 bases = space.newtuple([])
 else:
 bases = space.newtuple([from_ref(space, base_pyo)])
-pto.c_tp_bases = make_ref(space, bases)
+pto.c_tp_bases = get_pyobj_and_incref(space, bases)
 
 def finish_type_2(space, pto, w_obj):
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: rename from_pyobj() back to from_ref() too

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81964:769d8cdc1853
Date: 2016-01-27 00:34 +0100
http://bitbucket.org/pypy/pypy/changeset/769d8cdc1853/

Log:rename from_pyobj() back to from_ref() too

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -308,7 +308,7 @@
 elif is_PyObject(ARG) and is_wrapped:
 # build a W_Root, possibly from a 'PyObject *'
 if is_pyobj(input_arg):
-arg = from_pyobj(space, input_arg)
+arg = from_ref(space, input_arg)
 else:
 arg = input_arg
 
@@ -634,7 +634,7 @@
 arg = args[i]
 if is_PyObject(typ) and is_wrapped:
 assert is_pyobj(arg)
-arg_conv = from_pyobj(space, arg)
+arg_conv = from_ref(space, arg)
 else:
 arg_conv = arg
 boxed_args += (arg_conv, )
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
@@ -209,17 +209,12 @@
 Finds the interpreter object corresponding to the given reference.  If the
 object is not yet realized (see stringobject.py), creates it.
 """
-GOES_AWAY
-assert lltype.typeOf(ref) == PyObject
+assert is_pyobj(ref)
 if not ref:
 return None
-state = space.fromcache(RefcountState)
-ptr = rffi.cast(ADDR, ref)
-
-try:
-return state.py_objects_r2w[ptr]
-except KeyError:
-pass
+w_obj = rawrefcount.to_obj(W_Root, pyobj)
+if w_obj is not None:
+return w_obj
 
 # This reference is not yet a real interpreter object.
 # Realize it.
@@ -259,20 +254,6 @@
 return rawrefcount.to_obj(W_Root, pyobj) is not None
 INTERPLEVEL_API['pyobj_has_w_obj'] = staticmethod(pyobj_has_w_obj)
 
-@specialize.ll()
-def from_pyobj(space, pyobj):
-assert is_pyobj(pyobj)
-if pyobj:
-pyobj = rffi.cast(PyObject, pyobj)
-w_obj = rawrefcount.to_obj(W_Root, pyobj)
-if w_obj is None:
-XXX
-return w_obj
-else:
-return None
-from_pyobj._always_inline_ = 'try'
-INTERPLEVEL_API['from_pyobj'] = from_pyobj
-
 
 def is_pyobj(x):
 if x is None or isinstance(x, W_Root):
@@ -321,7 +302,7 @@
 """
 if is_pyobj(obj):
 pyobj = rffi.cast(PyObject, obj)
-w_obj = from_pyobj(space, pyobj)
+w_obj = from_ref(space, pyobj)
 else:
 w_obj = obj
 pyobj = as_pyobj(space, w_obj)
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
@@ -21,7 +21,7 @@
 from pypy.module.cpyext.modsupport import convert_method_defs
 from pypy.module.cpyext.pyobject import (
 PyObject, make_ref, create_ref, from_ref, get_typedescr, make_typedescr,
-track_reference, RefcountState, borrow_from, Py_DecRef)
+track_reference, RefcountState, borrow_from, Py_DecRef, as_pyobj)
 from pypy.module.cpyext.slotdefs import (
 slotdefs_for_tp_slots, slotdefs_for_wrappers, get_slot_tp_function)
 from pypy.module.cpyext.state import State
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Rename: this new function should really be a superset of make_ref()

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81963:af2938e59cd3
Date: 2016-01-27 00:29 +0100
http://bitbucket.org/pypy/pypy/changeset/af2938e59cd3/

Log:Rename: this new function should really be a superset of make_ref()

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -675,7 +675,7 @@
 if callable.api_func.result_borrowed:
 retval = as_pyobj(space, result)
 else:
-retval = get_pyobj_and_incref(space, result)
+retval = make_ref(space, result)
 retval = rffi.cast(callable.api_func.restype, retval)
 else:
 retval = lltype.nullptr(PyObject.TO)
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
@@ -33,7 +33,7 @@
 # similar to PyType_GenericAlloc?
 # except that it's not related to any pypy object.
 
-pytype = get_pyobj_and_incref(space, w_type)
+pytype = make_ref(space, w_type)
 pytype = rffi.cast(PyTypeObjectPtr, pytype)
 assert pytype
 # Don't increase refcount for non-heaptypes
@@ -241,7 +241,7 @@
 This doesn't give a new reference, but the returned 'PyObject *'
 is valid at least as long as 'w_obj' is.  **To be safe, you should
 use keepalive_until_here(w_obj) some time later.**  In case of
-doubt, use the safer get_pyobj_and_incref().
+doubt, use the safer make_ref().
 """
 if w_obj is not None:
 assert not is_pyobj(w_obj)
@@ -293,7 +293,7 @@
 return hop.inputconst(lltype.Bool, hop.s_result.const)
 
 @specialize.ll()
-def get_pyobj_and_incref(space, obj):
+def make_ref(space, obj):
 """Increment the reference counter of the PyObject and return it.
 Can be called with either a PyObject or a W_Root.
 """
@@ -309,7 +309,7 @@
 return pyobj
 else:
 return lltype.nullptr(PyObject.TO)
-INTERPLEVEL_API['get_pyobj_and_incref'] = get_pyobj_and_incref
+INTERPLEVEL_API['make_ref'] = make_ref
 
 
 @specialize.ll()
@@ -335,7 +335,7 @@
 
 @specialize.ll()
 def incref(space, obj):
-get_pyobj_and_incref(space, obj)
+make_ref(space, obj)
 INTERPLEVEL_API['incref'] = incref
 
 @specialize.ll()
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
@@ -21,8 +21,7 @@
 from pypy.module.cpyext.modsupport import convert_method_defs
 from pypy.module.cpyext.pyobject import (
 PyObject, make_ref, create_ref, from_ref, get_typedescr, make_typedescr,
-track_reference, RefcountState, borrow_from, Py_DecRef,
-get_pyobj_and_incref)
+track_reference, RefcountState, borrow_from, Py_DecRef)
 from pypy.module.cpyext.slotdefs import (
 slotdefs_for_tp_slots, slotdefs_for_wrappers, get_slot_tp_function)
 from pypy.module.cpyext.state import State
@@ -418,7 +417,7 @@
 
 
 def type_alloc(space, w_metatype):
-metatype = get_pyobj_and_incref(space, w_metatype)
+metatype = make_ref(space, w_metatype)
 metatype = rffi.cast(PyTypeObjectPtr, metatype)
 assert metatype
 # Don't increase refcount for non-heaptypes
@@ -473,7 +472,7 @@
 # XXX implement
 # c_tp_compare and the following fields (see 
http://docs.python.org/c-api/typeobj.html )
 w_base = best_base(space, w_type.bases_w)
-py_base = get_pyobj_and_incref(space, w_base)
+py_base = make_ref(space, w_base)
 pto.c_tp_base = rffi.cast(PyTypeObjectPtr, py_base)
 
 finish_type_1(space, pto)
@@ -493,7 +492,7 @@
 if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
 w_typename = space.getattr(w_type, space.wrap('__name__'))
 heaptype = rffi.cast(PyHeapTypeObject, pto)
-heaptype.c_ht_name = get_pyobj_and_incref(space, w_typename)
+heaptype.c_ht_name = make_ref(space, w_typename)
 from pypy.module.cpyext.stringobject import PyString_AsString
 pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
 else:
@@ -599,7 +598,7 @@
 bases = space.newtuple([])
 else:
 bases = space.newtuple([from_ref(space, base_pyo)])
-pto.c_tp_bases = get_pyobj_and_incref(space, bases)
+pto.c_tp_bases = make_ref(space, bases)
 
 def finish_type_2(space, pto, w_obj):
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Hopefully fix the bootstrap cycles in this way

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81965:ae316294940c
Date: 2016-01-27 01:04 +0100
http://bitbucket.org/pypy/pypy/changeset/ae316294940c/

Log:Hopefully fix the bootstrap cycles in this way

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
@@ -310,13 +310,24 @@
realize=type_realize,
dealloc=type_dealloc)
 
-# we create the type "type" manually here, because of the cycle
-# through its 'c_ob_type' field
+# There is the obvious cycle of 'type(type) == type', but there are
+# also several other ones, like 'tuple.tp_bases' being itself a
+# tuple instance.  We solve the first one by creating the type
+# "type" manually here.  For the other cycles, we fix them by delaying
+# creation of the types here, and hoping nothing breaks by seeing
+# uninitialized-yet types (only for a few basic types like 'type',
+# 'tuple', 'object', 'str').
+space._cpyext_delay_type_creation = []
+
 py_type   = _type_alloc(space, lltype.nullptr(PyTypeObject))
 py_type.c_ob_type = rffi.cast(PyTypeObjectPtr, py_type)
 track_reference(space, py_type, space.w_type)
 type_attach(space, py_type, space.w_type)
 
+while space._cpyext_delay_type_creation:
+_type_really_attach(space, *space._cpyext_delay_type_creation.pop())
+del space._cpyext_delay_type_creation
+
 
 @cpython_api([PyObject], lltype.Void, external=False)
 def subtype_dealloc(space, obj):
@@ -447,6 +458,13 @@
 """
 Fills a newly allocated PyTypeObject from an existing type.
 """
+if hasattr(space, '_cpyext_delay_type_creation'):
+space._cpyext_delay_type_creation.append((py_obj, w_type))
+else:
+_type_really_attach(space, py_obj, w_type)
+return rffi.cast(PyTypeObjectPtr, py_obj)
+
+def _type_really_attach(space, py_obj, w_type):
 from pypy.module.cpyext.object import PyObject_Del
 
 assert isinstance(w_type, W_TypeObject)
@@ -499,7 +517,6 @@
 pto.c_tp_name = rffi.str2charp(w_type.name)
 
 pto.c_tp_flags |= Py_TPFLAGS_READY
-return pto
 
 def py_type_ready(space, pto):
 if pto.c_tp_flags & Py_TPFLAGS_READY:
@@ -513,6 +530,7 @@
 
 def type_realize(space, py_obj):
 pto = rffi.cast(PyTypeObjectPtr, py_obj)
+assert pto.c_tp_flags & Py_TPFLAGS_READY == 0
 assert pto.c_tp_flags & Py_TPFLAGS_READYING == 0
 pto.c_tp_flags |= Py_TPFLAGS_READYING
 try:
@@ -590,7 +608,8 @@
 base = pto.c_tp_base
 base_pyo = rffi.cast(PyObject, pto.c_tp_base)
 if base and not base.c_tp_flags & Py_TPFLAGS_READY:
-type_realize(space, rffi.cast(PyObject, base_pyo))
+if not hasattr(space, '_cpyext_delay_type_creation'):
+type_realize(space, rffi.cast(PyObject, base_pyo))
 if base and not pto.c_ob_type: # will be filled later
 pto.c_ob_type = base.c_ob_type
 if not pto.c_tp_bases:
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -164,6 +164,10 @@
 else:
 w_self.terminator = NoDictTerminator(space, w_self)
 
+def __repr__(self):
+"NOT_RPYTHON"
+return '' % (self.name, id(self))
+
 def mutated(w_self, key):
 """
 The type is being mutated. key is either the string containing the
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix imports

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81967:fcc70c53434c
Date: 2016-01-27 01:19 +0100
http://bitbucket.org/pypy/pypy/changeset/fcc70c53434c/

Log:fix imports

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -290,9 +290,8 @@
 
 @specialize.ll()
 def unwrapper(space, *args):
-from pypy.module.cpyext.pyobject import Py_DecRef
+from pypy.module.cpyext.pyobject import Py_DecRef, is_pyobj
 from pypy.module.cpyext.pyobject import make_ref, from_ref
-from pypy.module.cpyext.pyobject import Reference
 newargs = ()
 keepalives = ()
 assert len(args) == len(api_function.argtypes)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: More tweaks for bootstrapping

2016-01-26 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81966:dfc37d8a80f8
Date: 2016-01-27 01:17 +0100
http://bitbucket.org/pypy/pypy/changeset/dfc37d8a80f8/

Log:More tweaks for bootstrapping

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
@@ -5,7 +5,7 @@
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from pypy.module.cpyext.api import (
 cpython_api, bootstrap_function, PyObject, PyObjectP, ADDR,
-CANNOT_FAIL, Py_TPFLAGS_HEAPTYPE, PyTypeObjectPtr,
+CANNOT_FAIL, Py_TPFLAGS_HEAPTYPE, PyTypeObjectPtr, is_PyObject,
 INTERPLEVEL_API)
 from pypy.module.cpyext.state import State
 from pypy.objspace.std.typeobject import W_TypeObject
@@ -212,7 +212,7 @@
 assert is_pyobj(ref)
 if not ref:
 return None
-w_obj = rawrefcount.to_obj(W_Root, pyobj)
+w_obj = rawrefcount.to_obj(W_Root, ref)
 if w_obj is not None:
 return w_obj
 
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
@@ -324,9 +324,21 @@
 track_reference(space, py_type, space.w_type)
 type_attach(space, py_type, space.w_type)
 
+as_pyobj(space, space.w_str)
+as_pyobj(space, space.w_tuple)
+as_pyobj(space, space.w_object)
+
+delayed_types = []
 while space._cpyext_delay_type_creation:
-_type_really_attach(space, *space._cpyext_delay_type_creation.pop())
+(py_obj, w_type) = space._cpyext_delay_type_creation.pop()
+_type_really_attach(space, py_obj, w_type)
+delayed_types.append((py_obj, w_type))
 del space._cpyext_delay_type_creation
+for py_obj, w_type in delayed_types:
+pto = rffi.cast(PyTypeObjectPtr, py_obj)
+finish_type_1(space, pto)
+finish_type_2(space, pto, w_type)
+finish_type_3(space, pto, w_type)
 
 
 @cpython_api([PyObject], lltype.Void, external=False)
@@ -493,8 +505,9 @@
 py_base = make_ref(space, w_base)
 pto.c_tp_base = rffi.cast(PyTypeObjectPtr, py_base)
 
-finish_type_1(space, pto)
-finish_type_2(space, pto, w_type)
+if not hasattr(space, '_cpyext_delay_type_creation'):
+finish_type_1(space, pto)
+finish_type_2(space, pto, w_type)
 
 pto.c_tp_basicsize = rffi.sizeof(typedescr.basestruct)
 if pto.c_tp_base:
@@ -507,6 +520,12 @@
 pto.c_tp_new = rffi.cast(newfunc, 1)
 update_all_slots(space, w_type, pto)
 
+if not hasattr(space, '_cpyext_delay_type_creation'):
+finish_type_3(space, pto, w_type)
+
+pto.c_tp_flags |= Py_TPFLAGS_READY
+
+def finish_type_3(space, pto, w_type):
 if pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE:
 w_typename = space.getattr(w_type, space.wrap('__name__'))
 heaptype = rffi.cast(PyHeapTypeObject, pto)
@@ -516,8 +535,6 @@
 else:
 pto.c_tp_name = rffi.str2charp(w_type.name)
 
-pto.c_tp_flags |= Py_TPFLAGS_READY
-
 def py_type_ready(space, pto):
 if pto.c_tp_flags & Py_TPFLAGS_READY:
 return
@@ -608,8 +625,7 @@
 base = pto.c_tp_base
 base_pyo = rffi.cast(PyObject, pto.c_tp_base)
 if base and not base.c_tp_flags & Py_TPFLAGS_READY:
-if not hasattr(space, '_cpyext_delay_type_creation'):
-type_realize(space, rffi.cast(PyObject, base_pyo))
+type_realize(space, rffi.cast(PyObject, base_pyo))
 if base and not pto.c_ob_type: # will be filled later
 pto.c_ob_type = base.c_ob_type
 if not pto.c_tp_bases:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-bootstrap: A branch to simplify the bootstrapping, to reduce the amount of changes

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-bootstrap
Changeset: r81968:30bbc81f0b06
Date: 2016-01-27 13:42 +0100
http://bitbucket.org/pypy/pypy/changeset/30bbc81f0b06/

Log:A branch to simplify the bootstrapping, to reduce the amount of
changes in cpyext-gc-support-2

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-bootstrap: Kill kill kill the logic in init_typeobject(). It was anyway very

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-bootstrap
Changeset: r81969:3cd5ace97b49
Date: 2016-01-27 13:43 +0100
http://bitbucket.org/pypy/pypy/changeset/3cd5ace97b49/

Log:Kill kill kill the logic in init_typeobject(). It was anyway very
strange, because it would create "heap" type objects, initialize
them carefully, and then forget them happily by calling
track_reference() again (which would crash if DEBUG_REFCOUNT=True)

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -828,6 +828,9 @@
 space.fromcache(State).install_dll(eci)
 
 # populate static data
+from pypy.module.cpyext.pyobject import track_reference, get_typedescr
+from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
+to_attach = []
 for name, (typ, expr) in GLOBALS.iteritems():
 from pypy.module import cpyext
 w_obj = eval(expr)
@@ -861,18 +864,25 @@
 # we have a structure, get its address
 in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, 
name)
 py_obj = ll2ctypes.ctypes2lltype(PyObject, 
ctypes.pointer(in_dll))
-from pypy.module.cpyext.pyobject import (
-track_reference, get_typedescr)
-w_type = space.type(w_obj)
-typedescr = get_typedescr(w_type.instancetypedef)
 py_obj.c_ob_refcnt = 1
-py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
- make_ref(space, w_type))
-typedescr.attach(space, py_obj, w_obj)
 track_reference(space, py_obj, w_obj)
+to_attach.append((py_obj, w_obj))
 else:
 assert False, "Unknown static object: %s %s" % (typ, name)
 
+space._cpyext_type_init = []
+for py_obj, w_obj in to_attach:
+w_type = space.type(w_obj)
+typedescr = get_typedescr(w_type.instancetypedef)
+py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
+ make_ref(space, w_type))
+typedescr.attach(space, py_obj, w_obj)
+cpyext_type_init = space._cpyext_type_init
+del space._cpyext_type_init
+for pto, w_type in cpyext_type_init:
+finish_type_1(space, pto)
+finish_type_2(space, pto, w_type)
+
 pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
 
 # implement structure initialization code
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
@@ -310,55 +310,6 @@
realize=type_realize,
dealloc=type_dealloc)
 
-# some types are difficult to create because of cycles.
-# - object.ob_type = type
-# - type.ob_type   = type
-# - tuple.ob_type  = type
-# - type.tp_base   = object
-# - tuple.tp_base  = object
-# - type.tp_bases is a tuple
-# - object.tp_bases is a tuple
-# - tuple.tp_bases is a tuple
-
-# insert null placeholders to please create_ref()
-track_reference(space, lltype.nullptr(PyObject.TO), space.w_type)
-track_reference(space, lltype.nullptr(PyObject.TO), space.w_object)
-track_reference(space, lltype.nullptr(PyObject.TO), space.w_tuple)
-track_reference(space, lltype.nullptr(PyObject.TO), space.w_str)
-
-# create the objects
-py_type = create_ref(space, space.w_type)
-py_object = create_ref(space, space.w_object)
-py_tuple = create_ref(space, space.w_tuple)
-py_str = create_ref(space, space.w_str)
-# XXX py_str is not initialized here correctly, because we are
-# not tracking it, it gets an empty c_ob_type from py_basestring
-
-# form cycles
-pto_type = rffi.cast(PyTypeObjectPtr, py_type)
-py_type.c_ob_type = pto_type
-py_object.c_ob_type = pto_type
-py_tuple.c_ob_type = pto_type
-
-pto_object = rffi.cast(PyTypeObjectPtr, py_object)
-pto_type.c_tp_base = pto_object
-pto_tuple = rffi.cast(PyTypeObjectPtr, py_tuple)
-pto_tuple.c_tp_base = pto_object
-
-pto_type.c_tp_bases.c_ob_type = pto_tuple
-pto_object.c_tp_bases.c_ob_type = pto_tuple
-pto_tuple.c_tp_bases.c_ob_type = pto_tuple
-
-for typ in (py_type, py_object, py_tuple, py_str):
-heaptype = rffi.cast(PyHeapTypeObject, typ)
-heaptype.c_ht_name.c_ob_type = pto_type
-
-# Restore the mapping
-track_reference(space, py_type, space.w_type, replace=True)
-track_reference(space, py_object, space.w_object, replace=True)
-track_reference(space, py_tuple, space.w_tuple, replace=True)
-track_reference(space, py_str, space.w_str, replace=True)
-
 
 @cpython_api([PyObject], lltype.Void, external=False)
 def subtype_dealloc(space, obj):
@@ -520,8 +471,11 @@
 w_base = best_base(space, w_type.bases_w)
 pto.c_tp_base = rffi.cast(PyTypeObjectPtr, make_ref(space, w_base))
 
-finish_type_1(spac

[pypy-commit] pypy default: Add "-m ensurepip"

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r81970:4974d1173ac2
Date: 2016-01-27 14:26 +0100
http://bitbucket.org/pypy/pypy/changeset/4974d1173ac2/

Log:Add "-m ensurepip"

diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -54,7 +54,8 @@
 It is quite common nowadays that xyz is available on PyPI_ and
 installable with ``pip install xyz``.  The simplest solution is to `use
 virtualenv (as documented here)`_.  Then enter (activate) the virtualenv
-and type: ``pip install xyz``.
+and type: ``pip install xyz``.  If you don't know or don't want virtualenv,
+you can also install ``pip`` globally by saying ``pypy -m ensurepip``.
 
 If you get errors from the C compiler, the module is a CPython C
 Extension module using unsupported features.  `See below.`_
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-bootstrap: pfff, took me a while to figure out that memory corruption was going on here:

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-bootstrap
Changeset: r81971:ed11e491b6c2
Date: 2016-01-27 14:50 +0100
http://bitbucket.org/pypy/pypy/changeset/ed11e491b6c2/

Log:pfff, took me a while to figure out that memory corruption was going
on here: the globals False/True would be initialized as longs by
writing 0/1 in the third word of memory, but they were only 2-words
PyObjects...

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -442,8 +442,8 @@
 TYPES = {}
 GLOBALS = { # this needs to include all prebuilt pto, otherwise segfaults occur
 '_Py_NoneStruct#': ('PyObject*', 'space.w_None'),
-'_Py_TrueStruct#': ('PyObject*', 'space.w_True'),
-'_Py_ZeroStruct#': ('PyObject*', 'space.w_False'),
+'_Py_TrueStruct#': ('PyIntObject*', 'space.w_True'),
+'_Py_ZeroStruct#': ('PyIntObject*', 'space.w_False'),
 '_Py_NotImplementedStruct#': ('PyObject*', 'space.w_NotImplemented'),
 '_Py_EllipsisObject#': ('PyObject*', 'space.w_Ellipsis'),
 'PyDateTimeAPI': ('PyDateTime_CAPI*', 'None'),
@@ -855,7 +855,7 @@
 assert False, "Unknown static pointer: %s %s" % (typ, name)
 ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
 ctypes.c_void_p).value
-elif typ in ('PyObject*', 'PyTypeObject*'):
+elif typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*'):
 if name.startswith('PyPyExc_') or 
name.startswith('cpyexttestExc_'):
 # we already have the pointer
 in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, 
name)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-bootstrap: This test checks a condition which is actually not true, but which

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-bootstrap
Changeset: r81972:dd3a1abe4374
Date: 2016-01-27 16:35 +0100
http://bitbucket.org/pypy/pypy/changeset/dd3a1abe4374/

Log:This test checks a condition which is actually not true, but which
happened to be true due to the two versions of some PyTypeObjects
which this branch removes. The condition is false e.g. after
translation anyway.

diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -374,6 +374,11 @@
 module = self.import_extension('foo', [
 ("test_type", "METH_O",
  '''
+ /* "args->ob_type" is a strange way to get at 'type',
+which should have a different tp_getattro/tp_setattro
+than its tp_base, which is 'object'.
+  */
+  
  if (!args->ob_type->tp_setattro)
  {
  PyErr_SetString(PyExc_ValueError, "missing tp_setattro");
@@ -382,8 +387,12 @@
  if (args->ob_type->tp_setattro ==
  args->ob_type->tp_base->tp_setattro)
  {
- PyErr_SetString(PyExc_ValueError, "recursive 
tp_setattro");
- return NULL;
+ /* Note that unlike CPython, in PyPy 'type.tp_setattro'
+is the same function as 'object.tp_setattro'.  This
+test used to check that it was not, but that was an
+artifact of the bootstrap logic only---in the final
+C sources I checked and they are indeed the same.
+So we ignore this problem here. */
  }
  if (!args->ob_type->tp_getattro)
  {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-bootstrap: Attempt to fix translation, getting segfault while translating now

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-bootstrap
Changeset: r81973:036fa7ebc766
Date: 2016-01-27 17:03 +0100
http://bitbucket.org/pypy/pypy/changeset/036fa7ebc766/

Log:Attempt to fix translation, getting segfault while translating now

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -828,9 +828,7 @@
 space.fromcache(State).install_dll(eci)
 
 # populate static data
-from pypy.module.cpyext.pyobject import track_reference, get_typedescr
-from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
-to_attach = []
+builder = StaticObjectBuilder(space)
 for name, (typ, expr) in GLOBALS.iteritems():
 from pypy.module import cpyext
 w_obj = eval(expr)
@@ -864,24 +862,10 @@
 # we have a structure, get its address
 in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, 
name)
 py_obj = ll2ctypes.ctypes2lltype(PyObject, 
ctypes.pointer(in_dll))
-py_obj.c_ob_refcnt = 1
-track_reference(space, py_obj, w_obj)
-to_attach.append((py_obj, w_obj))
+builder.prepare(py_obj, w_obj)
 else:
 assert False, "Unknown static object: %s %s" % (typ, name)
-
-space._cpyext_type_init = []
-for py_obj, w_obj in to_attach:
-w_type = space.type(w_obj)
-typedescr = get_typedescr(w_type.instancetypedef)
-py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
- make_ref(space, w_type))
-typedescr.attach(space, py_obj, w_obj)
-cpyext_type_init = space._cpyext_type_init
-del space._cpyext_type_init
-for pto, w_type in cpyext_type_init:
-finish_type_1(space, pto)
-finish_type_2(space, pto, w_type)
+builder.attach_all()
 
 pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
 
@@ -898,6 +882,36 @@
 setup_init_functions(eci, translating=False)
 return modulename.new(ext='')
 
+
+class StaticObjectBuilder:
+def __init__(self, space):
+self.space = space
+self.to_attach = []
+
+def prepare(self, py_obj, w_obj):
+from pypy.module.cpyext.pyobject import track_reference
+py_obj.c_ob_refcnt = 1
+track_reference(self.space, py_obj, w_obj)
+self.to_attach.append((py_obj, w_obj))
+
+def attach_all(self):
+from pypy.module.cpyext.pyobject import get_typedescr, make_ref
+from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
+space = self.space
+space._cpyext_type_init = []
+for py_obj, w_obj in self.to_attach:
+w_type = space.type(w_obj)
+typedescr = get_typedescr(w_type.instancetypedef)
+py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
+ make_ref(space, w_type))
+typedescr.attach(space, py_obj, w_obj)
+cpyext_type_init = space._cpyext_type_init
+del space._cpyext_type_init
+for pto, w_type in cpyext_type_init:
+finish_type_1(space, pto)
+finish_type_2(space, pto, w_type)
+
+
 def mangle_name(prefix, name):
 if name.startswith('Py'):
 return prefix + name[2:]
@@ -1074,7 +1088,7 @@
 
 def setup_library(space):
 "NOT_RPYTHON"
-from pypy.module.cpyext.pyobject import make_ref
+from pypy.module.cpyext.pyobject import get_typedescr, make_ref
 
 export_symbols = list(FUNCTIONS) + SYMBOLS_C + list(GLOBALS)
 from rpython.translator.c.database import LowLevelDatabase
@@ -1092,14 +1106,36 @@
 run_bootstrap_functions(space)
 setup_va_functions(eci)
 
+from pypy.module import cpyext   # for eval() below
+
+# Set up the types.  This version of the code really allocates
+# them: this is different from build_bridge(), where they are set
+# up at the static address from the bridge library.  This needs
+# special logic to solve the cycles issue; otherwise, we could
+# simply leave everything to make_ref() in the "populate static
+# data" loop below.
+builder = StaticObjectBuilder(space)
+for name, (typ, expr) in GLOBALS.iteritems():
+if typ == 'PyTypeObject*':
+w_type = eval(expr)
+w_typetype = space.type(w_type)
+if not space.is_w(w_typetype, space.w_type):
+continue # skip types with a custom metaclass
+typedescr = get_typedescr(w_typetype.instancetypedef)
+py_obj = typedescr.allocate(space, None)
+builder.prepare(py_obj, w_type)
+py_typetype = rffi.cast(PyTypeObjectPtr, make_ref(space, space.w_type))
+for py_obj, w_type in builder.to_attach:
+py_obj.c_ob_type = py_typetype
+builder.attach_all()
+
 # populate static data
 for name, (typ, expr) in GLOBALS.iteritems():
 name = name.replace("#", "")
 if name.startswith('PyExc_')

[pypy-commit] pypy cpyext-bootstrap: Some translation fixes

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-bootstrap
Changeset: r81974:a11965258086
Date: 2016-01-27 17:39 +0100
http://bitbucket.org/pypy/pypy/changeset/a11965258086/

Log:Some translation fixes

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -506,7 +506,9 @@
 def get_structtype_for_ctype(ctype):
 from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
 from pypy.module.cpyext.cdatetime import PyDateTime_CAPI
+from pypy.module.cpyext.intobject import PyIntObject
 return {"PyObject*": PyObject, "PyTypeObject*": PyTypeObjectPtr,
+"PyIntObject*": PyIntObject,
 "PyDateTime_CAPI*": lltype.Ptr(PyDateTime_CAPI)}[ctype]
 
 PyTypeObject = lltype.ForwardReference()
@@ -1088,7 +1090,7 @@
 
 def setup_library(space):
 "NOT_RPYTHON"
-from pypy.module.cpyext.pyobject import get_typedescr, make_ref
+from pypy.module.cpyext.pyobject import make_ref
 
 export_symbols = list(FUNCTIONS) + SYMBOLS_C + list(GLOBALS)
 from rpython.translator.c.database import LowLevelDatabase
@@ -1108,25 +1110,22 @@
 
 from pypy.module import cpyext   # for eval() below
 
-# Set up the types.  This version of the code really allocates
-# them: this is different from build_bridge(), where they are set
-# up at the static address from the bridge library.  This needs
-# special logic to solve the cycles issue; otherwise, we could
-# simply leave everything to make_ref() in the "populate static
-# data" loop below.
+# Set up the types.  Needs a special case, because of the
+# immediate cycle involving 'c_ob_type', and because we don't
+# want these types to be Py_TPFLAGS_HEAPTYPE.
+static_types = {}
+for name, (typ, expr) in GLOBALS.items():
+if typ == 'PyTypeObject*':
+pto = lltype.malloc(PyTypeObject, immortal=True,
+zero=True, flavor='raw')
+pto.c_ob_refcnt = 1
+pto.c_tp_basicsize = -1
+static_types[name] = pto
 builder = StaticObjectBuilder(space)
-for name, (typ, expr) in GLOBALS.iteritems():
-if typ == 'PyTypeObject*':
-w_type = eval(expr)
-w_typetype = space.type(w_type)
-if not space.is_w(w_typetype, space.w_type):
-continue # skip types with a custom metaclass
-typedescr = get_typedescr(w_typetype.instancetypedef)
-py_obj = typedescr.allocate(space, None)
-builder.prepare(py_obj, w_type)
-py_typetype = rffi.cast(PyTypeObjectPtr, make_ref(space, space.w_type))
-for py_obj, w_type in builder.to_attach:
-py_obj.c_ob_type = py_typetype
+for name, pto in static_types.items():
+pto.c_ob_type = static_types['PyType_Type#']
+w_type = eval(GLOBALS[name][1])
+builder.prepare(rffi.cast(PyObject, pto), w_type)
 builder.attach_all()
 
 # populate static data
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
@@ -146,7 +146,7 @@
 assert len(slot_names) == 2
 struct = getattr(pto, slot_names[0])
 if not struct:
-assert not space.config.translating
+#assert not space.config.translating
 assert not pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE
 if slot_names[0] == 'c_tp_as_number':
 STRUCT_TYPE = PyNumberMethods
@@ -427,6 +427,8 @@
 pto.c_tp_as_sequence = heaptype.c_as_sequence
 pto.c_tp_as_mapping = heaptype.c_as_mapping
 pto.c_tp_as_buffer = heaptype.c_as_buffer
+pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
+pto.c_tp_itemsize = 0
 
 return rffi.cast(PyObject, heaptype)
 
@@ -462,8 +464,6 @@
 pto.c_tp_name = PyString_AsString(space, heaptype.c_ht_name)
 else:
 pto.c_tp_name = rffi.str2charp(w_type.name)
-pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
-pto.c_tp_itemsize = 0
 # uninitialized fields:
 # c_tp_print, c_tp_getattr, c_tp_setattr
 # XXX implement
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: cpyext implies micronumpy, otherwise we get never-initialized ndarray subclasses

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r81975:ec6457a2d845
Date: 2016-01-27 18:05 +0100
http://bitbucket.org/pypy/pypy/changeset/ec6457a2d845/

Log:cpyext implies micronumpy, otherwise we get never-initialized
ndarray subclasses

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -85,7 +85,8 @@
 module_dependencies = {
 '_multiprocessing': [('objspace.usemodules.time', True),
  ('objspace.usemodules.thread', True)],
-'cpyext': [('objspace.usemodules.array', True)],
+'cpyext': [('objspace.usemodules.array', True),
+   ('objspace.usemodules.micronumpy', True)],
 'cppyy': [('objspace.usemodules.cpyext', True)],
 }
 module_suggests = {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: hg merge cpyext-bootstrap

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r81977:7d1a37bf041c
Date: 2016-01-27 19:02 +0100
http://bitbucket.org/pypy/pypy/changeset/7d1a37bf041c/

Log:hg merge cpyext-bootstrap

simplify the bootstrap procedure, which was a bit manual and
slightly buggy (e.g. untranslated, it made two versions of the same
PyTypeObjects; and translated, the type objects ends up with
Py_TPFLAGS_HEAPTYPE, even though they should not be).

also fixes a potential memory corruption for initializing boolean
objects.

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -442,8 +442,8 @@
 TYPES = {}
 GLOBALS = { # this needs to include all prebuilt pto, otherwise segfaults occur
 '_Py_NoneStruct#': ('PyObject*', 'space.w_None'),
-'_Py_TrueStruct#': ('PyObject*', 'space.w_True'),
-'_Py_ZeroStruct#': ('PyObject*', 'space.w_False'),
+'_Py_TrueStruct#': ('PyIntObject*', 'space.w_True'),
+'_Py_ZeroStruct#': ('PyIntObject*', 'space.w_False'),
 '_Py_NotImplementedStruct#': ('PyObject*', 'space.w_NotImplemented'),
 '_Py_EllipsisObject#': ('PyObject*', 'space.w_Ellipsis'),
 'PyDateTimeAPI': ('PyDateTime_CAPI*', 'None'),
@@ -506,7 +506,9 @@
 def get_structtype_for_ctype(ctype):
 from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
 from pypy.module.cpyext.cdatetime import PyDateTime_CAPI
+from pypy.module.cpyext.intobject import PyIntObject
 return {"PyObject*": PyObject, "PyTypeObject*": PyTypeObjectPtr,
+"PyIntObject*": PyIntObject,
 "PyDateTime_CAPI*": lltype.Ptr(PyDateTime_CAPI)}[ctype]
 
 PyTypeObject = lltype.ForwardReference()
@@ -828,6 +830,7 @@
 space.fromcache(State).install_dll(eci)
 
 # populate static data
+builder = StaticObjectBuilder(space)
 for name, (typ, expr) in GLOBALS.iteritems():
 from pypy.module import cpyext
 w_obj = eval(expr)
@@ -852,7 +855,7 @@
 assert False, "Unknown static pointer: %s %s" % (typ, name)
 ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
 ctypes.c_void_p).value
-elif typ in ('PyObject*', 'PyTypeObject*'):
+elif typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*'):
 if name.startswith('PyPyExc_') or 
name.startswith('cpyexttestExc_'):
 # we already have the pointer
 in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, 
name)
@@ -861,17 +864,10 @@
 # we have a structure, get its address
 in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, 
name)
 py_obj = ll2ctypes.ctypes2lltype(PyObject, 
ctypes.pointer(in_dll))
-from pypy.module.cpyext.pyobject import (
-track_reference, get_typedescr)
-w_type = space.type(w_obj)
-typedescr = get_typedescr(w_type.instancetypedef)
-py_obj.c_ob_refcnt = 1
-py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
- make_ref(space, w_type))
-typedescr.attach(space, py_obj, w_obj)
-track_reference(space, py_obj, w_obj)
+builder.prepare(py_obj, w_obj)
 else:
 assert False, "Unknown static object: %s %s" % (typ, name)
+builder.attach_all()
 
 pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
 
@@ -888,6 +884,36 @@
 setup_init_functions(eci, translating=False)
 return modulename.new(ext='')
 
+
+class StaticObjectBuilder:
+def __init__(self, space):
+self.space = space
+self.to_attach = []
+
+def prepare(self, py_obj, w_obj):
+from pypy.module.cpyext.pyobject import track_reference
+py_obj.c_ob_refcnt = 1
+track_reference(self.space, py_obj, w_obj)
+self.to_attach.append((py_obj, w_obj))
+
+def attach_all(self):
+from pypy.module.cpyext.pyobject import get_typedescr, make_ref
+from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
+space = self.space
+space._cpyext_type_init = []
+for py_obj, w_obj in self.to_attach:
+w_type = space.type(w_obj)
+typedescr = get_typedescr(w_type.instancetypedef)
+py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
+ make_ref(space, w_type))
+typedescr.attach(space, py_obj, w_obj)
+cpyext_type_init = space._cpyext_type_init
+del space._cpyext_type_init
+for pto, w_type in cpyext_type_init:
+finish_type_1(space, pto)
+finish_type_2(space, pto, w_type)
+
+
 def mangle_name(prefix, name):
 if name.startswith('Py'):
 return prefix + name[2:]
@@ -1082,14 +1108,33 @@
 run_bootstrap_functions(space)
 setup_va_functions(eci)
 
+from pypy.module import cpyext 

[pypy-commit] pypy cpyext-bootstrap: Seems to work, merging

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-bootstrap
Changeset: r81976:0fac859d23a0
Date: 2016-01-27 18:58 +0100
http://bitbucket.org/pypy/pypy/changeset/0fac859d23a0/

Log:Seems to work, merging

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: hg merge default

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81979:1fc97a564c99
Date: 2016-01-27 19:12 +0100
http://bitbucket.org/pypy/pypy/changeset/1fc97a564c99/

Log:hg merge default

diff too long, truncating to 2000 out of 4461 lines

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -85,7 +85,8 @@
 module_dependencies = {
 '_multiprocessing': [('objspace.usemodules.time', True),
  ('objspace.usemodules.thread', True)],
-'cpyext': [('objspace.usemodules.array', True)],
+'cpyext': [('objspace.usemodules.array', True),
+   ('objspace.usemodules.micronumpy', True)],
 'cppyy': [('objspace.usemodules.cpyext', True)],
 }
 module_suggests = {
diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -54,7 +54,8 @@
 It is quite common nowadays that xyz is available on PyPI_ and
 installable with ``pip install xyz``.  The simplest solution is to `use
 virtualenv (as documented here)`_.  Then enter (activate) the virtualenv
-and type: ``pip install xyz``.
+and type: ``pip install xyz``.  If you don't know or don't want virtualenv,
+you can also install ``pip`` globally by saying ``pypy -m ensurepip``.
 
 If you get errors from the C compiler, the module is a CPython C
 Extension module using unsupported features.  `See below.`_
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -123,3 +123,13 @@
 .. branch: fix-cpython-ssl-tests-2.7
 
 Fix SSL tests by importing cpython's patch
+
+.. branch: remove-getfield-pure
+
+Remove pure variants of ``getfield_gc_*`` operations from the JIT. Relevant
+optimizations instead consult the field descriptor to determine the purity of
+the operation. Additionally, pure ``getfield`` operations are now handled
+entirely by `rpython/jit/metainterp/optimizeopt/heap.py` rather than
+`rpython/jit/metainterp/optimizeopt/pure.py`, which can result in better 
codegen
+for traces containing a large number of pure getfield operations.
+
diff --git a/pypy/module/cpyext/Doc_stubgen_enable.patch 
b/pypy/module/cpyext/Doc_stubgen_enable.patch
deleted file mode 100644
--- a/pypy/module/cpyext/Doc_stubgen_enable.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-Index: Doc/tools/sphinx/ext/refcounting.py
-===
 Doc/tools/sphinx/ext/refcounting.py(Revision 79453)
-+++ Doc/tools/sphinx/ext/refcounting.py(Arbeitskopie)
-@@ -91,6 +91,7 @@
- if app.config.refcount_file:
- refcounts = Refcounts.fromfile(
- path.join(app.srcdir, app.config.refcount_file))
-+app._refcounts = refcounts
- app.connect('doctree-read', refcounts.add_refcount_annotations)
- 
- 
-Index: Doc/conf.py
-===
 Doc/conf.py(Revision 79421)
-+++ Doc/conf.py(Arbeitskopie)
-@@ -13,8 +13,8 @@
- # General configuration
- # -
- 
--extensions = ['sphinx.ext.refcounting', 'sphinx.ext.coverage',
--  'sphinx.ext.doctest', 'pyspecific']
-+extensions = ['pypy.module.cpyext.stubgen', 'sphinx.ext.refcounting', 
'sphinx.ext.coverage',
-+  'sphinx.ext.doctest', 'pyspecific', ]
- templates_path = ['tools/sphinxext']
- 
- # General substitutions.
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -441,8 +441,8 @@
 TYPES = {}
 GLOBALS = { # this needs to include all prebuilt pto, otherwise segfaults occur
 '_Py_NoneStruct#': ('PyObject*', 'space.w_None'),
-'_Py_TrueStruct#': ('PyObject*', 'space.w_True'),
-'_Py_ZeroStruct#': ('PyObject*', 'space.w_False'),
+'_Py_TrueStruct#': ('PyIntObject*', 'space.w_True'),
+'_Py_ZeroStruct#': ('PyIntObject*', 'space.w_False'),
 '_Py_NotImplementedStruct#': ('PyObject*', 'space.w_NotImplemented'),
 '_Py_EllipsisObject#': ('PyObject*', 'space.w_Ellipsis'),
 'PyDateTimeAPI': ('PyDateTime_CAPI*', 'None'),
@@ -505,7 +505,9 @@
 def get_structtype_for_ctype(ctype):
 from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
 from pypy.module.cpyext.cdatetime import PyDateTime_CAPI
+from pypy.module.cpyext.intobject import PyIntObject
 return {"PyObject*": PyObject, "PyTypeObject*": PyTypeObjectPtr,
+"PyIntObject*": PyIntObject,
 "PyDateTime_CAPI*": lltype.Ptr(PyDateTime_CAPI)}[ctype]
 
 # Note: as a special case, "PyObject" is the pointer type in RPython,
@@ -846,6 +848,7 @@
 space.fromcache(State).install_dll(eci)
 
 # populate static data
+builder = StaticObjectBuilder(space)
 for name, (typ, expr) in GLOBALS.iteritems():
 from pypy.module import cpyext# for the eval() below
 w_obj = eval(expr)
@@ -870,7 +873,7 @@
 as

[pypy-commit] pypy default: ignore branch

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r81978:5edae6a9f5e3
Date: 2016-01-27 19:10 +0100
http://bitbucket.org/pypy/pypy/changeset/5edae6a9f5e3/

Log:ignore branch

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -133,3 +133,4 @@
 `rpython/jit/metainterp/optimizeopt/pure.py`, which can result in better 
codegen
 for traces containing a large number of pure getfield operations.
 
+.. branch: cpyext-bootstrap
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81980:4f7fc4ae3711
Date: 2016-01-27 19:14 +0100
http://bitbucket.org/pypy/pypy/changeset/4f7fc4ae3711/

Log:fix

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -291,7 +291,7 @@
 @specialize.ll()
 def unwrapper(space, *args):
 from pypy.module.cpyext.pyobject import Py_DecRef, is_pyobj
-from pypy.module.cpyext.pyobject import make_ref, from_ref
+from pypy.module.cpyext.pyobject import from_ref, as_pyobj
 newargs = ()
 keepalives = ()
 assert len(args) == len(api_function.argtypes)
@@ -301,7 +301,7 @@
 # build a 'PyObject *' (not holding a reference)
 if not is_pyobj(input_arg):
 keepalives += (input_arg,)
-arg = rffi.cast(ARG, as_xpyobj(space, input_arg))
+arg = rffi.cast(ARG, as_pyobj(space, input_arg))
 else:
 arg = rffi.cast(ARG, input_arg)
 elif is_PyObject(ARG) and is_wrapped:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: yay, test_api passes

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81981:a3c663eba7c9
Date: 2016-01-27 19:21 +0100
http://bitbucket.org/pypy/pypy/changeset/a3c663eba7c9/

Log:yay, test_api passes

diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -80,12 +80,11 @@
 
 from pypy.module.cpyext.typeobject import setup_new_method_def
 from pypy.module.cpyext.api import INIT_FUNCTIONS
-from pypy.module.cpyext.api import init_static_data_translated
 
 if we_are_translated():
 rawrefcount.init(llhelper(rawrefcount.RAWREFCOUNT_DEALLOC_TRIGGER,
   self.dealloc_trigger))
-init_static_data_translated(space)
+XXX#init_static_data_translated(space)
 
 setup_new_method_def(space)
 
diff --git a/pypy/module/cpyext/test/test_api.py 
b/pypy/module/cpyext/test/test_api.py
--- a/pypy/module/cpyext/test/test_api.py
+++ b/pypy/module/cpyext/test/test_api.py
@@ -53,7 +53,6 @@
 return state.clear_exception()
 
 def setup_method(self, func):
-#return   # ZZZ
 freeze_refcnts(self)
 
 def teardown_method(self, func):
diff --git a/pypy/module/cpyext/test/test_cpyext.py 
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -14,7 +14,7 @@
 from rpython.tool.udir import udir
 from pypy.module.cpyext import api
 from pypy.module.cpyext.state import State
-from pypy.module.cpyext.pyobject import RefcountState
+from pypy.module.cpyext.pyobject import debug_collect
 from pypy.module.cpyext.pyobject import Py_DecRef, InvalidPointerException
 from rpython.tool.identity_dict import identity_dict
 from rpython.tool import leakfinder
@@ -92,6 +92,7 @@
 return str(pydname)
 
 def freeze_refcnts(self):
+return #ZZZ
 state = self.space.fromcache(RefcountState)
 self.frozen_refcounts = {}
 for w_obj, obj in state.py_objects_w2r.iteritems():
@@ -109,6 +110,7 @@
 
 @staticmethod
 def cleanup_references(space):
+return #ZZZ
 state = space.fromcache(RefcountState)
 
 import gc; gc.collect()
@@ -127,6 +129,8 @@
 state.reset_borrowed_references()
 
 def check_and_print_leaks(self):
+debug_collect()
+return #ZZZ
 # check for sane refcnts
 import gc
 
@@ -212,8 +216,8 @@
 cls.space.getbuiltinmodule("cpyext")
 from pypy.module.imp.importing import importhook
 importhook(cls.space, "os") # warm up reference counts
-state = cls.space.fromcache(RefcountState)
-state.non_heaptypes_w[:] = []
+#state = cls.space.fromcache(RefcountState) ZZZ
+#state.non_heaptypes_w[:] = []
 
 def setup_method(self, func):
 @unwrap_spec(name=str)
@@ -348,7 +352,7 @@
 interp2app(record_imported_module))
 self.w_here = self.space.wrap(
 str(py.path.local(pypydir)) + '/module/cpyext/test/')
-
+self.w_debug_collect = self.space.wrap(interp2app(debug_collect))
 
 # create the file lock before we count allocations
 self.space.call_method(self.space.sys.get("stdout"), "flush")
@@ -647,7 +651,7 @@
 Py_DECREF(true_obj);
 Py_DECREF(true_obj);
 fprintf(stderr, "REFCNT %i %i\\n", refcnt, refcnt_after);
-return PyBool_FromLong(refcnt_after == refcnt+2 && refcnt < 3);
+return PyBool_FromLong(refcnt_after == refcnt + 2);
 }
 static PyObject* foo_bar(PyObject* self, PyObject *args)
 {
@@ -662,8 +666,10 @@
 return NULL;
 refcnt_after = true_obj->ob_refcnt;
 Py_DECREF(tup);
-fprintf(stderr, "REFCNT2 %i %i\\n", refcnt, refcnt_after);
-return PyBool_FromLong(refcnt_after == refcnt);
+fprintf(stderr, "REFCNT2 %i %i %i\\n", refcnt, refcnt_after,
+true_obj->ob_refcnt);
+return PyBool_FromLong(refcnt_after == refcnt + 1 &&
+   refcnt == true_obj->ob_refcnt);
 }
 
 static PyMethodDef methods[] = {
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
@@ -568,9 +568,6 @@
 
 finish_type_2(space, py_type, w_obj)
 
-state = space.fromcache(RefcountState)
-state.non_heaptypes_w.append(w_obj)
-
 return w_obj
 
 def finish_type_1(space, pto):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: Mention the "@pypy-4.0.1" part of the url

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r697:848d8a627c0e
Date: 2016-01-27 20:16 +0100
http://bitbucket.org/pypy/pypy.org/changeset/848d8a627c0e/

Log:Mention the "@pypy-4.0.1" part of the url

diff --git a/download.html b/download.html
--- a/download.html
+++ b/download.html
@@ -214,7 +214,10 @@
 If you have pip:
 
 pypy -m pip install git+https://bitbucket.org/pypy/numpy.git
+pypy -m pip install git+https://bitbucket.org/pypy/numpy.git@pypy-4.0.1
 
+(the second version selects a particular tag, which may be needed if your
+pypy is not the latest development version.)
 Alternatively, the direct way:
 
 git clone https://bitbucket.org/pypy/numpy.git
diff --git a/source/download.txt b/source/download.txt
--- a/source/download.txt
+++ b/source/download.txt
@@ -225,6 +225,10 @@
 If you have pip::
 
 pypy -m pip install git+https://bitbucket.org/pypy/numpy.git
+pypy -m pip install git+https://bitbucket.org/pypy/numpy.git@pypy-4.0.1
+
+(the second version selects a particular tag, which may be needed if your
+pypy is not the latest development version.)
 
 Alternatively, the direct way::
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Add a comment (thanks ronan)

2016-01-27 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r81984:97395b8025f0
Date: 2016-01-27 20:48 +0100
http://bitbucket.org/pypy/pypy/changeset/97395b8025f0/

Log:Add a comment (thanks ronan)

diff --git a/rpython/rlib/rawrefcount.py b/rpython/rlib/rawrefcount.py
--- a/rpython/rlib/rawrefcount.py
+++ b/rpython/rlib/rawrefcount.py
@@ -1,6 +1,9 @@
 #
 #  See documentation in pypy/doc/discussion/rawrefcount.rst
 #
+#  This is meant for pypy's cpyext module, but is a generally
+#  useful interface over our GC.  XXX "pypy" should be removed here
+#
 import sys, weakref
 from rpython.rtyper.lltypesystem import lltype, llmemory
 from rpython.rlib.objectmodel import we_are_translated, specialize
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: Slides

2016-01-29 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5597:a7b5322ad0b4
Date: 2016-01-29 21:51 +0100
http://bitbucket.org/pypy/extradoc/changeset/a7b5322ad0b4/

Log:Slides

diff --git a/talk/fosdem2016/slides b/talk/fosdem2016/slides
new file mode 100644
--- /dev/null
+++ b/talk/fosdem2016/slides
@@ -0,0 +1,405 @@
+=
+CFFI and PyPy
+=
+
+
+CFFI
+
+
+* successful project according to PyPI
+
+* 3.4 million downloads last month
+
+* total 19.2 millions, 27th place on `pypi-ranking.info`
+
+  - Django is 28th
+
+* some high-visibility projects have switched to it (Cryptography)
+
+
+PyPy
+
+
+* harder to say, but probably not so successful
+
+* more later
+
+
+CFFI
+
+
+
+
+CFFI
+
+
+* call C from Python
+
+* CFFI = C Foreign Function Interface
+
+* shares ideas from Cython, ctypes, and LuaJIT's FFI
+
+
+CFFI demo
+=
+
+::
+
+  $ man getpwuid
+
+  SYNOPSIS
+ #include 
+ #include 
+
+ struct passwd *getpwnam(const char *name);
+
+
+CFFI demo
+=
+
+::
+
+   .
+   .
+   .
+   The passwd structure is defined in  as follows:
+
+   struct passwd {
+   char   *pw_name;   /* username */
+   char   *pw_passwd; /* user password */
+   uid_t   pw_uid;/* user ID */
+   .
+   .
+   .
+
+
+CFFI demo
+=
+
+::
+
+  from cffi import FFI
+  ffi = cffi.FFI()
+
+  ffi.cdef("""
+  typedef int... uid_t;
+  struct passwd {
+  uid_t pw_uid;
+  ...;
+  };
+  struct passwd *getpwnam(const char *name);
+  """)
+
+
+CFFI demo
+=
+
+::
+
+  ffi.set_source("_pwuid_cffi", """
+  #include 
+  #include 
+  """)
+
+  ffi.compile()
+
+--- ^^ put that in pwuid_build.py
+
+
+CFFI demo
+=
+
+::
+
+  python pwuid_build.py
+
+creates ``_pwuid_cffi.so``
+
+
+CFFI demo
+=
+
+::
+
+  from _pwuid_cffi import lib
+
+  print lib.getpwnam("arigo").pw_uid
+
+
+CFFI demo
+=
+
+::
+
+  from _pwuid_cffi import ffi, lib
+
+* ``lib`` gives access to all functions from the cdef
+
+* ``ffi`` gives access to a few general helpers, e.g.
+
+   - ``ffi.cast("float", 42)``
+
+   - ``p = ffi.new("struct passwd *")``
+
+   - ``p = ffi.new("char[10]"); p[0] = 'X'; s = lib.getpwnam(p)``
+
+   - ``p = ffi.new_handle(random_obj); ...; random_obj = ffi.from_handle(p)``
+
+
+CFFI
+
+
+* supports more or less the whole C
+
+* there is more than my short explanation suggests
+
+* read the docs: http://cffi.readthedocs.org/
+
+
+
+PyPy
+
+
+
+PyPy
+
+
+* a Python interpreter
+
+* different from the standard, which is CPython
+
+* main goal of PyPy: speed
+
+
+PyPy
+
+
+::
+
+$ pypy
+
+Python 2.7.10 (5f8302b8bf9f, Nov 18 2015, 10:46:46)
+[PyPy 4.0.1 with GCC 4.8.4] on linux2
+Type "help", "copyright", "credits" or "license" for more information.
+>>>> 2+3
+5
+>>>>
+
+
+PyPy
+
+
+* run ``pypy my_program.py``
+
+* starts working like an interpreter
+
+* then a Just-in-Time Compiler kicks in
+
+* generate and execute machine code from the Python program
+
+* good or great speed-ups for the majority of long-running code
+
+
+PyPy
+
+
+* different techniques than CPython also for "garbage collection"
+
+* works very well (arguably better than CPython's reference counting)
+
+
+PyPy: Garbage Collection
+
+
+* "**moving,** generational, incremental GC"
+
+* objects don't have reference counters
+
+* allocated in a "nursery"
+
+* when nursery full, find surviving nursery objects and move them out
+
+* usually work on nursery objects only (fast), but rarely also perform
+  a full GC
+
+
+PyPy: C extensions
+==
+
+* PyPy works great for running Python
+
+* less great when there are CPython C extension modules involved
+
+
+PyPy: C extensions
+==
+
+* not directly possible: we have moving, non-reference-counted objects,
+  and the C code expects non-moving, reference-counted objects
+
+
+PyPy: C extensions
+==
+
+* PyPy has still some support for them, called its ``cpyext`` module
+
+* similar to IronPython's Ironclad
+
+* emulate all objects for C extensions with a shadow, non-movable,
+  reference-counted object
+
+
+PyPy: C extensions
+==
+
+* ``cpyext`` is slow
+
+* ``cpyext`` is actually *really, really* slow
+
+  - but we're working on making it *only* slow
+
+
+PyPy: C extensions
+==
+
+* ``cpyext`` will "often" work, but there are a some high-profile C
+  extension modules that are not supported so far
+
+* notably, ``numpy``
+
+* (it is future work)
+
+
+PyPy: ad
+
+
+* but, hey, if you need performance out of Python and do

[pypy-commit] pypy.org extradoc: Add a warning: pypy3 is slow and old

2016-01-30 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r698:d5286b71511a
Date: 2016-01-30 15:40 +0100
http://bitbucket.org/pypy/pypy.org/changeset/d5286b71511a/

Log:Add a warning: pypy3 is slow and old

diff --git a/download.html b/download.html
--- a/download.html
+++ b/download.html
@@ -134,6 +134,9 @@
 
 
 Python 3.2.5 compatible PyPy3 2.4.0
+Warning: this is (1) based on an old release of PyPy, 
and (2) only
+supporting the Python 3.2 language.  It's also known to be
+(sometimes much) slower than PyPy 2.
 
 https://bitbucket.org/pypy/pypy/downloads/pypy3-2.4.0-linux.tar.bz2";>Linux
 x86 binary (32bit, tar.bz2 built on Ubuntu 10.04.4 LTS) (see [1] below)
 https://bitbucket.org/pypy/pypy/downloads/pypy3-2.4.0-linux64.tar.bz2";>Linux
 x86-64 binary (64bit, tar.bz2 built on Ubuntu 12.04 - 14.04) (see [1] below)
diff --git a/source/download.txt b/source/download.txt
--- a/source/download.txt
+++ b/source/download.txt
@@ -109,6 +109,12 @@
 Python 3.2.5 compatible PyPy3 2.4.0
 ---
 
+.. class:: download_menu
+
+Warning: this is (1) based on an old release of PyPy, and (2) only
+supporting the Python 3.2 language.  It's also known to be
+(sometimes much) slower than PyPy 2.
+
 * `Linux x86 binary (32bit, tar.bz2 built on Ubuntu 10.04.4 LTS)`__ (see 
``[1]`` below)
 * `Linux x86-64 binary (64bit, tar.bz2 built on Ubuntu 12.04 - 14.04)`__ (see 
``[1]`` below)
 * `ARM Hardfloat Linux binary (ARMHF/gnueabihf, tar.bz2, Raspbian)`__ (see 
``[1]`` below)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: updated slides, check in the html version

2016-01-30 Thread arigo
+img.align-center, .figure.align-center, object.align-center {
+  display: block;
+  margin-left: auto;
+  margin-right: auto;
+}
+
+.align-left {
+  text-align: left }
+
+.align-center {
+  clear: both ;
+  text-align: center }
+
+.align-right {
+  text-align: right }
+
+/* reset inner alignment in figures */
+div.align-right {
+  text-align: inherit }
+
+/* div.align-center * { */
+/*   text-align: left } */
+
+ol.simple, ul.simple {
+  margin-bottom: 1em }
+
+ol.arabic {
+  list-style: decimal }
+
+ol.loweralpha {
+  list-style: lower-alpha }
+
+ol.upperalpha {
+  list-style: upper-alpha }
+
+ol.lowerroman {
+  list-style: lower-roman }
+
+ol.upperroman {
+  list-style: upper-roman }
+
+p.attribution {
+  text-align: right ;
+  margin-left: 50% }
+
+p.caption {
+  font-style: italic }
+
+p.credits {
+  font-style: italic ;
+  font-size: smaller }
+
+p.label {
+  white-space: nowrap }
+
+p.rubric {
+  font-weight: bold ;
+  font-size: larger ;
+  color: maroon ;
+  text-align: center }
+
+p.sidebar-title {
+  font-family: sans-serif ;
+  font-weight: bold ;
+  font-size: larger }
+
+p.sidebar-subtitle {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+p.topic-title {
+  font-weight: bold }
+
+pre.address {
+  margin-bottom: 0 ;
+  margin-top: 0 ;
+  font: inherit }
+
+pre.literal-block, pre.doctest-block, pre.math, pre.code {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+pre.code .ln { color: grey; } /* line numbers */
+pre.code, code { background-color: #ee }
+pre.code .comment, code .comment { color: #5C6576 }
+pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
+pre.code .literal.string, code .literal.string { color: #0C5404 }
+pre.code .name.builtin, code .name.builtin { color: #352B84 }
+pre.code .deleted, code .deleted { background-color: #DEB0A1}
+pre.code .inserted, code .inserted { background-color: #A3D289}
+
+span.classifier {
+  font-family: sans-serif ;
+  font-style: oblique }
+
+span.classifier-delimiter {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+span.interpreted {
+  font-family: sans-serif }
+
+span.option {
+  white-space: nowrap }
+
+span.pre {
+  white-space: pre }
+
+span.problematic {
+  color: red }
+
+span.section-subtitle {
+  /* font-size relative to parent (h1..h6 element) */
+  font-size: 80% }
+
+table.citation {
+  border-left: solid 1px gray;
+  margin-left: 1px }
+
+table.docinfo {
+  margin: 2em 4em }
+
+table.docutils {
+  margin-top: 0.5em ;
+  margin-bottom: 0.5em }
+
+table.footnote {
+  border-left: solid 1px black;
+  margin-left: 1px }
+
+table.docutils td, table.docutils th,
+table.docinfo td, table.docinfo th {
+  padding-left: 0.5em ;
+  padding-right: 0.5em ;
+  vertical-align: top }
+
+table.docutils th.field-name, table.docinfo th.docinfo-name {
+  font-weight: bold ;
+  text-align: left ;
+  white-space: nowrap ;
+  padding-left: 0 }
+
+/* "booktabs" style (no vertical lines) */
+table.docutils.booktabs {
+  border: 0px;
+  border-top: 2px solid;
+  border-bottom: 2px solid;
+  border-collapse: collapse;
+}
+table.docutils.booktabs * {
+  border: 0px;
+}
+table.docutils.booktabs th {
+  border-bottom: thin solid;
+  text-align: left;
+}
+
+h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
+h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
+  font-size: 100% }
+
+ul.auto-toc {
+  list-style-type: none }
+
+
+
+
+
+
+
+
+
+
+
+
+
+#currentSlide {display: none;}
+
+
+
+
+
+
+
+
+
+
+CFFI and PyPy
+
+
+
+
+
+CFFI and PyPy
+
+
+
+
+CFFI
+
+successful project according to PyPI
+3.4 million downloads last month
+total 19.2 millions, 27th place on pypi-ranking.info
+Django is 28th
+
+
+some high-visibility projects have switched to it (Cryptography)
+
+
+
+PyPy
+
+harder to say, but probably not so successful
+more later
+
+
+
+CFFI
+
+
+CFFI
+
+call C from Python
+CFFI = C Foreign Function Interface
+shares ideas from Cython, ctypes, and LuaJIT's FFI
+
+
+
+CFFI demo
+
+$ man getpwuid
+
+SYNOPSIS
+   #include <sys/types.h>
+   #include <pwd.h>
+
+   struct passwd *getpwnam(const char *name);
+
+
+
+CFFI demo
+
+.
+.
+.
+The passwd structure is defined in <pwd.h> as follows:
+
+struct passwd {
+char   *pw_name;   /* username */
+char   *pw_passwd; /* user password */
+uid_t   pw_uid;/* user ID */
+.
+.
+.
+
+
+
+CFFI demo
+
+from cffi import FFI
+ffi = cffi.FFI()
+
+ffi.cdef("""
+typedef int... uid_t;
+struct passwd {
+uid_t pw_uid;
+...;
+};
+struct passwd *getpwnam(const char *name);
+""")
+
+
+
+CFFI demo
+
+ffi.set_source("_pwuid_cffi", """
+#include <sys/types.h>
+#include <pwd.h>
+""")
+
+ffi.compile()
+
+--- ^^ put that in pwuid_build.py
+
+
+CFFI demo
+
+python pwuid_build.py
+
+creates _pwuid_cffi.so
+
+
+CFFI demo
+
+from _pwuid_cffi import lib
+
+print lib.getpwnam("arigo").pw_uid
+
+
+

[pypy-commit] cffi default: Issue #244: parse_type() calls the Parser logic but self._options used

2016-01-31 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2615:6b198bbbad9f
Date: 2016-01-31 16:29 +0100
http://bitbucket.org/cffi/cffi/changeset/6b198bbbad9f/

Log:Issue #244: parse_type() calls the Parser logic but self._options
used to be None, crashing in corner cases

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -220,7 +220,7 @@
 self._included_declarations = set()
 self._anonymous_counter = 0
 self._structnode2type = weakref.WeakKeyDictionary()
-self._options = None
+self._options = {}
 self._int_constants = {}
 self._recomplete = []
 self._uses_new_feature = None
@@ -374,7 +374,7 @@
 
 def _declare_function(self, tp, quals, decl):
 tp = self._get_type_pointer(tp, quals)
-if self._options['dllexport']:
+if self._options.get('dllexport'):
 tag = 'dllexport_python '
 elif self._inside_extern_python:
 tag = 'extern_python '
@@ -450,7 +450,7 @@
 prevobj, prevquals = self._declarations[name]
 if prevobj is obj and prevquals == quals:
 return
-if not self._options['override']:
+if not self._options.get('override'):
 raise api.FFIError(
 "multiple declarations of %s (for interactive usage, "
 "try cdef(xx, override=True))" % (name,))
@@ -729,7 +729,7 @@
 if isinstance(tp, model.StructType) and tp.partial:
 raise NotImplementedError("%s: using both bitfields and '...;'"
   % (tp,))
-tp.packed = self._options['packed']
+tp.packed = self._options.get('packed')
 if tp.completed:# must be re-completed: it is not opaque any more
 tp.completed = 0
 self._recomplete.append(tp)
diff --git a/testing/cffi0/backend_tests.py b/testing/cffi0/backend_tests.py
--- a/testing/cffi0/backend_tests.py
+++ b/testing/cffi0/backend_tests.py
@@ -1846,3 +1846,8 @@
 thread.start_new_thread(f, ())
 time.sleep(1.5)
 assert seen == ['init!', 'init done'] + 6 * [7]
+
+def test_sizeof_struct_directly(self):
+# only works with the Python FFI instances
+ffi = FFI(backend=self.Backend())
+assert ffi.sizeof("struct{int a;}") == ffi.sizeof("int")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: copy slides from fosdem2016

2016-02-02 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5599:daa5d98e6cad
Date: 2016-02-02 10:52 +0100
http://bitbucket.org/pypy/extradoc/changeset/daa5d98e6cad/

Log:copy slides from fosdem2016

diff --git a/talk/swisspython2016/slides.rst b/talk/swisspython2016/slides.rst
new file mode 100644
--- /dev/null
+++ b/talk/swisspython2016/slides.rst
@@ -0,0 +1,405 @@
+=
+CFFI and PyPy
+=
+
+
+CFFI
+
+
+* successful project according to PyPI
+
+* 3.4 million downloads last month
+
+* total 19.2 millions, 27th place on `pypi-ranking.info`
+
+  - Django is 28th
+
+* some high-visibility projects have switched to it (Cryptography)
+
+
+PyPy
+
+
+* harder to say, but probably not so successful
+
+* more later
+
+
+CFFI
+
+
+
+
+CFFI
+
+
+* call C from Python
+
+* CFFI = C Foreign Function Interface
+
+* shares ideas from Cython, ctypes, and LuaJIT's FFI
+
+
+CFFI demo
+=
+
+::
+
+  $ man getpwuid
+
+  SYNOPSIS
+ #include 
+ #include 
+
+ struct passwd *getpwnam(const char *name);
+
+
+CFFI demo
+=
+
+::
+
+   .
+   .
+   .
+   The passwd structure is defined in  as follows:
+
+   struct passwd {
+   char   *pw_name;   /* username */
+   char   *pw_passwd; /* user password */
+   uid_t   pw_uid;/* user ID */
+   .
+   .
+   .
+
+
+CFFI demo
+=
+
+::
+
+  from cffi import FFI
+  ffi = cffi.FFI()
+
+  ffi.cdef("""
+  typedef int... uid_t;
+  struct passwd {
+  uid_t pw_uid;
+  ...;
+  };
+  struct passwd *getpwnam(const char *name);
+  """)
+
+
+CFFI demo
+=
+
+::
+
+  ffi.set_source("_pwuid_cffi", """
+  #include 
+  #include 
+  """)
+
+  ffi.compile()
+
+--- ^^ put that in pwuid_build.py
+
+
+CFFI demo
+=
+
+::
+
+  python pwuid_build.py
+
+creates ``_pwuid_cffi.so``
+
+
+CFFI demo
+=
+
+::
+
+  from _pwuid_cffi import lib
+
+  print lib.getpwnam("arigo").pw_uid
+
+
+CFFI demo
+=
+
+::
+
+  from _pwuid_cffi import ffi, lib
+
+* ``lib`` gives access to all functions from the cdef
+
+* ``ffi`` gives access to a few general helpers, e.g.
+
+   - ``ffi.cast("float", 42)``
+
+   - ``p = ffi.new("struct passwd *")``
+
+   - ``p = ffi.new("char[10]"); p[0] = 'X'; s = lib.getpwnam(p)``
+
+   - ``p = ffi.new_handle(random_obj); ...; random_obj = ffi.from_handle(p)``
+
+
+CFFI
+
+
+* supports more or less the whole C
+
+* there is more than my short explanation suggests
+
+* read the docs: http://cffi.readthedocs.org/
+
+
+
+PyPy
+
+
+
+PyPy
+
+
+* a Python interpreter
+
+* different from the standard, which is CPython
+
+* main goal of PyPy: speed
+
+
+PyPy
+
+
+::
+
+$ pypy
+
+Python 2.7.10 (5f8302b8bf9f, Nov 18 2015, 10:46:46)
+[PyPy 4.0.1 with GCC 4.8.4] on linux2
+Type "help", "copyright", "credits" or "license" for more information.
+>>>> 2+3
+5
+>>>>
+
+
+PyPy
+
+
+* run ``pypy my_program.py``
+
+* starts working like an interpreter
+
+* then a Just-in-Time Compiler kicks in
+
+* generate and execute machine code from the Python program
+
+* good or great speed-ups for the majority of long-running code
+
+
+PyPy
+
+
+* different techniques than CPython also for "garbage collection"
+
+* works very well (arguably better than CPython's reference counting)
+
+
+PyPy: Garbage Collection
+
+
+* "**moving,** generational, incremental GC"
+
+* objects don't have reference counters
+
+* allocated in a "nursery"
+
+* when nursery full, find surviving nursery objects and move them out
+
+* usually work on nursery objects only (fast), but rarely also perform
+  a full GC
+
+
+PyPy: C extensions
+==
+
+* PyPy works great for running Python
+
+* less great when there are CPython C extension modules involved
+
+
+PyPy: C extensions
+==
+
+* not directly possible: we have moving, non-reference-counted objects,
+  and the C code expects non-moving, reference-counted objects
+
+
+PyPy: C extensions
+==
+
+* PyPy has still some support for them, called its ``cpyext`` module
+
+* similar to IronPython's Ironclad
+
+* emulate all objects for C extensions with a shadow, non-movable,
+  reference-counted object
+
+
+PyPy: C extensions
+==
+
+* ``cpyext`` is slow
+
+* ``cpyext`` is actually *really, really* slow
+
+  - but we're working on making it *only* slow
+
+
+PyPy: C extensions
+==
+
+* ``cpyext`` will "often" work, but there are a some high-profile C
+  extension modules that are not supported so far
+
+* notably, ``numpy``
+
+* (it is future work)
+
+
+PyPy: ad
+
+
+* but, hey, if

[pypy-commit] extradoc extradoc: expand a bit the cffi part

2016-02-02 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5600:6c7e299c3d71
Date: 2016-02-02 11:24 +0100
http://bitbucket.org/pypy/extradoc/changeset/6c7e299c3d71/

Log:expand a bit the cffi part

diff --git a/talk/swisspython2016/slides.rst b/talk/swisspython2016/slides.rst
--- a/talk/swisspython2016/slides.rst
+++ b/talk/swisspython2016/slides.rst
@@ -135,15 +135,83 @@
 
 * ``lib`` gives access to all functions from the cdef
 
-* ``ffi`` gives access to a few general helpers, e.g.
+* ``ffi`` gives access to a few general helpers
 
-   - ``ffi.cast("float", 42)``
 
-   - ``p = ffi.new("struct passwd *")``
+ffi.cdef()
+==
 
-   - ``p = ffi.new("char[10]"); p[0] = 'X'; s = lib.getpwnam(p)``
+::
 
-   - ``p = ffi.new_handle(random_obj); ...; random_obj = ffi.from_handle(p)``
+ffi.cdef("""
+int foo1(int a, int b);
+
+typedef ... Window;
+Window *make_window(int, int, int);
+void hide_window(Window *);
+""")
+
+
+ffi.new()
+=
+
+::
+
+>>> p = ffi.new("char[]", "Some string")
+>>> p
+
+>>> p[1]
+'o'
+>>> q = lib.getpwnam(p)
+>>> q
+
+>>> q.pw_uid
+500
+
+ffi.cast()
+==
+
+::
+
+>>> p = lib.getpwnam("root")
+>>> p
+
+>>> ffi.cast("void *", p)
+
+>>> ffi.cast("long", p)
+305419896
+>>> hex(_)
+0x12345678
+
+ffi.new_handle()
+
+
+::
+
+>>> h1 = ffi.new_handle(some_object)
+>>> h1
+>
+>>> lib.same_away(h1)
+
+>>> h2 = lib.fish_again()
+>>> h2
+
+>>> ffi.from_handle(h2)
+
+
+ffi.string()
+
+
+::
+
+>>> p
+
+>>> p.pw_uid
+500
+>>> p.pw_name
+
+>>> ffi.string(p.pw_name)
+"username"
 
 
 CFFI
@@ -151,7 +219,7 @@
 
 * supports more or less the whole C
 
-* there is more than my short explanation suggests
+* there is more than my short explanations suggests
 
 * read the docs: http://cffi.readthedocs.org/
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: hack hack hack to make rst2beamer output correct latex

2016-02-02 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5601:a0f714ccd3d0
Date: 2016-02-02 12:09 +0100
http://bitbucket.org/pypy/extradoc/changeset/a0f714ccd3d0/

Log:hack hack hack to make rst2beamer output correct latex

diff --git a/talk/swisspython2016/slides.rst b/talk/swisspython2016/slides.rst
--- a/talk/swisspython2016/slides.rst
+++ b/talk/swisspython2016/slides.rst
@@ -2,6 +2,15 @@
 CFFI and PyPy
 =
 
+.. raw:: latex
+
+   \catcode`\|=13
+   \def|{\hskip 1cm}
+
+   \let\foobarbaz=>
+   \catcode`\>=13
+   \def>{\foobarbaz\relax}
+ 
 
 CFFI
 
@@ -45,13 +54,19 @@
 
 ::
 
-  $ man getpwuid
+ |$ man getpwuid
 
-  SYNOPSIS
- #include 
- #include 
+ | 
 
- struct passwd *getpwnam(const char *name);
+ |SYNOPSIS
+
+ ||  #include 
+
+ ||  #include 
+
+ ||
+
+ ||  struct passwd *getpwnam(const char *);
 
 
 CFFI demo
@@ -59,36 +74,59 @@
 
 ::
 
-   .
-   .
-   .
-   The passwd structure is defined in  as follows:
+ |   .
 
-   struct passwd {
-   char   *pw_name;   /* username */
-   char   *pw_passwd; /* user password */
-   uid_t   pw_uid;/* user ID */
-   .
-   .
-   .
+ |   .
 
+ |   .
+
+ |   The passwd structure is defined in 
+
+ |   as follows:
+
+ |
+ 
+ |   struct passwd {
+
+ |   |  char   *pw_name;   /* username */
+
+ |   |  char   *pw_passwd; /* user password */
+ 
+ |   |  uid_t   pw_uid;/* user ID */
+ 
+ |   .
+
+ |   .
+
+ |   .
+   
 
 CFFI demo
 =
 
 ::
 
-  from cffi import FFI
-  ffi = cffi.FFI()
+ |  from cffi import FFI
 
-  ffi.cdef("""
-  typedef int... uid_t;
-  struct passwd {
-  uid_t pw_uid;
-  ...;
-  };
-  struct passwd *getpwnam(const char *name);
-  """)
+ |  ffi = cffi.FFI()
+
+ |
+
+ |  ffi.cdef("""
+
+ |  | typedef int... uid_t;
+ 
+ |  | struct passwd {
+ 
+ |  | | uid_t pw_uid;
+ 
+ |  | | ...;
+ 
+ |  | };
+ 
+ |  | struct passwd *getpwnam(const char *);
+ 
+ |  """)
 
 
 CFFI demo
@@ -96,14 +134,21 @@
 
 ::
 
-  ffi.set_source("_pwuid_cffi", """
-  #include 
-  #include 
-  """)
+ | ffi.set_source("_pwuid_cffi", """
+ 
+ | |#include 
+ 
+ | |#include 
+ 
+ | """)
 
-  ffi.compile()
+ |
+ 
+ | ffi.compile()
 
 ^^ put that in pwuid_build.py
+ |
+
+... and put that in pwuid_build.py
 
 
 CFFI demo
@@ -111,9 +156,11 @@
 
 ::
 
-  python pwuid_build.py
+ | python pwuid_build.py
 
-creates ``_pwuid_cffi.so``
+ |
+
+creates _pwuid_cffi.so
 
 
 CFFI demo
@@ -123,7 +170,7 @@
 
   from _pwuid_cffi import lib
 
-  print lib.getpwnam("arigo").pw_uid
+  print lib.getpwnam("username").pw_uid
 
 
 CFFI demo
@@ -143,13 +190,19 @@
 
 ::
 
-ffi.cdef("""
-int foo1(int a, int b);
+ |   ffi.cdef("""
+ 
+ |   |   int foo1(int a, int b);
 
-typedef ... Window;
-Window *make_window(int, int, int);
-void hide_window(Window *);
-""")
+ |   |
+
+ |   |   typedef ... Window;
+ 
+ |   |   Window *make_window(int w, int h);
+ 
+ |   |   void hide_window(Window *);
+ 
+ |   """)
 
 
 ffi.new()
@@ -157,61 +210,116 @@
 
 ::
 
->>> p = ffi.new("char[]", "Some string")
->>> p
-
->>> p[1]
-'o'
->>> q = lib.getpwnam(p)
->>> q
-
->>> q.pw_uid
-500
+ |   >>> p = ffi.new("char[]", "Some string")
+ 
+ |   >>> p
+ 
+ |   
+
+ |
+ 
+ |   >>> p[1]
+ 
+ |   'o'
+
+ |
+ 
+ |   >>> q = lib.getpwnam(p)
+ 
+ |   >>> q
+ 
+ |   
+
+ |
+  
+ |   >>> q.pw_uid
+ 
+ |   500
 
 ffi.cast()
 ==
 
 ::
 
->>> p = lib.getpwnam("root")
->>> p
-
->>> ffi.cast("void *", p)
-
->>> ffi.cast("long", p)
-305419896
->>> hex(_)
-0x12345678
+ |   >>> p = lib.getpwnam("root")
+
+ |   >>> p
+
+ |   
+
+ |
+
+ |   >>> ffi.cast("void *", p)
+
+ |   
+
+ |
+
+ |   >>> ffi.cast("long", p)
+
+ |   305419896
+
+ |   >>> hex(_)
+
+ |   0x12345678
+
 
 ffi.new_handle()
 
 
 ::
 
->>> h1 = ffi.new_handle(some_object)
->>> h1
->
->>> lib.same_away(h1)
+ |   >>> h1 = ffi.new_handle(some_object)
+ 
+ |   >>> h1
+ 
+ |   >> h2 = lib.fish_again()
->>> h2
-
->>> ffi.from_handle(h2)
-
+ |   | | | | >
+ 
+ |   >>> lib.save_away(h1)
+ 

[pypy-commit] extradoc extradoc: tweaks tweaks tweaks

2016-02-02 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5602:bbe9486a3f32
Date: 2016-02-02 12:30 +0100
http://bitbucket.org/pypy/extradoc/changeset/bbe9486a3f32/

Log:tweaks tweaks tweaks

diff --git a/talk/swisspython2016/Makefile b/talk/swisspython2016/Makefile
new file mode 100644
--- /dev/null
+++ b/talk/swisspython2016/Makefile
@@ -0,0 +1,6 @@
+slides.pdf: slides.tex author.latex
+   pdflatex $<
+
+slides.tex: slides.rst
+   rst2beamer.py slides.rst > slides.tex
+   sed 's/\\date{}/\\input{author.latex}/' -i slides.tex || exit
diff --git a/talk/swisspython2016/author.latex 
b/talk/swisspython2016/author.latex
new file mode 100644
--- /dev/null
+++ b/talk/swisspython2016/author.latex
@@ -0,0 +1,7 @@
+\definecolor{rrblitbackground}{rgb}{0.4, 0.0, 0.0}
+
+\title[CFFI and PyPy]{CFFI and PyPy}
+\author[Armin Rigo]{Armin Rigo}
+
+\institute{Swiss Python Summit 2016}
+\date{Feb 2016}
diff --git a/talk/swisspython2016/slides.rst b/talk/swisspython2016/slides.rst
--- a/talk/swisspython2016/slides.rst
+++ b/talk/swisspython2016/slides.rst
@@ -1,6 +1,6 @@
-=
+
 CFFI and PyPy
-=
+
 
 .. raw:: latex
 
@@ -10,6 +10,7 @@
\let\foobarbaz=>
\catcode`\>=13
\def>{\foobarbaz\relax}
+
  
 
 CFFI
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Issue #245: __stdcall not generated correctly on extern "Python" functions

2016-02-03 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2618:465ce534fc8a
Date: 2016-02-04 07:40 +0100
http://bitbucket.org/cffi/cffi/changeset/465ce534fc8a/

Log:Issue #245: __stdcall not generated correctly on extern "Python"
functions

diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -231,6 +231,12 @@
 ((got_nonpos) == (expected <= 0) && \
  (got) == (unsigned long long)expected)
 
+#ifdef MS_WIN32
+# define _cffi_stdcall  __stdcall
+#else
+# define _cffi_stdcall  /* nothing */
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -1170,6 +1170,8 @@
 repr_arguments = ', '.join(arguments)
 repr_arguments = repr_arguments or 'void'
 name_and_arguments = '%s(%s)' % (name, repr_arguments)
+if tp.abi == "__stdcall":
+name_and_arguments = '_cffi_stdcall ' + name_and_arguments
 #
 def may_need_128_bits(tp):
 return (isinstance(tp, model.PrimitiveType) and
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -1713,3 +1713,33 @@
 # a case where 'onerror' is not callable
 py.test.raises(TypeError, ffi.def_extern(name='bar', onerror=42),
lambda x: x)
+
+def test_extern_python_stdcall():
+ffi = FFI()
+ffi.cdef("""
+extern "Python" int __stdcall foo(int);
+extern "Python" int WINAPI bar(int);
+int (__stdcall * mycb1)(int);
+int indirect_call(int);
+""")
+lib = verify(ffi, 'test_extern_python_stdcall', """
+#ifndef _MSC_VER
+#  define __stdcall
+#endif
+static int (__stdcall * mycb1)(int);
+static int indirect_call(int x) {
+return mycb1(x);
+}
+""")
+#
+@ffi.def_extern()
+def foo(x):
+return x + 42
+@ffi.def_extern()
+def bar(x):
+return x + 43
+assert lib.foo(100) == 142
+assert lib.bar(100) == 143
+lib.mycb1 = lib.foo
+assert lib.mycb1(200) == 242
+assert lib.indirect_call(300) == 342
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: update the values

2016-02-06 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r699:e27956d33e01
Date: 2016-02-06 19:47 +0100
http://bitbucket.org/pypy/pypy.org/changeset/e27956d33e01/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -15,7 +15,7 @@
 
 

-   $62793 of $105000 (59.8%)
+   $62841 of $105000 (59.8%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting Python 3 in 
PyPy.
   Current status:
-we have $7965 left
+we have $8008 left
   in the account. Read proposal
   
   
diff --git a/don4.html b/don4.html
--- a/don4.html
+++ b/don4.html
@@ -17,7 +17,7 @@
2nd call:

-   $30379 of $8 (38.0%)
+   $30383 of $8 (38.0%)


 
@@ -25,7 +25,7 @@
   
   This donation goes towards supporting the 
Transactional Memory in PyPy.
   Current status:
-we have $23106 left
+we have $23109 left
   in the account. Read proposal (2nd 
call)
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: issue #246: trying to be more robust against CPython's fragile

2016-02-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2619:bdcc6eeb3de4
Date: 2016-02-06 20:25 +0100
http://bitbucket.org/cffi/cffi/changeset/bdcc6eeb3de4/

Log:issue #246: trying to be more robust against CPython's fragile
interpreter shutdown logic

diff --git a/c/call_python.c b/c/call_python.c
--- a/c/call_python.c
+++ b/c/call_python.c
@@ -115,6 +115,7 @@
 static int _update_cache_to_call_python(struct _cffi_externpy_s *externpy)
 {
 PyObject *interpstate_dict, *interpstate_key, *infotuple, *old1, *new1;
+PyObject *old2;
 
 interpstate_dict = _get_interpstate_dict();
 if (interpstate_dict == NULL)
@@ -127,14 +128,17 @@
 infotuple = PyDict_GetItem(interpstate_dict, interpstate_key);
 Py_DECREF(interpstate_key);
 if (infotuple == NULL)
-return 1;/* no ffi.def_extern() from this subinterpreter */
+return 3;/* no ffi.def_extern() from this subinterpreter */
 
 new1 = PyThreadState_GET()->interp->modules;
 Py_INCREF(new1);
+Py_INCREF(infotuple);
 old1 = (PyObject *)externpy->reserved1;
+old2 = (PyObject *)externpy->reserved2;
 externpy->reserved1 = new1; /* holds a reference*/
-externpy->reserved2 = infotuple;/* doesn't hold a reference */
+externpy->reserved2 = infotuple;/* holds a reference (issue #246) */
 Py_XDECREF(old1);
+Py_XDECREF(old2);
 
 return 0;   /* no error */
 
@@ -213,9 +217,11 @@
 gil_release(state);
 }
 if (err) {
-static const char *msg[2] = {
+static const char *msg[] = {
 "no code was attached to it yet with @ffi.def_extern()",
-"got internal exception (out of memory?)" };
+"got internal exception (out of memory / shutdown issue)",
+"@ffi.def_extern() was not called in the current subinterpreter",
+};
 fprintf(stderr, "extern \"Python\": function %s() called, "
 "but %s.  Returning 0.\n", externpy->name, msg[err-1]);
 memset(args, 0, externpy->size_of_result);
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Pass a few more tests

2016-02-06 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82100:2eef9245adc0
Date: 2016-02-06 19:10 +0100
http://bitbucket.org/pypy/pypy/changeset/2eef9245adc0/

Log:Pass a few more tests

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -616,8 +616,7 @@
 
 @specialize.ll()
 def wrapper(*args):
-from pypy.module.cpyext.pyobject import make_ref, from_ref
-from pypy.module.cpyext.pyobject import Reference
+from pypy.module.cpyext.pyobject import make_ref, from_ref, is_pyobj
 # we hope that malloc removal removes the newtuple() that is
 # inserted exactly here by the varargs specializer
 if gil_acquire:
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
@@ -227,7 +227,7 @@
 
 
 def debug_collect():
-rawrefcount._collect(track_allocation=False)
+rawrefcount._collect()
 
 
 def as_pyobj(space, w_obj):
diff --git a/pypy/module/cpyext/test/test_cpyext.py 
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -130,11 +130,10 @@
 
 def check_and_print_leaks(self):
 debug_collect()
-return #ZZZ
 # check for sane refcnts
 import gc
 
-if not self.enable_leak_checking:
+if 1:  #ZZZ  not self.enable_leak_checking:
 leakfinder.stop_tracking_allocations(check=False)
 return False
 
@@ -199,6 +198,9 @@
 "the test actually passed in the first place; if it failed "
 "it is likely to reach this place.")
 
+def test_only_import(self):
+import cpyext
+
 def test_load_error(self):
 import cpyext
 raises(ImportError, cpyext.load_module, "missing.file", "foo")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: borrowed results (copying from cpyext-gc-support)

2016-02-06 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82101:da0f029832ef
Date: 2016-02-06 19:13 +0100
http://bitbucket.org/pypy/pypy/changeset/da0f029832ef/

Log:borrowed results (copying from cpyext-gc-support)

diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -1,7 +1,7 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
 from pypy.module.cpyext.api import cpython_api, cpython_struct, \
 METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL, CONST_STRING
-from pypy.module.cpyext.pyobject import PyObject, borrow_from
+from pypy.module.cpyext.pyobject import PyObject
 from pypy.interpreter.module import Module
 from pypy.module.cpyext.methodobject import (
 W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod,
@@ -34,7 +34,7 @@
 # This is actually the Py_InitModule4 function,
 # renamed to refuse modules built against CPython headers.
 @cpython_api([CONST_STRING, lltype.Ptr(PyMethodDef), CONST_STRING,
-  PyObject, rffi.INT_real], PyObject)
+  PyObject, rffi.INT_real], PyObject, result_borrowed=True)
 def _Py_InitPyPyModule(space, name, methods, doc, w_self, apiver):
 """
 Create a new module object based on a name and table of functions, 
returning
@@ -69,7 +69,7 @@
 if doc:
 space.setattr(w_mod, space.wrap("__doc__"),
   space.wrap(rffi.charp2str(doc)))
-return borrow_from(None, w_mod)
+return w_mod   # borrowed result kept alive in PyImport_AddModule()
 
 
 def convert_method_defs(space, dict_w, methods, w_type, w_self=None, 
name=None):
@@ -114,12 +114,12 @@
 return int(space.is_w(w_type, w_obj_type) or
space.is_true(space.issubtype(w_obj_type, w_type)))
 
-@cpython_api([PyObject], PyObject)
+@cpython_api([PyObject], PyObject, result_borrowed=True)
 def PyModule_GetDict(space, w_mod):
 if PyModule_Check(space, w_mod):
 assert isinstance(w_mod, Module)
 w_dict = w_mod.getdict(space)
-return borrow_from(w_mod, w_dict)
+return w_dict# borrowed reference, likely from w_mod.w_dict
 else:
 PyErr_BadInternalCall(space)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: issue #2236: ignore xchgb

2016-02-07 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82105:8581149fc8c5
Date: 2016-02-07 14:33 +0100
http://bitbucket.org/pypy/pypy/changeset/8581149fc8c5/

Log:issue #2236: ignore xchgb

diff --git a/rpython/translator/c/gcc/trackgcroot.py 
b/rpython/translator/c/gcc/trackgcroot.py
--- a/rpython/translator/c/gcc/trackgcroot.py
+++ b/rpython/translator/c/gcc/trackgcroot.py
@@ -528,6 +528,8 @@
 'rex64',
 # movbe, converts from big-endian, so most probably not GC pointers
 'movbe',
+# xchgb, byte-sized, so not GC pointers
+'xchgb',
 ])
 
 # a partial list is hopefully good enough for now; it's all to support
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge heads

2016-02-07 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82106:90f38a4668e2
Date: 2016-02-07 14:34 +0100
http://bitbucket.org/pypy/pypy/changeset/90f38a4668e2/

Log:merge heads

diff too long, truncating to 2000 out of 3793 lines

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -75,6 +75,7 @@
 ^lib_pypy/__pycache__$
 ^lib_pypy/ctypes_config_cache/_.+_cache\.py$
 ^lib_pypy/ctypes_config_cache/_.+_.+_\.py$
+^lib_pypy/_libmpdec/.+.o$
 ^rpython/translator/cli/query-descriptions$
 ^pypy/doc/discussion/.+\.html$
 ^include/.+\.h$
diff --git a/dotviewer/drawgraph.py b/dotviewer/drawgraph.py
--- a/dotviewer/drawgraph.py
+++ b/dotviewer/drawgraph.py
@@ -14,12 +14,661 @@
 FONT = os.path.join(this_dir, 'font', 'DroidSans.ttf')
 FIXEDFONT = os.path.join(this_dir, 'font', 'DroidSansMono.ttf')
 COLOR = {
-'black': (0,0,0),
-'white': (255,255,255),
-'red': (255,0,0),
-'green': (0,255,0),
-'blue': (0,0,255),
-'yellow': (255,255,0),
+'aliceblue': (240, 248, 255),
+'antiquewhite': (250, 235, 215),
+'antiquewhite1': (255, 239, 219),
+'antiquewhite2': (238, 223, 204),
+'antiquewhite3': (205, 192, 176),
+'antiquewhite4': (139, 131, 120),
+'aquamarine': (127, 255, 212),
+'aquamarine1': (127, 255, 212),
+'aquamarine2': (118, 238, 198),
+'aquamarine3': (102, 205, 170),
+'aquamarine4': (69, 139, 116),
+'azure': (240, 255, 255),
+'azure1': (240, 255, 255),
+'azure2': (224, 238, 238),
+'azure3': (193, 205, 205),
+'azure4': (131, 139, 139),
+'beige': (245, 245, 220),
+'bisque': (255, 228, 196),
+'bisque1': (255, 228, 196),
+'bisque2': (238, 213, 183),
+'bisque3': (205, 183, 158),
+'bisque4': (139, 125, 107),
+'black': (0, 0, 0),
+'blanchedalmond': (255, 235, 205),
+'blue': (0, 0, 255),
+'blue1': (0, 0, 255),
+'blue2': (0, 0, 238),
+'blue3': (0, 0, 205),
+'blue4': (0, 0, 139),
+'blueviolet': (138, 43, 226),
+'brown': (165, 42, 42),
+'brown1': (255, 64, 64),
+'brown2': (238, 59, 59),
+'brown3': (205, 51, 51),
+'brown4': (139, 35, 35),
+'burlywood': (222, 184, 135),
+'burlywood1': (255, 211, 155),
+'burlywood2': (238, 197, 145),
+'burlywood3': (205, 170, 125),
+'burlywood4': (139, 115, 85),
+'cadetblue': (95, 158, 160),
+'cadetblue1': (152, 245, 255),
+'cadetblue2': (142, 229, 238),
+'cadetblue3': (122, 197, 205),
+'cadetblue4': (83, 134, 139),
+'chartreuse': (127, 255, 0),
+'chartreuse1': (127, 255, 0),
+'chartreuse2': (118, 238, 0),
+'chartreuse3': (102, 205, 0),
+'chartreuse4': (69, 139, 0),
+'chocolate': (210, 105, 30),
+'chocolate1': (255, 127, 36),
+'chocolate2': (238, 118, 33),
+'chocolate3': (205, 102, 29),
+'chocolate4': (139, 69, 19),
+'coral': (255, 127, 80),
+'coral1': (255, 114, 86),
+'coral2': (238, 106, 80),
+'coral3': (205, 91, 69),
+'coral4': (139, 62, 47),
+'cornflowerblue': (100, 149, 237),
+'cornsilk': (255, 248, 220),
+'cornsilk1': (255, 248, 220),
+'cornsilk2': (238, 232, 205),
+'cornsilk3': (205, 200, 177),
+'cornsilk4': (139, 136, 120),
+'crimson': (220, 20, 60),
+'cyan': (0, 255, 255),
+'cyan1': (0, 255, 255),
+'cyan2': (0, 238, 238),
+'cyan3': (0, 205, 205),
+'cyan4': (0, 139, 139),
+'darkgoldenrod': (184, 134, 11),
+'darkgoldenrod1': (255, 185, 15),
+'darkgoldenrod2': (238, 173, 14),
+'darkgoldenrod3': (205, 149, 12),
+'darkgoldenrod4': (139, 101, 8),
+'darkgreen': (0, 100, 0),
+'darkkhaki': (189, 183, 107),
+'darkolivegreen': (85, 107, 47),
+'darkolivegreen1': (202, 255, 112),
+'darkolivegreen2': (188, 238, 104),
+'darkolivegreen3': (162, 205, 90),
+'darkolivegreen4': (110, 139, 61),
+'darkorange': (255, 140, 0),
+'darkorange1': (255, 127, 0),
+'darkorange2': (238, 118, 0),
+'darkorange3': (205, 102, 0),
+'darkorange4': (139, 69, 0),
+'darkorchid': (153, 50, 204),
+'darkorchid1': (191, 62, 255),
+'darkorchid2': (178, 58, 238),
+'darkorchid3': (154, 50, 205),
+'darkorchid4': (104, 34, 139),
+'darksalmon': (233, 150, 122),
+'darkseagreen': (143, 188, 143),
+'darkseagreen1': (193, 255, 193),
+'darkseagreen2': (180, 238, 180),
+'darkseagreen3': (155, 205, 155),
+'darkseagreen4': (105, 139, 105),
+'darkslateblue': (72, 61, 139),
+'darkslategray': (47, 79, 79),
+'darkslategray1': (151, 255, 255),
+'darkslategray2': (141, 238, 238),
+'darkslategray3': (121, 205, 205),
+'darkslategray4': (82, 139, 139),
+'darkslategrey': (47, 79, 79),
+'darkturquoise': (0, 206, 209),
+'darkviolet': (148, 0, 211),
+'deeppink': (255, 20, 147),
+'deeppink1': (255, 20, 147),
+'deeppink2': (238, 18, 137),
+'deeppink3': (205, 16, 118),
+'deeppink4': (139, 10, 80),
+'deepskyblue': (0, 191, 255),
+'deepskyblue1': (0, 191, 255),
+'deepskyblue2': (0, 1

[pypy-commit] pypy.org extradoc: update the values

2016-02-08 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r700:dcc5d23c5099
Date: 2016-02-08 13:40 +0100
http://bitbucket.org/pypy/pypy.org/changeset/dcc5d23c5099/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -9,13 +9,13 @@
 
   $(function() {
 $("#progressbar").progressbar({
-  value: 59.8
+  value: 59.9
});
   });
 
 

-   $62841 of $105000 (59.8%)
+   $62850 of $105000 (59.9%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting Python 3 in 
PyPy.
   Current status:
-we have $8008 left
+we have $8016 left
   in the account. Read proposal
   
   
diff --git a/don3.html b/don3.html
--- a/don3.html
+++ b/don3.html
@@ -15,7 +15,7 @@
 
 

-   $53142 of $6 (88.6%)
+   $53152 of $6 (88.6%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting NumPy in PyPy.
   Current status:
-we have $7933 left
+we have $7941 left
   in the account. Read proposal
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: imports, and "oops"

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82120:0016cf6f514f
Date: 2016-02-09 09:28 +0100
http://bitbucket.org/pypy/pypy/changeset/0016cf6f514f/

Log:imports, and "oops"

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -617,6 +617,7 @@
 @specialize.ll()
 def wrapper(*args):
 from pypy.module.cpyext.pyobject import make_ref, from_ref, is_pyobj
+from pypy.module.cpyext.pyobject import as_pyobj
 # we hope that malloc removal removes the newtuple() that is
 # inserted exactly here by the varargs specializer
 if gil_acquire:
@@ -671,7 +672,7 @@
 if is_pyobj(result):
 retval = result
 else:
-if result is None:
+if result is not None:
 if callable.api_func.result_borrowed:
 retval = as_pyobj(space, result)
 else:
@@ -1262,7 +1263,8 @@
 @specialize.memo()
 def make_generic_cpy_call(FT, expect_null):
 from pypy.module.cpyext.pyobject import make_ref, from_ref, Py_DecRef
-from pypy.module.cpyext.pyobject import RefcountState
+from pypy.module.cpyext.pyobject import is_pyobj, as_pyobj
+from pypy.module.cpyext.pyobject import get_w_obj_and_decref
 from pypy.module.cpyext.pyerrors import PyErr_Occurred
 unrolling_arg_types = unrolling_iterable(enumerate(FT.ARGS))
 RESULT_TYPE = FT.RESULT
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Document whatsnew

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2620:66c37829e1f5
Date: 2016-02-09 13:31 +0100
http://bitbucket.org/cffi/cffi/changeset/66c37829e1f5/

Log:Document whatsnew

diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -3,6 +3,18 @@
 ==
 
 
+v1.5.1
+==
+
+* A few installation-time tweaks (thanks Stefano!)
+
+* Issue #245: Win32: ``__stdcall`` was never generated for
+  ``extern "Python"`` functions
+
+* Issue #246: trying to be more robust against CPython's fragile
+  interpreter shutdown logic
+
+
 v1.5.0
 ==
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: bump the version number

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2621:5833cd037e9e
Date: 2016-02-09 13:44 +0100
http://bitbucket.org/cffi/cffi/changeset/5833cd037e9e/

Log:bump the version number

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2,7 +2,7 @@
 #include 
 #include "structmember.h"
 
-#define CFFI_VERSION  "1.5.0"
+#define CFFI_VERSION  "1.5.1"
 
 #ifdef MS_WIN32
 #include 
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -12,7 +12,7 @@
 # 
 
 import sys
-assert __version__ == "1.5.0", ("This test_c.py file is for testing a version"
+assert __version__ == "1.5.1", ("This test_c.py file is for testing a version"
 " of cffi that differs from the one that we"
 " get from 'import _cffi_backend'")
 if sys.version_info < (3,):
diff --git a/cffi/__init__.py b/cffi/__init__.py
--- a/cffi/__init__.py
+++ b/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.5.0"
-__version_info__ = (1, 5, 0)
+__version__ = "1.5.1"
+__version_info__ = (1, 5, 1)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/cffi/_embedding.h b/cffi/_embedding.h
--- a/cffi/_embedding.h
+++ b/cffi/_embedding.h
@@ -233,7 +233,7 @@
 f = PySys_GetObject((char *)"stderr");
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.5.0"
+   "\ncompiled with cffi version: 1.5.1"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/doc/source/conf.py b/doc/source/conf.py
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -47,7 +47,7 @@
 # The short X.Y version.
 version = '1.5'
 # The full version, including alpha/beta/rc tags.
-release = '1.5.0'
+release = '1.5.1'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -51,11 +51,11 @@
 
 Download and Installation:
 
-* http://pypi.python.org/packages/source/c/cffi/cffi-1.5.0.tar.gz
+* http://pypi.python.org/packages/source/c/cffi/cffi-1.5.1.tar.gz
 
-   - MD5: dec8441e67880494ee881305059af656
+   - MD5: ...
 
-   - SHA: fd21011ba2a3cab627001b52c69fd7274517e549
+   - SHA: ...
 
 * Or grab the most current version from the `Bitbucket page`_:
   ``hg clone https://bitbucket.org/cffi/cffi``
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -144,7 +144,7 @@
 
 `Mailing list `_
 """,
-version='1.5.0',
+version='1.5.1',
 packages=['cffi'] if cpython else [],
 package_data={'cffi': ['_cffi_include.h', 'parse_c_type.h', 
'_embedding.h']}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: fix

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5604:16b7f0cfe1fe
Date: 2016-02-09 14:28 +0100
http://bitbucket.org/pypy/extradoc/changeset/16b7f0cfe1fe/

Log:fix

diff --git a/talk/swisspython2016/slides.rst b/talk/swisspython2016/slides.rst
--- a/talk/swisspython2016/slides.rst
+++ b/talk/swisspython2016/slides.rst
@@ -107,7 +107,7 @@
 
 ::
 
- |  from cffi import FFI
+ |  import cffi
 
  |  ffi = cffi.FFI()
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: expand with more recent info

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5605:5296e53a14b9
Date: 2016-02-09 14:31 +0100
http://bitbucket.org/pypy/extradoc/changeset/5296e53a14b9/

Log:expand with more recent info

diff --git a/sprintinfo/leysin-winter-2016/people.txt 
b/sprintinfo/leysin-winter-2016/people.txt
--- a/sprintinfo/leysin-winter-2016/people.txt
+++ b/sprintinfo/leysin-winter-2016/people.txt
@@ -10,9 +10,8 @@
 Name  Arrive/Depart Accomodation 
  == ===
 Armin Rigo  private
-(SEE NOTE BELOW)
 Remi Meier   21-27  Ermina
-Carl Friedrich Bolz  20-27  Ermina?
+Carl Friedrich Bolz  20-27  Ermina (individual room)
 Matti Picus  20-25  Ermina
 Manuel Jacob 20-27  Ermina
 Richard Plangger 20-28  Ermina
@@ -21,10 +20,16 @@
 Pierre-Yves David20-27  Ermina
  == ===
 
-**NOTE:** we might have only a single double-bed room and a big room
-(5-6 individual beds).  I can ask if more people want smaller rooms,
-and/or recommend hotels elsewhere in Leysin.  Please be explicit in what
-you prefer.  The standard booking is for the nights from Saturday to
+**NOTE:** lodging is by default in Ermina in 4-5 people rooms.  (One of
+the two big rooms may be rented on the last day; we'll see if we have to
+do other arrangements on-the-spot, but don't worry, it is possible in
+the worst case to send a couple of people to a hotel for one night.)
+
+Please tell if you would prefer a smaller or individual room (which may
+be in a nearby hotel).  Of course you're free to book the hotel yourself
+if you prefer.
+
+The standard booking is for the nights from Saturday to
 Saturday, but it is possible to extend that.
 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cffi-embedding-win32: Add pypy_init_embedded_cffi_module() to test_ztranslation

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: cffi-embedding-win32
Changeset: r82129:6644cb289b26
Date: 2016-02-09 21:14 +0100
http://bitbucket.org/pypy/pypy/changeset/6644cb289b26/

Log:Add pypy_init_embedded_cffi_module() to test_ztranslation

diff --git a/pypy/module/_cffi_backend/test/test_ztranslation.py 
b/pypy/module/_cffi_backend/test/test_ztranslation.py
--- a/pypy/module/_cffi_backend/test/test_ztranslation.py
+++ b/pypy/module/_cffi_backend/test/test_ztranslation.py
@@ -4,15 +4,18 @@
 
 # side-effect: FORMAT_LONGDOUBLE must be built before test_checkmodule()
 from pypy.module._cffi_backend import misc
-from pypy.module._cffi_backend import cffi1_module
+from pypy.module._cffi_backend import cffi1_module, embedding
 
 
 def test_checkmodule():
 # prepare_file_argument() is not working without translating the _file
 # module too
 def dummy_prepare_file_argument(space, fileobj):
-# call load_cffi1_module() too, from a random place like here
-cffi1_module.load_cffi1_module(space, "foo", "foo", 42)
+# call pypy_init_embedded_cffi_module() from a random place like here
+# --- this calls load_cffi1_module(), too
+embedding.pypy_init_embedded_cffi_module(
+rffi.cast(rffi.INT, embedding.EMBED_VERSION_MIN),
+42)
 return lltype.nullptr(rffi.CCHARP.TO)
 old = ctypeptr.prepare_file_argument
 try:
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -397,9 +397,14 @@
 space.wrap(value)
 
 class FakeCompiler(object):
-pass
+def compile(self, code, name, mode, flags):
+return FakePyCode()
 FakeObjSpace.default_compiler = FakeCompiler()
 
+class FakePyCode(W_Root):
+def exec_code(self, space, w_globals, w_locals):
+return W_Root()
+
 
 class FakeModule(W_Root):
 def __init__(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cffi-embedding-win32: in-progress: share more code between posix and win32, and use

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: cffi-embedding-win32
Changeset: r82130:12211c49a141
Date: 2016-02-09 21:17 +0100
http://bitbucket.org/pypy/pypy/changeset/12211c49a141/

Log:in-progress: share more code between posix and win32, and use only
win32 functions available on Windows XP

diff --git a/pypy/module/_cffi_backend/embedding.py 
b/pypy/module/_cffi_backend/embedding.py
--- a/pypy/module/_cffi_backend/embedding.py
+++ b/pypy/module/_cffi_backend/embedding.py
@@ -84,72 +84,87 @@
 return rffi.cast(rffi.INT, res)
 
 # 
+
 if os.name == 'nt':
-do_startup = r'''
-#include 
-#define WIN32_LEAN_AND_MEAN
+
+do_includes = r"""
+#define _WIN32_WINNT 0x0501
 #include 
-RPY_EXPORTED void rpython_startup_code(void);
-RPY_EXPORTED int pypy_setup_home(char *, int);
 
-static unsigned char _cffi_ready = 0;
-static const char *volatile _cffi_module_name;
+#define CFFI_INIT_HOME_PATH_MAX  _MAX_PATH
+static void _cffi_init(void);
+static void _cffi_init_error(const char *msg, const char *extra);
 
-static void _cffi_init_error(const char *msg, const char *extra)
+static int _cffi_init_home(char *output_home_path)
 {
-fprintf(stderr,
-"\nPyPy initialization failure when loading module '%s':\n%s%s\n",
-_cffi_module_name, msg, extra);
-}
-
-BOOL CALLBACK _cffi_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex)
-{
-
-HMODULE hModule;
-TCHAR home[_MAX_PATH];
-rpython_startup_code();
-RPyGilAllocate();
+HMODULE hModule = 0;
+DWORD res;
 
 GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCTSTR)&_cffi_init, &hModule);
+
 if (hModule == 0 ) {
-/* TODO turn the int into a string with FormatMessage */
-
-_cffi_init_error("dladdr() failed: ", "");
-return TRUE;
+_cffi_init_error("GetModuleHandleEx() failed", "");
+return -1;
 }
-GetModuleFileName(hModule, home, _MAX_PATH);
-if (pypy_setup_home(home, 1) != 0) {
-_cffi_init_error("pypy_setup_home() failed", "");
-return TRUE;
+res = GetModuleFileName(hModule, output_home_path, 
CFFI_INIT_HOME_PATH_MAX);
+if (res >= CFFI_INIT_HOME_PATH_MAX) {
+return -1;
 }
-_cffi_ready = 1;
-fprintf(stderr, "startup succeeded, home %s\n", home);
-return TRUE;
+return 0;
 }
 
-RPY_EXPORTED
-int pypy_carefully_make_gil(const char *name)
+static void _cffi_init_once(void)
 {
-/* For CFFI: this initializes the GIL and loads the home path.
-   It can be called completely concurrently from unrelated threads.
-   It assumes that we don't hold the GIL before (if it exists), and we
-   don't hold it afterwards.
-*/
-static INIT_ONCE s_init_once;
+static LONG volatile lock = 0;
+static int _init_called = 0;
 
-_cffi_module_name = name;/* not really thread-safe, but better than
-nothing */
-InitOnceExecuteOnce(&s_init_once, _cffi_init, NULL, NULL);
-return (int)_cffi_ready - 1;
-}'''
+while (InterlockedCompareExchange(&lock, 1, 0) != 0) {
+ SwitchToThread();/* spin loop */
+}
+if (!_init_called) {
+_cffi_init();
+_init_called = 1;
+}
+InterlockedCompareExchange(&lock, 0, 1);
+}
+"""
+
 else:
-do_startup = r"""
-#include 
+
+do_includes = r"""
 #include 
 #include 
 
+#define CFFI_INIT_HOME_PATH_MAX  PATH_MAX
+static void _cffi_init(void);
+static void _cffi_init_error(const char *msg, const char *extra);
+
+static int _cffi_init_home(char *output_home_path)
+{
+Dl_info info;
+dlerror();   /* reset */
+if (dladdr(&_cffi_init, &info) == 0) {
+_cffi_init_error("dladdr() failed: ", dlerror());
+return -1;
+}
+if (realpath(info.dli_fname, output_home_path) == NULL) {
+perror("realpath() failed");
+_cffi_init_error("realpath() failed", "");
+return -1;
+}
+return 0;
+}
+
+static void _cffi_init_once(void)
+{
+static pthread_once_t once_control = PTHREAD_ONCE_INIT;
+pthread_once(&once_control, _cffi_init);
+}
+"""
+
+do_startup = do_includes + r"""
 RPY_EXPORTED void rpython_startup_code(void);
 RPY_EXPORTED int pypy_setup_home(char *, int);
 
@@ -165,17 +180,13 @@
 
 static void _cffi_init(void)
 {
-Dl_info info;
-char *home;
+char home[CFFI_INIT_HOME_PATH_MAX + 1];
 
 rpython_startup_code();
 RPyGilAllocate();
 
-if (dladdr(&_cffi_init, &info) == 0) {
-_cffi_init_error("dladdr() failed: ", dlerror());
+if (_cffi_init_home(home) != 0)
 return;
-}
-home = realpath(info.dli_fname, NULL);
 if (pypy_setup_home(home, 1) != 0) {
 _cffi_init_error("pypy_setup_home() failed", "");
 return;
@@ -191,11 +202,9 @@
It assumes that we don't hold the GIL before (if it exists), a

[pypy-commit] pypy default: add missing file

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82135:675f24c75537
Date: 2016-02-09 23:23 +0100
http://bitbucket.org/pypy/pypy/changeset/675f24c75537/

Log:add missing file

diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
new file mode 100644
--- /dev/null
+++ b/lib_pypy/cffi/_embedding.h
@@ -0,0 +1,517 @@
+
+/* Support code for embedding */
+
+#if defined(_MSC_VER)
+#  define CFFI_DLLEXPORT  __declspec(dllexport)
+#elif defined(__GNUC__)
+#  define CFFI_DLLEXPORT  __attribute__((visibility("default")))
+#else
+#  define CFFI_DLLEXPORT  /* nothing */
+#endif
+
+
+/* There are two global variables of type _cffi_call_python_fnptr:
+
+   * _cffi_call_python, which we declare just below, is the one called
+ by ``extern "Python"`` implementations.
+
+   * _cffi_call_python_org, which on CPython is actually part of the
+ _cffi_exports[] array, is the function pointer copied from
+ _cffi_backend.
+
+   After initialization is complete, both are equal.  However, the
+   first one remains equal to &_cffi_start_and_call_python until the
+   very end of initialization, when we are (or should be) sure that
+   concurrent threads also see a completely initialized world, and
+   only then is it changed.
+*/
+#undef _cffi_call_python
+typedef void (*_cffi_call_python_fnptr)(struct _cffi_externpy_s *, char *);
+static void _cffi_start_and_call_python(struct _cffi_externpy_s *, char *);
+static _cffi_call_python_fnptr _cffi_call_python = 
&_cffi_start_and_call_python;
+
+
+#ifndef _MSC_VER
+   /* --- Assuming a GCC not infinitely old --- */
+# define cffi_compare_and_swap(l,o,n)  __sync_bool_compare_and_swap(l,o,n)
+# define cffi_write_barrier()  __sync_synchronize()
+# if !defined(__amd64__) && !defined(__x86_64__) &&   \
+ !defined(__i386__) && !defined(__i386)
+#   define cffi_read_barrier() __sync_synchronize()
+# else
+#   define cffi_read_barrier() (void)0
+# endif
+#else
+   /* --- Windows threads version --- */
+# include 
+# define cffi_compare_and_swap(l,o,n) \
+   (InterlockedCompareExchangePointer(l,n,o) == 
(o))
+# define cffi_write_barrier()   
InterlockedCompareExchange(&_cffi_dummy,0,0)
+# define cffi_read_barrier()   (void)0
+static volatile LONG _cffi_dummy;
+#endif
+
+#ifdef WITH_THREAD
+# ifndef _MSC_VER
+#  include 
+   static pthread_mutex_t _cffi_embed_startup_lock;
+# else
+   static CRITICAL_SECTION _cffi_embed_startup_lock;
+# endif
+  static char _cffi_embed_startup_lock_ready = 0;
+#endif
+
+static void _cffi_acquire_reentrant_mutex(void)
+{
+static void *volatile lock = NULL;
+
+while (!cffi_compare_and_swap(&lock, NULL, (void *)1)) {
+/* should ideally do a spin loop instruction here, but
+   hard to do it portably and doesn't really matter I
+   think: pthread_mutex_init() should be very fast, and
+   this is only run at start-up anyway. */
+}
+
+#ifdef WITH_THREAD
+if (!_cffi_embed_startup_lock_ready) {
+# ifndef _MSC_VER
+pthread_mutexattr_t attr;
+pthread_mutexattr_init(&attr);
+pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+pthread_mutex_init(&_cffi_embed_startup_lock, &attr);
+# else
+InitializeCriticalSection(&_cffi_embed_startup_lock);
+# endif
+_cffi_embed_startup_lock_ready = 1;
+}
+#endif
+
+while (!cffi_compare_and_swap(&lock, (void *)1, NULL))
+;
+
+#ifndef _MSC_VER
+pthread_mutex_lock(&_cffi_embed_startup_lock);
+#else
+EnterCriticalSection(&_cffi_embed_startup_lock);
+#endif
+}
+
+static void _cffi_release_reentrant_mutex(void)
+{
+#ifndef _MSC_VER
+pthread_mutex_unlock(&_cffi_embed_startup_lock);
+#else
+LeaveCriticalSection(&_cffi_embed_startup_lock);
+#endif
+}
+
+
+/**  CPython-specific section  **/
+#ifndef PYPY_VERSION
+
+
+#define _cffi_call_python_org  _cffi_exports[_CFFI_CPIDX]
+
+PyMODINIT_FUNC _CFFI_PYTHON_STARTUP_FUNC(void);   /* forward */
+
+static void _cffi_py_initialize(void)
+{
+/* XXX use initsigs=0, which "skips initialization registration of
+   signal handlers, which might be useful when Python is
+   embedded" according to the Python docs.  But review and think
+   if it should be a user-controllable setting.
+
+   XXX we should also give a way to write errors to a buffer
+   instead of to stderr.
+
+   XXX if importing 'site' fails, CPython (any version) calls
+   exit().  Should we try to work around this behavior here?
+*/
+Py_InitializeEx(0);
+}
+
+static int _cffi_initialize_python(void)
+{
+/* This initializes Python, imports _cffi_backend, and then the
+   present .dll/.so is set up as a CPython C extension module.
+*/
+int result;
+PyGILState_STATE state;
+PyObject *pycode=NULL, *global_dict=NULL, *x;
+
+#if PY_MAJOR_VERSION >= 3
+/* see comments in _cffi_carefully_make_gil() about the
+   Python2/Python3 difference 
+ 

[pypy-commit] pypy default: import cffi 1.5.1 at rev. 5833cd037e9e

2016-02-09 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82136:e83d573de6df
Date: 2016-02-09 23:32 +0100
http://bitbucket.org/pypy/pypy/changeset/e83d573de6df/

Log:import cffi 1.5.1 at rev. 5833cd037e9e

diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO
--- a/lib_pypy/cffi.egg-info/PKG-INFO
+++ b/lib_pypy/cffi.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cffi
-Version: 1.5.0
+Version: 1.5.1
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.5.0"
-__version_info__ = (1, 5, 0)
+__version__ = "1.5.1"
+__version_info__ = (1, 5, 1)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h
--- a/lib_pypy/cffi/_cffi_include.h
+++ b/lib_pypy/cffi/_cffi_include.h
@@ -231,6 +231,12 @@
 ((got_nonpos) == (expected <= 0) && \
  (got) == (unsigned long long)expected)
 
+#ifdef MS_WIN32
+# define _cffi_stdcall  __stdcall
+#else
+# define _cffi_stdcall  /* nothing */
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -1,4 +1,4 @@
-import sys, types
+import sys, sysconfig, types
 from .lock import allocate_lock
 
 try:
@@ -544,28 +544,32 @@
 
 def _apply_embedding_fix(self, kwds):
 # must include an argument like "-lpython2.7" for the compiler
+def ensure(key, value):
+lst = kwds.setdefault(key, [])
+if value not in lst:
+lst.append(value)
+#
 if '__pypy__' in sys.builtin_module_names:
 if hasattr(sys, 'prefix'):
 import os
-libdir = os.path.join(sys.prefix, 'bin')
-dirs = kwds.setdefault('library_dirs', [])
-if libdir not in dirs:
-dirs.append(libdir)
+ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
 pythonlib = "pypy-c"
 else:
 if sys.platform == "win32":
 template = "python%d%d"
-if sys.flags.debug:
-template = template + '_d'
+if hasattr(sys, 'gettotalrefcount'):
+template += '_d'
 else:
 template = "python%d.%d"
+if sysconfig.get_config_var('DEBUG_EXT'):
+template += sysconfig.get_config_var('DEBUG_EXT')
 pythonlib = (template %
 (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
 if hasattr(sys, 'abiflags'):
 pythonlib += sys.abiflags
-libraries = kwds.setdefault('libraries', [])
-if pythonlib not in libraries:
-libraries.append(pythonlib)
+ensure('libraries', pythonlib)
+if sys.platform == "win32":
+ensure('extra_link_args', '/MANIFEST')
 
 def set_source(self, module_name, source, source_extension='.c', **kwds):
 if hasattr(self, '_assigned_source'):
@@ -631,7 +635,7 @@
 compiled DLL.  Use '*' to force distutils' choice, suitable for
 regular CPython C API modules.  Use a file name ending in '.*'
 to ask for the system's default extension for dynamic libraries
-(.so/.dll).
+(.so/.dll/.dylib).
 
 The default is '*' when building a non-embedded C API extension,
 and (module_name + '.*') when building an embedded library.
@@ -695,6 +699,10 @@
 #
 self._embedding = pysource
 
+def def_extern(self, *args, **kwds):
+raise ValueError("ffi.def_extern() is only available on API-mode FFI "
+ "objects")
+
 
 def _load_backend_lib(backend, name, flags):
 if name is None:
diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -220,7 +220,7 @@
 self._included_declarations = set()
 self._anonymous_counter = 0
 self._structnode2type = weakref.WeakKeyDictionary()
-self._options = None
+self._options = {}
 self._int_constants = {}
 self._recomplete = []
 self._uses_new_feature = None
@@ -374,7 +374,7 @@
 
 def _declare_function(self, tp, quals, decl):
 tp = self._get_type_pointer(tp, quals)
-if self._options['dllexport']:
+if self._options.get('dllexport'):
 tag = 'dllexport_python '
 elif self._inside_extern_python:
 tag = 'extern_pytho

[pypy-commit] buildbot default: check in the changes applied locally on baroquesoftware.com

2016-02-10 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r987:f460098a5737
Date: 2016-02-10 15:08 +0100
http://bitbucket.org/pypy/buildbot/changeset/f460098a5737/

Log:check in the changes applied locally on baroquesoftware.com

diff --git a/README b/README
--- a/README
+++ b/README
@@ -50,6 +50,10 @@
 
 $ buildbot start
 
+OR
+
+$ ./restart_buildmaster_when_not_running
+
 To run a buildslave
 ===
 Please refer to README_BUILDSLAVE
diff --git a/bbhook/irc.py b/bbhook/irc.py
--- a/bbhook/irc.py
+++ b/bbhook/irc.py
@@ -44,11 +44,13 @@
 print message + '\n'
 else:
 from .main import app
-return subprocess.call([
+args = [
 app.config['BOT'],
 app.config['CHANNEL'],
 message,
-])
+]
+print args
+return subprocess.call(args)
 
 def get_short_id(owner, repo, branch):
 """
diff --git a/bot2/pypybuildbot/master.py b/bot2/pypybuildbot/master.py
--- a/bot2/pypybuildbot/master.py
+++ b/bot2/pypybuildbot/master.py
@@ -484,7 +484,7 @@
"category": 'mac32'
   },
   {"name" : JITMACOSX64,
-   "slavenames": ["rebuy-de", "xerxes", "tosh", 
"osx-10.9-x64-dw"],
+   "slavenames": ["rebuy-de", "tosh", "osx-10.9-x64-dw"],  # 
"xerxes"
'builddir' : JITMACOSX64,
'factory' : pypyJITTranslatedTestFactoryOSX64,
'category' : 'mac64',
diff --git a/bot2/pypybuildbot/util.py b/bot2/pypybuildbot/util.py
--- a/bot2/pypybuildbot/util.py
+++ b/bot2/pypybuildbot/util.py
@@ -2,7 +2,7 @@
 import socket
 
 def we_are_debugging():
-return socket.gethostname() != 'cobra'
+return socket.gethostname() != 'baroquesoftware'
 
 def load(name):
 mod = __import__(name, {}, {}, ['__all__'])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Mark these three source files as deprecated

2016-02-10 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2622:1e856d51d384
Date: 2016-02-10 15:39 +0100
http://bitbucket.org/cffi/cffi/changeset/1e856d51d384/

Log:Mark these three source files as deprecated

diff --git a/cffi/vengine_cpy.py b/cffi/vengine_cpy.py
--- a/cffi/vengine_cpy.py
+++ b/cffi/vengine_cpy.py
@@ -1,3 +1,6 @@
+#
+# DEPRECATED: implementation for ffi.verify()
+#
 import sys, imp
 from . import model, ffiplatform
 
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py
--- a/cffi/vengine_gen.py
+++ b/cffi/vengine_gen.py
@@ -1,3 +1,6 @@
+#
+# DEPRECATED: implementation for ffi.verify()
+#
 import sys, os
 import types
 
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -1,3 +1,6 @@
+#
+# DEPRECATED: implementation for ffi.verify()
+#
 import sys, os, binascii, shutil, io
 from . import __version_verifier_modules__
 from . import ffiplatform
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: update the values

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r701:26ecf707b33d
Date: 2016-02-11 11:35 +0100
http://bitbucket.org/pypy/pypy.org/changeset/26ecf707b33d/

Log:update the values

diff --git a/don3.html b/don3.html
--- a/don3.html
+++ b/don3.html
@@ -9,13 +9,13 @@
 
   $(function() {
 $("#progressbar").progressbar({
-  value: 88.6
+  value: 88.7
});
   });
 
 

-   $53152 of $6 (88.6%)
+   $53247 of $6 (88.7%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting NumPy in PyPy.
   Current status:
-we have $7941 left
+we have $8029 left
   in the account. Read proposal
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi embedding-pypy-win32: I finally managed to run the tests on Windows, but only without

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: embedding-pypy-win32
Changeset: r2623:4383aaecf96d
Date: 2016-02-11 14:57 +0100
http://bitbucket.org/cffi/cffi/changeset/4383aaecf96d/

Log:I finally managed to run the tests on Windows, but only without
changes in that file and by copying the file "libpypy-c.lib" from
translation to a subdirectory "bin" of "sys.prefix"

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -549,25 +549,24 @@
 if value not in lst:
 lst.append(value)
 #
-if sys.platform == "win32":
-# XXX pypy should not reuse the same import library name
-template = "python%d%d"
-if hasattr(sys, 'gettotalrefcount'):
-template += '_d'
+if '__pypy__' in sys.builtin_module_names:
+if hasattr(sys, 'prefix'):
+import os
+ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
+pythonlib = "pypy-c"
 else:
-if '__pypy__' in sys.builtin_module_names:
-if hasattr(sys, 'prefix'):
-import os
-ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
-pythonlib = "pypy-c"
+if sys.platform == "win32":
+template = "python%d%d"
+if hasattr(sys, 'gettotalrefcount'):
+template += '_d'
 else:
 template = "python%d.%d"
 if sysconfig.get_config_var('DEBUG_EXT'):
 template += sysconfig.get_config_var('DEBUG_EXT')
-pythonlib = (template %
-(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
-if hasattr(sys, 'abiflags'):
-pythonlib += sys.abiflags
+pythonlib = (template %
+(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
+if hasattr(sys, 'abiflags'):
+pythonlib += sys.abiflags
 ensure('libraries', pythonlib)
 if sys.platform == "win32":
 ensure('extra_link_args', '/MANIFEST')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi embedding-pypy-win32: Windows need the file 'libpypy-c.lib', which (unless people disagree) I

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: embedding-pypy-win32
Changeset: r2624:cd622fb7a0d3
Date: 2016-02-11 15:15 +0100
http://bitbucket.org/cffi/cffi/changeset/cd622fb7a0d3/

Log:Windows need the file 'libpypy-c.lib', which (unless people
disagree) I will add to pypy distributions next

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -550,10 +550,19 @@
 lst.append(value)
 #
 if '__pypy__' in sys.builtin_module_names:
-if hasattr(sys, 'prefix'):
-import os
-ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
-pythonlib = "pypy-c"
+if sys.platform == "win32":
+# we need 'libpypy-c.lib' (included with recent pypy distrib)
+# in addition to the runtime 'libpypy-c.dll'
+pythonlib = "libpypy-c"
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', sys.prefix)
+else:
+# we need 'libpypy-c.{so,dylib}', which should be by
+# default located in 'sys.prefix/bin'
+pythonlib = "pypy-c"
+if hasattr(sys, 'prefix'):
+import os
+ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
 else:
 if sys.platform == "win32":
 template = "python%d%d"
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi embedding-pypy-win32: ready to merge

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: embedding-pypy-win32
Changeset: r2625:daa3d70b58a9
Date: 2016-02-11 15:21 +0100
http://bitbucket.org/cffi/cffi/changeset/daa3d70b58a9/

Log:ready to merge

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cffi-embedding-win32: Add libpypy-c.lib to the archive on windows

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: cffi-embedding-win32
Changeset: r82159:8f955811f19a
Date: 2016-02-11 15:18 +0100
http://bitbucket.org/pypy/pypy/changeset/8f955811f19a/

Log:Add libpypy-c.lib to the archive on windows

diff --git a/pypy/tool/release/package.py b/pypy/tool/release/package.py
--- a/pypy/tool/release/package.py
+++ b/pypy/tool/release/package.py
@@ -129,6 +129,9 @@
 win_extras = ['libpypy-c.dll', 'sqlite3.dll']
 if not options.no_tk:
 win_extras += ['tcl85.dll', 'tk85.dll']
+# add the .lib too, which is convenient to compile other programs
+# that use the .dll (and for cffi's embedding mode)
+win_extras.append('libpypy-c.lib')
 
 for extra in win_extras:
 p = pypy_c.dirpath().join(extra)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: hg merge embedding-pypy-win32

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2626:6e18e1a827d0
Date: 2016-02-11 15:21 +0100
http://bitbucket.org/cffi/cffi/changeset/6e18e1a827d0/

Log:hg merge embedding-pypy-win32

Thanks matti for the initial work!

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -550,10 +550,19 @@
 lst.append(value)
 #
 if '__pypy__' in sys.builtin_module_names:
-if hasattr(sys, 'prefix'):
-import os
-ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
-pythonlib = "pypy-c"
+if sys.platform == "win32":
+# we need 'libpypy-c.lib' (included with recent pypy distrib)
+# in addition to the runtime 'libpypy-c.dll'
+pythonlib = "libpypy-c"
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', sys.prefix)
+else:
+# we need 'libpypy-c.{so,dylib}', which should be by
+# default located in 'sys.prefix/bin'
+pythonlib = "pypy-c"
+if hasattr(sys, 'prefix'):
+import os
+ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
 else:
 if sys.platform == "win32":
 template = "python%d%d"
diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -118,12 +118,18 @@
 def execute(self, name):
 path = self.get_path()
 env_extra = {'PYTHONPATH': prefix_pythonpath()}
-libpath = os.environ.get('LD_LIBRARY_PATH')
-if libpath:
-libpath = path + ':' + libpath
+if sys.platform == 'win32':
+_path = os.environ.get('PATH')
+# for libpypy-c.dll or Python27.dll
+_path = os.path.split(sys.executable)[0] + ';' + _path
+env_extra['PATH'] = _path
 else:
-libpath = path
-env_extra['LD_LIBRARY_PATH'] = libpath
+libpath = os.environ.get('LD_LIBRARY_PATH')
+if libpath:
+libpath = path + ':' + libpath
+else:
+libpath = path
+env_extra['LD_LIBRARY_PATH'] = libpath
 print('running %r in %r' % (name, path))
 executable_name = name
 if sys.platform == 'win32':
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cffi-embedding-win32: follow-up for e1b9c0216be7: move it outside pypy_setup_home(), just in

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: cffi-embedding-win32
Changeset: r82160:fcdb779aa03c
Date: 2016-02-11 15:59 +0100
http://bitbucket.org/pypy/pypy/changeset/fcdb779aa03c/

Log:follow-up for e1b9c0216be7: move it outside pypy_setup_home(), just
in case, but keep the logic. Add a comment that describes the
problem.

diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -105,10 +105,6 @@
 space.appexec([w_path], """(path):
 import sys
 sys.path[:] = path
-import os
-sys.stdin  = sys.__stdin__  = os.fdopen(0, 'rb', 0)
-sys.stdout = sys.__stdout__ = os.fdopen(1, 'wb', 0)
-sys.stderr = sys.__stderr__ = os.fdopen(2, 'wb', 0)
 """)
 # import site
 try:
diff --git a/pypy/module/_cffi_backend/embedding.py 
b/pypy/module/_cffi_backend/embedding.py
--- a/pypy/module/_cffi_backend/embedding.py
+++ b/pypy/module/_cffi_backend/embedding.py
@@ -56,6 +56,24 @@
 must_leave = False
 try:
 must_leave = space.threadlocals.try_enter_thread(space)
+
+# Annoying: CPython would just use the C-level
+# std{in,out,err} as configured by the main application,
+# for example in binary mode on Windows or with buffering
+# turned off.  We can't easily do the same.  Instead, go
+# for the safest bet (but possibly bad for performance)
+# and open sys.std{in,out,err} unbuffered.  On Windows I
+# guess binary mode is a better default choice.
+#
+# XXX if needed, we could add support for a flag passed to
+# this function.
+space.appexec([], """():
+import os
+sys.stdin  = sys.__stdin__  = os.fdopen(0, 'rb', 0)
+sys.stdout = sys.__stdout__ = os.fdopen(1, 'wb', 0)
+sys.stderr = sys.__stderr__ = os.fdopen(2, 'wb', 0)
+""")
+
 load_embedded_cffi_module(space, version, init_struct)
 res = 0
 except OperationError, operr:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: hg backout 338d32e89981

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82163:6c6109b79b23
Date: 2016-02-11 16:08 +0100
http://bitbucket.org/pypy/pypy/changeset/6c6109b79b23/

Log:hg backout 338d32e89981

will be fixed by the following merge

diff --git a/pypy/module/_cffi_backend/embedding.py 
b/pypy/module/_cffi_backend/embedding.py
--- a/pypy/module/_cffi_backend/embedding.py
+++ b/pypy/module/_cffi_backend/embedding.py
@@ -84,68 +84,11 @@
 return rffi.cast(rffi.INT, res)
 
 # 
-if os.name == 'nt':
-do_startup = r'''
-#include 
-#define WIN32_LEAN_AND_MEAN
-#include 
-RPY_EXPORTED void rpython_startup_code(void);
-RPY_EXPORTED int pypy_setup_home(char *, int);
 
-static unsigned char _cffi_ready = 0;
-static const char *volatile _cffi_module_name;
 
-static void _cffi_init_error(const char *msg, const char *extra)
-{
-fprintf(stderr,
-"\nPyPy initialization failure when loading module '%s':\n%s%s\n",
-_cffi_module_name, msg, extra);
-}
-
-BOOL CALLBACK _cffi_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex)
-{
-
-HMODULE hModule;
-TCHAR home[_MAX_PATH];
-rpython_startup_code();
-RPyGilAllocate();
-
-GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 
-   GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
-   (LPCTSTR)&_cffi_init, &hModule);
-if (hModule == 0 ) {
-/* TODO turn the int into a string with FormatMessage */
-
-_cffi_init_error("dladdr() failed: ", "");
-return TRUE;
-}
-GetModuleFileName(hModule, home, _MAX_PATH);
-if (pypy_setup_home(home, 1) != 0) {
-_cffi_init_error("pypy_setup_home() failed", "");
-return TRUE;
-}
-_cffi_ready = 1;
-fprintf(stderr, "startup succeeded, home %s\n", home);
-return TRUE;
-}
-
-RPY_EXPORTED
-int pypy_carefully_make_gil(const char *name)
-{
-/* For CFFI: this initializes the GIL and loads the home path.
-   It can be called completely concurrently from unrelated threads.
-   It assumes that we don't hold the GIL before (if it exists), and we
-   don't hold it afterwards.
-*/
-static INIT_ONCE s_init_once;
-
-_cffi_module_name = name;/* not really thread-safe, but better than
-nothing */
-InitOnceExecuteOnce(&s_init_once, _cffi_init, NULL, NULL);
-return (int)_cffi_ready - 1;
-}'''
-else:
-do_startup = r"""
+eci = ExternalCompilationInfo(separate_module_sources=[
+r"""
+/* XXX Windows missing */
 #include 
 #include 
 #include 
@@ -198,7 +141,6 @@
 pthread_once(&once_control, _cffi_init);
 return (int)_cffi_ready - 1;
 }
-"""
-eci = ExternalCompilationInfo(separate_module_sources=[do_startup])
+"""])
 
 declare_c_function = rffi.llexternal_use_eci(eci)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: kill unused import

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82165:8dd4fb6cbbc4
Date: 2016-02-11 16:10 +0100
http://bitbucket.org/pypy/pypy/changeset/8dd4fb6cbbc4/

Log:kill unused import

diff --git a/pypy/module/_cffi_backend/test/test_ztranslation.py 
b/pypy/module/_cffi_backend/test/test_ztranslation.py
--- a/pypy/module/_cffi_backend/test/test_ztranslation.py
+++ b/pypy/module/_cffi_backend/test/test_ztranslation.py
@@ -4,7 +4,7 @@
 
 # side-effect: FORMAT_LONGDOUBLE must be built before test_checkmodule()
 from pypy.module._cffi_backend import misc
-from pypy.module._cffi_backend import cffi1_module, embedding
+from pypy.module._cffi_backend import embedding
 
 
 def test_checkmodule():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cffi-embedding-win32: Do this patching only once

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: cffi-embedding-win32
Changeset: r82161:bea8f2df95f8
Date: 2016-02-11 16:02 +0100
http://bitbucket.org/pypy/pypy/changeset/bea8f2df95f8/

Log:Do this patching only once

diff --git a/pypy/module/_cffi_backend/__init__.py 
b/pypy/module/_cffi_backend/__init__.py
--- a/pypy/module/_cffi_backend/__init__.py
+++ b/pypy/module/_cffi_backend/__init__.py
@@ -69,6 +69,7 @@
 def startup(self, space):
 from pypy.module._cffi_backend import embedding
 embedding.glob.space = space
+embedding.glob.patched_sys = False
 
 
 def get_dict_rtld_constants():
diff --git a/pypy/module/_cffi_backend/embedding.py 
b/pypy/module/_cffi_backend/embedding.py
--- a/pypy/module/_cffi_backend/embedding.py
+++ b/pypy/module/_cffi_backend/embedding.py
@@ -45,6 +45,26 @@
 pass
 glob = Global()
 
+def patch_sys(space):
+# Annoying: CPython would just use the C-level std{in,out,err} as
+# configured by the main application, for example in binary mode
+# on Windows or with buffering turned off.  We can't easily do the
+# same.  Instead, go for the safest bet (but possibly bad for
+# performance) and open sys.std{in,out,err} unbuffered.  On
+# Windows I guess binary mode is a better default choice.
+#
+# XXX if needed, we could add support for a flag passed to
+# pypy_init_embedded_cffi_module().
+if not glob.patched_sys:
+space.appexec([], """():
+import os
+sys.stdin  = sys.__stdin__  = os.fdopen(0, 'rb', 0)
+sys.stdout = sys.__stdout__ = os.fdopen(1, 'wb', 0)
+sys.stderr = sys.__stderr__ = os.fdopen(2, 'wb', 0)
+""")
+glob.patched_sys = True
+
+
 def pypy_init_embedded_cffi_module(version, init_struct):
 # called from __init__.py
 name = "?"
@@ -56,24 +76,7 @@
 must_leave = False
 try:
 must_leave = space.threadlocals.try_enter_thread(space)
-
-# Annoying: CPython would just use the C-level
-# std{in,out,err} as configured by the main application,
-# for example in binary mode on Windows or with buffering
-# turned off.  We can't easily do the same.  Instead, go
-# for the safest bet (but possibly bad for performance)
-# and open sys.std{in,out,err} unbuffered.  On Windows I
-# guess binary mode is a better default choice.
-#
-# XXX if needed, we could add support for a flag passed to
-# this function.
-space.appexec([], """():
-import os
-sys.stdin  = sys.__stdin__  = os.fdopen(0, 'rb', 0)
-sys.stdout = sys.__stdout__ = os.fdopen(1, 'wb', 0)
-sys.stderr = sys.__stderr__ = os.fdopen(2, 'wb', 0)
-""")
-
+patch_sys(space)
 load_embedded_cffi_module(space, version, init_struct)
 res = 0
 except OperationError, operr:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: hg merge cffi-embedding-win32

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82164:450c1a29e5d3
Date: 2016-02-11 16:09 +0100
http://bitbucket.org/pypy/pypy/changeset/450c1a29e5d3/

Log:hg merge cffi-embedding-win32

Support for cffi embedding on Windows. Thanks matti for the initial
work

diff --git a/pypy/module/_cffi_backend/__init__.py 
b/pypy/module/_cffi_backend/__init__.py
--- a/pypy/module/_cffi_backend/__init__.py
+++ b/pypy/module/_cffi_backend/__init__.py
@@ -69,6 +69,7 @@
 def startup(self, space):
 from pypy.module._cffi_backend import embedding
 embedding.glob.space = space
+embedding.glob.patched_sys = False
 
 
 def get_dict_rtld_constants():
diff --git a/pypy/module/_cffi_backend/embedding.py 
b/pypy/module/_cffi_backend/embedding.py
--- a/pypy/module/_cffi_backend/embedding.py
+++ b/pypy/module/_cffi_backend/embedding.py
@@ -45,6 +45,26 @@
 pass
 glob = Global()
 
+def patch_sys(space):
+# Annoying: CPython would just use the C-level std{in,out,err} as
+# configured by the main application, for example in binary mode
+# on Windows or with buffering turned off.  We can't easily do the
+# same.  Instead, go for the safest bet (but possibly bad for
+# performance) and open sys.std{in,out,err} unbuffered.  On
+# Windows I guess binary mode is a better default choice.
+#
+# XXX if needed, we could add support for a flag passed to
+# pypy_init_embedded_cffi_module().
+if not glob.patched_sys:
+space.appexec([], """():
+import os
+sys.stdin  = sys.__stdin__  = os.fdopen(0, 'rb', 0)
+sys.stdout = sys.__stdout__ = os.fdopen(1, 'wb', 0)
+sys.stderr = sys.__stderr__ = os.fdopen(2, 'wb', 0)
+""")
+glob.patched_sys = True
+
+
 def pypy_init_embedded_cffi_module(version, init_struct):
 # called from __init__.py
 name = "?"
@@ -56,6 +76,7 @@
 must_leave = False
 try:
 must_leave = space.threadlocals.try_enter_thread(space)
+patch_sys(space)
 load_embedded_cffi_module(space, version, init_struct)
 res = 0
 except OperationError, operr:
@@ -85,14 +106,86 @@
 
 # 
 
+if os.name == 'nt':
 
-eci = ExternalCompilationInfo(separate_module_sources=[
-r"""
-/* XXX Windows missing */
-#include 
+do_includes = r"""
+#define _WIN32_WINNT 0x0501
+#include 
+
+#define CFFI_INIT_HOME_PATH_MAX  _MAX_PATH
+static void _cffi_init(void);
+static void _cffi_init_error(const char *msg, const char *extra);
+
+static int _cffi_init_home(char *output_home_path)
+{
+HMODULE hModule = 0;
+DWORD res;
+
+GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 
+   GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+   (LPCTSTR)&_cffi_init, &hModule);
+
+if (hModule == 0 ) {
+_cffi_init_error("GetModuleHandleEx() failed", "");
+return -1;
+}
+res = GetModuleFileName(hModule, output_home_path, 
CFFI_INIT_HOME_PATH_MAX);
+if (res >= CFFI_INIT_HOME_PATH_MAX) {
+return -1;
+}
+return 0;
+}
+
+static void _cffi_init_once(void)
+{
+static LONG volatile lock = 0;
+static int _init_called = 0;
+
+while (InterlockedCompareExchange(&lock, 1, 0) != 0) {
+ SwitchToThread();/* spin loop */
+}
+if (!_init_called) {
+_cffi_init();
+_init_called = 1;
+}
+InterlockedCompareExchange(&lock, 0, 1);
+}
+"""
+
+else:
+
+do_includes = r"""
 #include 
 #include 
 
+#define CFFI_INIT_HOME_PATH_MAX  PATH_MAX
+static void _cffi_init(void);
+static void _cffi_init_error(const char *msg, const char *extra);
+
+static int _cffi_init_home(char *output_home_path)
+{
+Dl_info info;
+dlerror();   /* reset */
+if (dladdr(&_cffi_init, &info) == 0) {
+_cffi_init_error("dladdr() failed: ", dlerror());
+return -1;
+}
+if (realpath(info.dli_fname, output_home_path) == NULL) {
+perror("realpath() failed");
+_cffi_init_error("realpath() failed", "");
+return -1;
+}
+return 0;
+}
+
+static void _cffi_init_once(void)
+{
+static pthread_once_t once_control = PTHREAD_ONCE_INIT;
+pthread_once(&once_control, _cffi_init);
+}
+"""
+
+do_startup = do_includes + r"""
 RPY_EXPORTED void rpython_startup_code(void);
 RPY_EXPORTED int pypy_setup_home(char *, int);
 
@@ -108,17 +201,13 @@
 
 static void _cffi_init(void)
 {
-Dl_info info;
-char *home;
+char home[CFFI_INIT_HOME_PATH_MAX + 1];
 
 rpython_startup_code();
 RPyGilAllocate();
 
-if (dladdr(&_cffi_init, &info) == 0) {
-_cffi_init_error("dladdr() failed: ", dlerror());
+if (_cffi_init_home(home) != 0)
 return;
-}
-home = realpath(info.dli_fname, NULL);
 if (pypy_setup_home(home, 1) != 0) {
 _cffi_init_error("pypy_setup_home() failed", "");
 return;
@@ -134,13 

[pypy-commit] pypy cffi-embedding-win32: ready for merge

2016-02-11 Thread arigo
Author: Armin Rigo 
Branch: cffi-embedding-win32
Changeset: r82162:4c93a9cebb3e
Date: 2016-02-11 16:06 +0100
http://bitbucket.org/pypy/pypy/changeset/4c93a9cebb3e/

Log:ready for merge

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Aaaaaa finally found and fix an issue with stacklets on shadowstack

2016-02-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82188:1929d5b7982f
Date: 2016-02-12 18:44 +0100
http://bitbucket.org/pypy/pypy/changeset/1929d5b7982f/

Log:Aa finally found and fix an issue with stacklets on shadowstack

diff --git a/rpython/rlib/_stacklet_shadowstack.py 
b/rpython/rlib/_stacklet_shadowstack.py
--- a/rpython/rlib/_stacklet_shadowstack.py
+++ b/rpython/rlib/_stacklet_shadowstack.py
@@ -30,6 +30,11 @@
 mixlevelannotator.finish()
 lltype.attachRuntimeTypeInfo(STACKLET, destrptr=destrptr)
 
+# Note: it's important that this is a light finalizer, otherwise
+# the GC will call it but still expect the object to stay around for
+# a while---and it can't stay around, because s_sscopy points to
+# freed nonsense and customtrace() will crash
+@rgc.must_be_light_finalizer
 def stacklet_destructor(stacklet):
 sscopy = stacklet.s_sscopy
 if sscopy:
diff --git a/rpython/translator/backendopt/finalizer.py 
b/rpython/translator/backendopt/finalizer.py
--- a/rpython/translator/backendopt/finalizer.py
+++ b/rpython/translator/backendopt/finalizer.py
@@ -18,7 +18,7 @@
 """
 ok_operations = ['ptr_nonzero', 'ptr_eq', 'ptr_ne', 'free', 'same_as',
  'direct_ptradd', 'force_cast', 'track_alloc_stop',
- 'raw_free']
+ 'raw_free', 'adr_eq', 'adr_ne']
 
 def analyze_light_finalizer(self, graph):
 result = self.analyze_direct_call(graph)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi release-1.5: hg merge default

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: release-1.5
Changeset: r2627:1a2d841f7896
Date: 2016-02-13 09:54 +0100
http://bitbucket.org/cffi/cffi/changeset/1a2d841f7896/

Log:hg merge default

diff --git a/MANIFEST.in b/MANIFEST.in
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,6 +1,6 @@
 recursive-include cffi *.py *.h
 recursive-include c *.c *.h *.asm *.py win64.obj
-recursive-include testing *.py
+recursive-include testing *.py *.c *.h
 recursive-include doc *.py *.rst Makefile *.bat
-recursive-include demo py.cleanup *.py manual.c
+recursive-include demo py.cleanup *.py embedding_test.c manual.c
 include AUTHORS LICENSE setup.py setup_base.py
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2,7 +2,7 @@
 #include 
 #include "structmember.h"
 
-#define CFFI_VERSION  "1.5.0"
+#define CFFI_VERSION  "1.5.1"
 
 #ifdef MS_WIN32
 #include 
diff --git a/c/call_python.c b/c/call_python.c
--- a/c/call_python.c
+++ b/c/call_python.c
@@ -115,6 +115,7 @@
 static int _update_cache_to_call_python(struct _cffi_externpy_s *externpy)
 {
 PyObject *interpstate_dict, *interpstate_key, *infotuple, *old1, *new1;
+PyObject *old2;
 
 interpstate_dict = _get_interpstate_dict();
 if (interpstate_dict == NULL)
@@ -127,14 +128,17 @@
 infotuple = PyDict_GetItem(interpstate_dict, interpstate_key);
 Py_DECREF(interpstate_key);
 if (infotuple == NULL)
-return 1;/* no ffi.def_extern() from this subinterpreter */
+return 3;/* no ffi.def_extern() from this subinterpreter */
 
 new1 = PyThreadState_GET()->interp->modules;
 Py_INCREF(new1);
+Py_INCREF(infotuple);
 old1 = (PyObject *)externpy->reserved1;
+old2 = (PyObject *)externpy->reserved2;
 externpy->reserved1 = new1; /* holds a reference*/
-externpy->reserved2 = infotuple;/* doesn't hold a reference */
+externpy->reserved2 = infotuple;/* holds a reference (issue #246) */
 Py_XDECREF(old1);
+Py_XDECREF(old2);
 
 return 0;   /* no error */
 
@@ -213,9 +217,11 @@
 gil_release(state);
 }
 if (err) {
-static const char *msg[2] = {
+static const char *msg[] = {
 "no code was attached to it yet with @ffi.def_extern()",
-"got internal exception (out of memory?)" };
+"got internal exception (out of memory / shutdown issue)",
+"@ffi.def_extern() was not called in the current subinterpreter",
+};
 fprintf(stderr, "extern \"Python\": function %s() called, "
 "but %s.  Returning 0.\n", externpy->name, msg[err-1]);
 memset(args, 0, externpy->size_of_result);
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -12,7 +12,7 @@
 # 
 
 import sys
-assert __version__ == "1.5.0", ("This test_c.py file is for testing a version"
+assert __version__ == "1.5.1", ("This test_c.py file is for testing a version"
 " of cffi that differs from the one that we"
 " get from 'import _cffi_backend'")
 if sys.version_info < (3,):
diff --git a/cffi/__init__.py b/cffi/__init__.py
--- a/cffi/__init__.py
+++ b/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.5.0"
-__version_info__ = (1, 5, 0)
+__version__ = "1.5.1"
+__version_info__ = (1, 5, 1)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -231,6 +231,12 @@
 ((got_nonpos) == (expected <= 0) && \
  (got) == (unsigned long long)expected)
 
+#ifdef MS_WIN32
+# define _cffi_stdcall  __stdcall
+#else
+# define _cffi_stdcall  /* nothing */
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/cffi/_embedding.h b/cffi/_embedding.h
--- a/cffi/_embedding.h
+++ b/cffi/_embedding.h
@@ -233,7 +233,7 @@
 f = PySys_GetObject((char *)"stderr");
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.5.0"
+   "\ncompiled with cffi version: 1.5.1"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -1,4 +1,4 @@
-import sys, types
+import sys, sysconfig, types
 from .lock import allocate_lock
 
 try:
@@ -550,17 +550,28 @@
 lst.append(value)
 #
 if '__pypy__' in sys.builtin_module_names:
-if hasattr(sys, 'prefix'):
- 

[pypy-commit] cffi default: Pfff, debug=True goes in the way on Windows if you don't explicitly

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2628:3c3b6f19b5f6
Date: 2016-02-13 10:20 +0100
http://bitbucket.org/cffi/cffi/changeset/3c3b6f19b5f6/

Log:Pfff, debug=True goes in the way on Windows if you don't explicitly
have the debug version of the MS CRT installed first

diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -100,6 +100,7 @@
 c = distutils.ccompiler.new_compiler()
 print('compiling %s with %r' % (name, modules))
 extra_preargs = []
+debug = True
 if sys.platform == 'win32':
 libfiles = []
 for m in modules:
@@ -108,9 +109,12 @@
 libfiles.append('Release\\%s.lib' % m[:-4])
 modules = libfiles
 extra_preargs.append('/MANIFEST')
+debug = False# you need to install extra stuff
+ # for this to work
 elif threads:
 extra_preargs.append('-pthread')
-objects = c.compile([filename], macros=sorted(defines.items()), 
debug=True)
+objects = c.compile([filename], macros=sorted(defines.items()),
+debug=debug)
 c.link_executable(objects + modules, name, 
extra_preargs=extra_preargs)
 finally:
 os.chdir(curdir)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi release-1.5: hg merge default

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: release-1.5
Changeset: r2630:e877261953bc
Date: 2016-02-13 10:29 +0100
http://bitbucket.org/cffi/cffi/changeset/e877261953bc/

Log:hg merge default

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -551,8 +551,10 @@
 #
 if '__pypy__' in sys.builtin_module_names:
 if sys.platform == "win32":
-# we need 'libpypy-c.lib' (included with recent pypy distrib)
-# in addition to the runtime 'libpypy-c.dll'
+# we need 'libpypy-c.lib'.  Right now, distributions of
+# pypy contain it as 'include/python27.lib'.  You need
+# to manually copy it back to 'libpypy-c.lib'.  XXX Will
+# be fixed in the next pypy release.
 pythonlib = "libpypy-c"
 if hasattr(sys, 'prefix'):
 ensure('library_dirs', sys.prefix)
diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -100,6 +100,7 @@
 c = distutils.ccompiler.new_compiler()
 print('compiling %s with %r' % (name, modules))
 extra_preargs = []
+debug = True
 if sys.platform == 'win32':
 libfiles = []
 for m in modules:
@@ -108,9 +109,12 @@
 libfiles.append('Release\\%s.lib' % m[:-4])
 modules = libfiles
 extra_preargs.append('/MANIFEST')
+debug = False# you need to install extra stuff
+ # for this to work
 elif threads:
 extra_preargs.append('-pthread')
-objects = c.compile([filename], macros=sorted(defines.items()), 
debug=True)
+objects = c.compile([filename], macros=sorted(defines.items()),
+debug=debug)
 c.link_executable(objects + modules, name, 
extra_preargs=extra_preargs)
 finally:
 os.chdir(curdir)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Mention it's work in progress

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2629:9fc77fff3e63
Date: 2016-02-13 10:29 +0100
http://bitbucket.org/cffi/cffi/changeset/9fc77fff3e63/

Log:Mention it's work in progress

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -551,8 +551,10 @@
 #
 if '__pypy__' in sys.builtin_module_names:
 if sys.platform == "win32":
-# we need 'libpypy-c.lib' (included with recent pypy distrib)
-# in addition to the runtime 'libpypy-c.dll'
+# we need 'libpypy-c.lib'.  Right now, distributions of
+# pypy contain it as 'include/python27.lib'.  You need
+# to manually copy it back to 'libpypy-c.lib'.  XXX Will
+# be fixed in the next pypy release.
 pythonlib = "libpypy-c"
 if hasattr(sys, 'prefix'):
 ensure('library_dirs', sys.prefix)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi release-1.5: md5/sha1

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: release-1.5
Changeset: r2631:2d6f6fc88726
Date: 2016-02-13 10:31 +0100
http://bitbucket.org/cffi/cffi/changeset/2d6f6fc88726/

Log:md5/sha1

diff --git a/doc/source/installation.rst b/doc/source/installation.rst
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -53,9 +53,9 @@
 
 * http://pypi.python.org/packages/source/c/cffi/cffi-1.5.1.tar.gz
 
-   - MD5: ...
+   - MD5: ac9a3c7724bd7a4f3c0d4f6ffef2c6c7
 
-   - SHA: ...
+   - SHA: 933f7ea6f48ebbaf4794a1a807ae6f5ec232c83b
 
 * Or grab the most current version from the `Bitbucket page`_:
   ``hg clone https://bitbucket.org/cffi/cffi``
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: hg merge release-1.5

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2632:3ea5159b897c
Date: 2016-02-13 10:31 +0100
http://bitbucket.org/cffi/cffi/changeset/3ea5159b897c/

Log:hg merge release-1.5

diff --git a/doc/source/installation.rst b/doc/source/installation.rst
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -53,9 +53,9 @@
 
 * http://pypi.python.org/packages/source/c/cffi/cffi-1.5.1.tar.gz
 
-   - MD5: ...
+   - MD5: ac9a3c7724bd7a4f3c0d4f6ffef2c6c7
 
-   - SHA: ...
+   - SHA: 933f7ea6f48ebbaf4794a1a807ae6f5ec232c83b
 
 * Or grab the most current version from the `Bitbucket page`_:
   ``hg clone https://bitbucket.org/cffi/cffi``
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: in-progress: rewrite tupleobject.py to be similar to stringobject.py

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82216:b54a2a1a9efb
Date: 2016-02-13 16:09 +0100
http://bitbucket.org/pypy/pypy/changeset/b54a2a1a9efb/

Log:in-progress: rewrite tupleobject.py to be similar to stringobject.py
for similar reasons (documented)

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -497,7 +497,7 @@
 GLOBALS['%s#' % (cpyname, )] = ('PyTypeObject*', pypyexpr)
 
 for cpyname in '''PyMethodObject PyListObject PyLongObject
-  PyDictObject PyTupleObject PyClassObject'''.split():
+  PyDictObject PyClassObject'''.split():
 FORWARD_DECLS.append('typedef struct { PyObject_HEAD } %s'
  % (cpyname, ))
 build_exported_objects()
diff --git a/pypy/module/cpyext/include/tupleobject.h 
b/pypy/module/cpyext/include/tupleobject.h
--- a/pypy/module/cpyext/include/tupleobject.h
+++ b/pypy/module/cpyext/include/tupleobject.h
@@ -7,11 +7,21 @@
 extern "C" {
 #endif
 
+typedef struct {
+PyObject_HEAD
+Py_ssize_t ob_size;
+PyObject **ob_item;/* XXX optimize to ob_item[] */
+} PyTupleObject;
+
 /* defined in varargswrapper.c */
 PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
 
-#define PyTuple_SET_ITEM PyTuple_SetItem
-#define PyTuple_GET_ITEM PyTuple_GetItem
+/* Macro, trading safety for speed */
+#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
+#define PyTuple_GET_SIZE(op)Py_SIZE(op)
+
+/* Macro, *only* to be used to fill in brand new tuples */
+#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
 
 
 #ifdef __cplusplus
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
@@ -185,24 +185,6 @@
 assert py_obj
 rawrefcount.create_link_pypy(w_obj, py_obj)
 
-def make_ref(space, w_obj):
-"""
-Returns a new reference to an intepreter object.
-"""
-GOES_AWAY
-if w_obj is None:
-return lltype.nullptr(PyObject.TO)
-assert isinstance(w_obj, W_Root)
-state = space.fromcache(RefcountState)
-try:
-py_obj = state.py_objects_w2r[w_obj]
-except KeyError:
-py_obj = create_ref(space, w_obj)
-track_reference(space, py_obj, w_obj)
-else:
-Py_IncRef(space, py_obj)
-return py_obj
-
 
 def from_ref(space, ref):
 """
diff --git a/pypy/module/cpyext/test/test_tupleobject.py 
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -1,6 +1,8 @@
 import py
 
 from pypy.module.cpyext.pyobject import PyObject, PyObjectP, make_ref, from_ref
+from pypy.module.cpyext.pyobject import as_pyobj
+from pypy.module.cpyext.tupleobject import PyTupleObject
 from pypy.module.cpyext.test.test_api import BaseApiTest
 from rpython.rtyper.lltypesystem import rffi, lltype
 
@@ -10,25 +12,35 @@
 def test_tupleobject(self, space, api):
 assert not api.PyTuple_Check(space.w_None)
 assert api.PyTuple_SetItem(space.w_None, 0, space.w_None) == -1
-atuple = space.newtuple([0, 1, 'yay'])
+atuple = space.newtuple([space.wrap(0), space.wrap(1),
+ space.wrap('yay')])
 assert api.PyTuple_Size(atuple) == 3
-assert api.PyTuple_GET_SIZE(atuple) == 3
+#assert api.PyTuple_GET_SIZE(atuple) == 3  --- now a C macro
 raises(TypeError, api.PyTuple_Size(space.newlist([])))
 api.PyErr_Clear()
 
 def test_tuple_resize(self, space, api):
+w_42 = space.wrap(42)
+ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
+
 py_tuple = api.PyTuple_New(3)
-ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
-ar[0] = rffi.cast(PyObject, make_ref(space, py_tuple))
+rffi.cast(PyTupleObject, py_tuple).c_ob_item[0] = as_pyobj(space, w_42)
+ar[0] = py_tuple
 api._PyTuple_Resize(ar, 2)
-py_tuple = from_ref(space, ar[0])
-assert space.int_w(space.len(py_tuple)) == 2
-
+w_tuple = from_ref(space, ar[0])
+assert space.int_w(space.len(w_tuple)) == 2
+assert space.int_w(space.getitem(w_tuple, space.wrap(0))) == 42
+api.Py_DecRef(ar[0])
+
+py_tuple = api.PyTuple_New(3)
+rffi.cast(PyTupleObject, py_tuple).c_ob_item[0] = as_pyobj(space, w_42)
+ar[0] = py_tuple
 api._PyTuple_Resize(ar, 10)
-py_tuple = from_ref(space, ar[0])
-assert space.int_w(space.len(py_tuple)) == 10
-
+w_tuple = from_ref(space, ar[0])
+assert space.int_w(space.len(w_tuple)) == 10
+assert space.int_w(space.getitem(w_tuple, space.wrap(0))) == 42
 api.Py_DecRef(ar[0])
+
 lltype.free(ar, flavor='raw')
 
 def test_setitem(self, space, api):
diff --git a/pypy/mod

[pypy-commit] pypy default: merge heads

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82217:df6d9eeb2d42
Date: 2016-02-13 16:10 +0100
http://bitbucket.org/pypy/pypy/changeset/df6d9eeb2d42/

Log:merge heads

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -36,13 +36,13 @@
 "cStringIO", "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array",
 "binascii", "_multiprocessing", '_warnings', "_collections",
 "_multibytecodec", "micronumpy", "_continuation", "_cffi_backend",
-"_csv", "cppyy", "_pypyjson"
+"_csv", "cppyy", "_pypyjson", "_vmprof",
 ])
 
-if ((sys.platform.startswith('linux') or sys.platform == 'darwin')
-and os.uname()[4] == 'x86_64' and sys.maxint > 2**32):
+#if ((sys.platform.startswith('linux') or sys.platform == 'darwin')
+#and os.uname()[4] == 'x86_64' and sys.maxint > 2**32):
 # it's not enough that we get x86_64
-working_modules.add('_vmprof')
+#working_modules.add('_vmprof')
 
 translation_modules = default_modules.copy()
 translation_modules.update([
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -306,7 +306,7 @@
 return None
 
 
-class W_InterpIterable(W_Root):
+class InterpIterable(object):
 def __init__(self, space, w_iterable):
 self.w_iter = space.iter(w_iterable)
 self.space = space
@@ -745,9 +745,13 @@
 return self.int_w(self.hash(w_obj))
 
 def len_w(self, w_obj):
-"""shotcut for space.int_w(space.len(w_obj))"""
+"""shortcut for space.int_w(space.len(w_obj))"""
 return self.int_w(self.len(w_obj))
 
+def contains_w(self, w_container, w_item):
+"""shortcut for space.is_true(space.contains(w_container, w_item))"""
+return self.is_true(self.contains(w_container, w_item))
+
 def setitem_str(self, w_obj, key, w_value):
 return self.setitem(w_obj, self.wrap(key), w_value)
 
@@ -846,7 +850,7 @@
 return lst_w[:] # make the resulting list resizable
 
 def iteriterable(self, w_iterable):
-return W_InterpIterable(self, w_iterable)
+return InterpIterable(self, w_iterable)
 
 def _unpackiterable_unknown_length(self, w_iterator, w_iterable):
 """Unpack an iterable of unknown length into an interp-level
@@ -1237,7 +1241,7 @@
 if not isinstance(statement, PyCode):
 raise TypeError('space.exec_(): expected a string, code or PyCode 
object')
 w_key = self.wrap('__builtins__')
-if not self.is_true(self.contains(w_globals, w_key)):
+if not self.contains_w(w_globals, w_key):
 self.setitem(w_globals, w_key, self.wrap(self.builtin))
 return statement.exec_code(self, w_globals, w_locals)
 
diff --git a/pypy/module/__builtin__/interp_classobj.py 
b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -20,7 +20,7 @@
 if not space.isinstance_w(w_dict, space.w_dict):
 raise_type_err(space, 'bases', 'tuple', w_bases)
 
-if not space.is_true(space.contains(w_dict, space.wrap("__doc__"))):
+if not space.contains_w(w_dict, space.wrap("__doc__")):
 space.setitem(w_dict, space.wrap("__doc__"), space.w_None)
 
 # XXX missing: lengthy and obscure logic about "__module__"
diff --git a/pypy/module/_demo/test/test_import.py 
b/pypy/module/_demo/test/test_import.py
--- a/pypy/module/_demo/test/test_import.py
+++ b/pypy/module/_demo/test/test_import.py
@@ -12,8 +12,7 @@
 w_modules = space.sys.get('modules')
 
 assert _demo.Module.demo_events == ['setup']
-assert not space.is_true(space.contains(w_modules,
-space.wrap('_demo')))
+assert not space.contains_w(w_modules, space.wrap('_demo'))
 
 # first import
 w_import = space.builtin.get('__import__')
diff --git a/pypy/module/_vmprof/interp_vmprof.py 
b/pypy/module/_vmprof/interp_vmprof.py
--- a/pypy/module/_vmprof/interp_vmprof.py
+++ b/pypy/module/_vmprof/interp_vmprof.py
@@ -60,7 +60,7 @@
 Must be smaller than 1.0
 """
 w_modules = space.sys.get('modules')
-if space.is_true(space.contains(w_modules, space.wrap('_continuation'))):
+if space.contains_w(w_modules, space.wrap('_continuation')):
 space.warn(space.wrap("Using _continuation/greenlet/stacklet together "
   "with vmprof will crash"),
space.w_RuntimeWarning)
diff --git a/pypy/module/cpyext/test/test_dictobject.py 
b/pypy/module/cpyext/test/test_dictobject.py
--- a/pypy/module/cpyext/test/test_dictobject.py
+++ b/pypy/module/cpyext/test/test_dictobject.py
@@ -146,7 +146,7 @@
 def test_dictproxy(self, space, api):
 w_dict = space.sys.get('modules')
 w_proxy = api.PyDictProxy_New(w_dict)
-assert sp

[pypy-commit] pypy default: Document this fix here

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82215:191e5c069244
Date: 2016-02-12 19:03 +0100
http://bitbucket.org/pypy/pypy/changeset/191e5c069244/

Log:Document this fix here

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -7,6 +7,9 @@
 
 Fixed ``_PyLong_FromByteArray()``, which was buggy.
 
+Fixed a crash with stacklets (or greenlets) on non-Linux machines
+which showed up if you forget stacklets without resuming them.
+
 .. branch: numpy-1.10
 
 Fix tests to run cleanly with -A and start to fix micronumpy for upstream numpy
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: test_tuple_resize passes again

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82218:400bb271c619
Date: 2016-02-13 16:15 +0100
http://bitbucket.org/pypy/pypy/changeset/400bb271c619/

Log:test_tuple_resize passes again

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -828,6 +828,7 @@
 modulename = py.path.local(eci.libraries[-1])
 
 def dealloc_trigger():
+from pypy.module.cpyext.pyobject import _Py_Dealloc
 print 'dealloc_trigger...'
 while True:
 ob = rawrefcount.next_dead(PyObject)
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
@@ -317,7 +317,7 @@
 
 @cpython_api([PyObject], lltype.Void)
 def Py_IncRef(space, obj):
-incref(obj)
+incref(space, obj)
 
 @cpython_api([PyObject], lltype.Void)
 def Py_DecRef(space, obj):
@@ -332,11 +332,11 @@
 
 @cpython_api([PyObject], lltype.Void)
 def _Py_Dealloc(space, obj):
-from pypy.module.cpyext.api import generic_cpy_call_dont_decref
+from pypy.module.cpyext.api import generic_cpy_call
 pto = obj.c_ob_type
 #print >>sys.stderr, "Calling dealloc slot", pto.c_tp_dealloc, "of", obj, \
 #  "'s type which is", rffi.charp2str(pto.c_tp_name)
-generic_cpy_call_dont_decref(space, pto.c_tp_dealloc, obj)
+generic_cpy_call(space, pto.c_tp_dealloc, obj)
 
 @cpython_api([rffi.VOIDP], lltype.Signed, error=CANNOT_FAIL)
 def _Py_HashPointer(space, ptr):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix this test: can't any more call PyTuple_SetItem() on already-realized tuples

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82219:4564af2cb7ed
Date: 2016-02-13 16:27 +0100
http://bitbucket.org/pypy/pypy/changeset/4564af2cb7ed/

Log:fix this test: can't any more call PyTuple_SetItem() on already-
realized tuples

diff --git a/pypy/module/cpyext/test/test_tupleobject.py 
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -44,16 +44,13 @@
 lltype.free(ar, flavor='raw')
 
 def test_setitem(self, space, api):
-atuple = space.newtuple([space.wrap(0), space.wrap("hello")])
-assert api.PyTuple_Size(atuple) == 2
-assert space.eq_w(space.getitem(atuple, space.wrap(0)), space.wrap(0))
-assert space.eq_w(space.getitem(atuple, space.wrap(1)), 
space.wrap("hello"))
-w_obj = space.wrap(1)
-api.Py_IncRef(w_obj)
-api.PyTuple_SetItem(atuple, 1, w_obj)
-assert api.PyTuple_Size(atuple) == 2
-assert space.eq_w(space.getitem(atuple, space.wrap(0)), space.wrap(0))
-assert space.eq_w(space.getitem(atuple, space.wrap(1)), space.wrap(1))
+py_tuple = api.PyTuple_New(2)
+api.PyTuple_SetItem(py_tuple, 0, make_ref(space, space.wrap(42)))
+api.PyTuple_SetItem(py_tuple, 1, make_ref(space, space.wrap(43)))
+
+w_tuple = from_ref(space, py_tuple)
+assert space.eq_w(w_tuple, space.newtuple([space.wrap(42),
+   space.wrap(43)]))
 
 def test_getslice(self, space, api):
 w_tuple = space.newtuple([space.wrap(i) for i in range(10)])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Fix for Python 2.6

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2633:97b191f401bd
Date: 2016-02-13 16:32 +0100
http://bitbucket.org/cffi/cffi/changeset/97b191f401bd/

Log:Fix for Python 2.6

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -1,4 +1,4 @@
-import sys, sysconfig, types
+import sys, types
 from .lock import allocate_lock
 
 try:
@@ -571,6 +571,10 @@
 if hasattr(sys, 'gettotalrefcount'):
 template += '_d'
 else:
+try:
+import sysconfig
+except ImportError:# 2.6
+from distutils import sysconfig
 template = "python%d.%d"
 if sysconfig.get_config_var('DEBUG_EXT'):
 template += sysconfig.get_config_var('DEBUG_EXT')
diff --git a/testing/cffi0/test_zintegration.py 
b/testing/cffi0/test_zintegration.py
--- a/testing/cffi0/test_zintegration.py
+++ b/testing/cffi0/test_zintegration.py
@@ -4,6 +4,9 @@
 
 if sys.platform == 'win32':
 py.test.skip('snippets do not run on win32')
+if sys.version_info < (2, 7):
+py.test.skip('fails e.g. on a Debian/Ubuntu which patches virtualenv'
+ ' in a non-2.6-friendly way')
 
 def create_venv(name):
 tmpdir = udir.join(name)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Update version

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2634:5800738d1322
Date: 2016-02-13 16:32 +0100
http://bitbucket.org/cffi/cffi/changeset/5800738d1322/

Log:Update version

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2,7 +2,7 @@
 #include 
 #include "structmember.h"
 
-#define CFFI_VERSION  "1.5.1"
+#define CFFI_VERSION  "1.5.2"
 
 #ifdef MS_WIN32
 #include 
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -12,7 +12,7 @@
 # 
 
 import sys
-assert __version__ == "1.5.1", ("This test_c.py file is for testing a version"
+assert __version__ == "1.5.2", ("This test_c.py file is for testing a version"
 " of cffi that differs from the one that we"
 " get from 'import _cffi_backend'")
 if sys.version_info < (3,):
diff --git a/cffi/__init__.py b/cffi/__init__.py
--- a/cffi/__init__.py
+++ b/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.5.1"
-__version_info__ = (1, 5, 1)
+__version__ = "1.5.2"
+__version_info__ = (1, 5, 2)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/cffi/_embedding.h b/cffi/_embedding.h
--- a/cffi/_embedding.h
+++ b/cffi/_embedding.h
@@ -233,7 +233,7 @@
 f = PySys_GetObject((char *)"stderr");
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.5.1"
+   "\ncompiled with cffi version: 1.5.2"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/doc/source/conf.py b/doc/source/conf.py
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -47,7 +47,7 @@
 # The short X.Y version.
 version = '1.5'
 # The full version, including alpha/beta/rc tags.
-release = '1.5.1'
+release = '1.5.2'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -51,11 +51,11 @@
 
 Download and Installation:
 
-* http://pypi.python.org/packages/source/c/cffi/cffi-1.5.1.tar.gz
+* http://pypi.python.org/packages/source/c/cffi/cffi-1.5.2.tar.gz
 
-   - MD5: ac9a3c7724bd7a4f3c0d4f6ffef2c6c7
+   - MD5: ...
 
-   - SHA: 933f7ea6f48ebbaf4794a1a807ae6f5ec232c83b
+   - SHA: ...
 
 * Or grab the most current version from the `Bitbucket page`_:
   ``hg clone https://bitbucket.org/cffi/cffi``
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -3,6 +3,12 @@
 ==
 
 
+v1.5.2
+==
+
+* Fix 1.5.1 for Python 2.6.
+
+
 v1.5.1
 ==
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -144,7 +144,7 @@
 
 `Mailing list `_
 """,
-version='1.5.1',
+version='1.5.2',
 packages=['cffi'] if cpython else [],
 package_data={'cffi': ['_cffi_include.h', 'parse_c_type.h', 
'_embedding.h']}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi release-1.5: hg merge default

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: release-1.5
Changeset: r2635:b52caed9d9cf
Date: 2016-02-13 16:32 +0100
http://bitbucket.org/cffi/cffi/changeset/b52caed9d9cf/

Log:hg merge default

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2,7 +2,7 @@
 #include 
 #include "structmember.h"
 
-#define CFFI_VERSION  "1.5.1"
+#define CFFI_VERSION  "1.5.2"
 
 #ifdef MS_WIN32
 #include 
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -12,7 +12,7 @@
 # 
 
 import sys
-assert __version__ == "1.5.1", ("This test_c.py file is for testing a version"
+assert __version__ == "1.5.2", ("This test_c.py file is for testing a version"
 " of cffi that differs from the one that we"
 " get from 'import _cffi_backend'")
 if sys.version_info < (3,):
diff --git a/cffi/__init__.py b/cffi/__init__.py
--- a/cffi/__init__.py
+++ b/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.5.1"
-__version_info__ = (1, 5, 1)
+__version__ = "1.5.2"
+__version_info__ = (1, 5, 2)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/cffi/_embedding.h b/cffi/_embedding.h
--- a/cffi/_embedding.h
+++ b/cffi/_embedding.h
@@ -233,7 +233,7 @@
 f = PySys_GetObject((char *)"stderr");
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.5.1"
+   "\ncompiled with cffi version: 1.5.2"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -1,4 +1,4 @@
-import sys, sysconfig, types
+import sys, types
 from .lock import allocate_lock
 
 try:
@@ -571,6 +571,10 @@
 if hasattr(sys, 'gettotalrefcount'):
 template += '_d'
 else:
+try:
+import sysconfig
+except ImportError:# 2.6
+from distutils import sysconfig
 template = "python%d.%d"
 if sysconfig.get_config_var('DEBUG_EXT'):
 template += sysconfig.get_config_var('DEBUG_EXT')
diff --git a/doc/source/conf.py b/doc/source/conf.py
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -47,7 +47,7 @@
 # The short X.Y version.
 version = '1.5'
 # The full version, including alpha/beta/rc tags.
-release = '1.5.1'
+release = '1.5.2'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -51,11 +51,11 @@
 
 Download and Installation:
 
-* http://pypi.python.org/packages/source/c/cffi/cffi-1.5.1.tar.gz
+* http://pypi.python.org/packages/source/c/cffi/cffi-1.5.2.tar.gz
 
-   - MD5: ac9a3c7724bd7a4f3c0d4f6ffef2c6c7
+   - MD5: ...
 
-   - SHA: 933f7ea6f48ebbaf4794a1a807ae6f5ec232c83b
+   - SHA: ...
 
 * Or grab the most current version from the `Bitbucket page`_:
   ``hg clone https://bitbucket.org/cffi/cffi``
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -3,6 +3,12 @@
 ==
 
 
+v1.5.2
+==
+
+* Fix 1.5.1 for Python 2.6.
+
+
 v1.5.1
 ==
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -144,7 +144,7 @@
 
 `Mailing list `_
 """,
-version='1.5.1',
+version='1.5.2',
 packages=['cffi'] if cpython else [],
 package_data={'cffi': ['_cffi_include.h', 'parse_c_type.h', 
'_embedding.h']}
diff --git a/testing/cffi0/test_zintegration.py 
b/testing/cffi0/test_zintegration.py
--- a/testing/cffi0/test_zintegration.py
+++ b/testing/cffi0/test_zintegration.py
@@ -4,6 +4,9 @@
 
 if sys.platform == 'win32':
 py.test.skip('snippets do not run on win32')
+if sys.version_info < (2, 7):
+py.test.skip('fails e.g. on a Debian/Ubuntu which patches virtualenv'
+ ' in a non-2.6-friendly way')
 
 def create_venv(name):
 tmpdir = udir.join(name)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi release-1.5: md5/sha1

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: release-1.5
Changeset: r2636:815923bd8af3
Date: 2016-02-13 16:34 +0100
http://bitbucket.org/cffi/cffi/changeset/815923bd8af3/

Log:md5/sha1

diff --git a/doc/source/installation.rst b/doc/source/installation.rst
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -53,9 +53,9 @@
 
 * http://pypi.python.org/packages/source/c/cffi/cffi-1.5.2.tar.gz
 
-   - MD5: ...
+   - MD5: fa766133f7299464c8bf857e0c966a82
 
-   - SHA: ...
+   - SHA: 5239b3aa4f67eed3559c09778096ecd4faeca876
 
 * Or grab the most current version from the `Bitbucket page`_:
   ``hg clone https://bitbucket.org/cffi/cffi``
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: hg merge release-1.5

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2637:4640c7bfb316
Date: 2016-02-13 16:34 +0100
http://bitbucket.org/cffi/cffi/changeset/4640c7bfb316/

Log:hg merge release-1.5

diff --git a/doc/source/installation.rst b/doc/source/installation.rst
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -53,9 +53,9 @@
 
 * http://pypi.python.org/packages/source/c/cffi/cffi-1.5.2.tar.gz
 
-   - MD5: ...
+   - MD5: fa766133f7299464c8bf857e0c966a82
 
-   - SHA: ...
+   - SHA: 5239b3aa4f67eed3559c09778096ecd4faeca876
 
 * Or grab the most current version from the `Bitbucket page`_:
   ``hg clone https://bitbucket.org/cffi/cffi``
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix test_pyerrors

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82220:f19a490ae47f
Date: 2016-02-13 16:42 +0100
http://bitbucket.org/pypy/pypy/changeset/f19a490ae47f/

Log:fix test_pyerrors

diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -28,12 +28,12 @@
 """This is a shorthand for PyErr_SetObject(type, Py_None)."""
 PyErr_SetObject(space, w_type, space.w_None)
 
-@cpython_api([], PyObject)
+@cpython_api([], PyObject, result_borrowed=True)
 def PyErr_Occurred(space):
 state = space.fromcache(State)
 if state.operror is None:
 return None
-return borrow_from(None, state.operror.w_type)
+return state.operror.w_type
 
 @cpython_api([], lltype.Void)
 def PyErr_Clear(space):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r8:0656f5bc1381
Date: 2016-02-13 16:59 +0100
http://bitbucket.org/pypy/pypy/changeset/0656f5bc1381/

Log:fix

diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -31,17 +31,16 @@
 Py_GE = 5
 
 
-def check_num_args(space, ob, n):
-from pypy.module.cpyext.tupleobject import PyTuple_CheckExact, \
-PyTuple_GET_SIZE
-if not PyTuple_CheckExact(space, ob):
+def check_num_args(space, w_ob, n):
+from pypy.module.cpyext.tupleobject import PyTuple_CheckExact
+if not PyTuple_CheckExact(space, w_ob):
 raise OperationError(space.w_SystemError,
 space.wrap("PyArg_UnpackTuple() argument list is not a tuple"))
-if n == PyTuple_GET_SIZE(space, ob):
+if n == space.len_w(w_ob):
 return
 raise oefmt(space.w_TypeError,
 "expected %d arguments, got %d",
-n, PyTuple_GET_SIZE(space, ob))
+n, space.len_w(w_ob))
 
 def wrap_init(space, w_self, w_args, func, w_kwargs):
 func_init = rffi.cast(initproc, func)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: kill test, borrowing as such no longer exists

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82223:ecb4ebcdb9e4
Date: 2016-02-13 16:59 +0100
http://bitbucket.org/pypy/pypy/changeset/ecb4ebcdb9e4/

Log:kill test, borrowing as such no longer exists

diff --git a/pypy/module/cpyext/test/test_borrow.py 
b/pypy/module/cpyext/test/test_borrow.py
--- a/pypy/module/cpyext/test/test_borrow.py
+++ b/pypy/module/cpyext/test/test_borrow.py
@@ -4,17 +4,6 @@
 from pypy.module.cpyext.pyobject import make_ref, borrow_from, RefcountState
 
 
-class TestBorrowing(BaseApiTest):
-def test_borrowing(self, space, api):
-w_int = space.wrap(1)
-w_tuple = space.newtuple([w_int])
-api.Py_IncRef(w_tuple)
-one_pyo = borrow_from(w_tuple, w_int).get_ref(space)
-api.Py_DecRef(w_tuple)
-state = space.fromcache(RefcountState)
-state.print_refcounts()
-py.test.raises(AssertionError, api.Py_DecRef, one_pyo)
-
 class AppTestBorrow(AppTestCpythonExtensionBase):
 def test_tuple_borrowing(self):
 module = self.import_extension('foo', [
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: A direct test for the refcount management of tuples

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82224:973d9b955039
Date: 2016-02-13 17:08 +0100
http://bitbucket.org/pypy/pypy/changeset/973d9b955039/

Log:A direct test for the refcount management of tuples

diff --git a/pypy/module/cpyext/test/test_tupleobject.py 
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -4,6 +4,7 @@
 from pypy.module.cpyext.pyobject import as_pyobj
 from pypy.module.cpyext.tupleobject import PyTupleObject
 from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 from rpython.rtyper.lltypesystem import rffi, lltype
 
 
@@ -58,3 +59,45 @@
 assert space.eq_w(w_slice,
   space.newtuple([space.wrap(i) for i in range(3, 7)]))
 
+
+class AppTestTuple(AppTestCpythonExtensionBase):
+def test_refcounts(self):
+module = self.import_extension('foo', [
+("run", "METH_NOARGS",
+ """
+PyObject *item = PyTuple_New(0);
+PyObject *t = PyTuple_New(1);
+if (t->ob_refcnt != 1 || item->ob_refcnt != 1) {
+PyErr_SetString(PyExc_SystemError, "bad initial refcnt");
+return NULL;
+}
+
+PyTuple_SetItem(t, 0, item);
+if (t->ob_refcnt != 1) {
+PyErr_SetString(PyExc_SystemError, "SetItem: t refcnt != 
1");
+return NULL;
+}
+if (item->ob_refcnt != 1) {
+PyErr_SetString(PyExc_SystemError, "SetItem: item refcnt 
!= 1");
+return NULL;
+}
+
+if (PyTuple_GetItem(t, 0) != item ||
+PyTuple_GetItem(t, 0) != item) {
+PyErr_SetString(PyExc_SystemError, "GetItem: bogus item");
+return NULL;
+}
+
+if (t->ob_refcnt != 1) {
+PyErr_SetString(PyExc_SystemError, "GetItem: t refcnt != 
1");
+return NULL;
+}
+if (item->ob_refcnt != 1) {
+PyErr_SetString(PyExc_SystemError, "GetItem: item refcnt 
!= 1");
+return NULL;
+}
+return t;
+ """),
+])
+x = module.run()
+assert x == ((),)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: App-level assertion details don't always work. In one case, I could

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82225:77fd0fb746fe
Date: 2016-02-13 17:21 +0100
http://bitbucket.org/pypy/pypy/changeset/77fd0fb746fe/

Log:App-level assertion details don't always work. In one case, I could
restore support for them with this fix, caused probably by some
long-ago refactoring

diff --git a/pypy/tool/pytest/appsupport.py b/pypy/tool/pytest/appsupport.py
--- a/pypy/tool/pytest/appsupport.py
+++ b/pypy/tool/pytest/appsupport.py
@@ -58,6 +58,9 @@
 self.w_locals = space.getattr(pyframe, space.wrap('f_locals'))
 self.f_locals = self.w_locals   # for py.test's recursion detection
 
+def get_w_globals(self):
+return self.w_globals
+
 def eval(self, code, **vars):
 space = self.space
 for key, w_value in vars.items():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: next fix

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82221:5eb12aee635c
Date: 2016-02-13 16:43 +0100
http://bitbucket.org/pypy/pypy/changeset/5eb12aee635c/

Log:next fix

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
@@ -61,9 +61,9 @@
 w_type = from_ref(space, rffi.cast(PyObject, obj.c_ob_type))
 w_obj = space.allocate_instance(self.W_BaseObject, w_type)
 track_reference(space, obj, w_obj)
-if w_type is not space.gettypefor(self.W_BaseObject):
-state = space.fromcache(RefcountState)
-state.set_lifeline(w_obj, obj)
+#if w_type is not space.gettypefor(self.W_BaseObject):
+#state = space.fromcache(RefcountState)
+#state.set_lifeline(w_obj, obj)
 return w_obj
 
 typedescr_cache = {}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Small fix to avoid being thrown into pdb when running test_complexobject

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82226:373f38b1e4ac
Date: 2016-02-13 17:29 +0100
http://bitbucket.org/pypy/pypy/changeset/373f38b1e4ac/

Log:Small fix to avoid being thrown into pdb when running
test_complexobject with "-s" (the test passes anyway)

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
@@ -43,7 +43,7 @@
 
 # lltype does not handle functions returning a structure.  This implements a
 # helper function, which takes as argument a reference to the return value.
-@cpython_api([PyObject, Py_complex_ptr], lltype.Void)
+@cpython_api([PyObject, Py_complex_ptr], rffi.INT_real, error=-1)
 def _PyComplex_AsCComplex(space, w_obj, result):
 """Return the Py_complex value of the complex number op.
 
@@ -60,7 +60,7 @@
 # if the above did not work, interpret obj as a float giving the
 # real part of the result, and fill in the imaginary part as 0.
 result.c_real = PyFloat_AsDouble(space, w_obj) # -1 on failure
-return
+return 0
 
 if not PyComplex_Check(space, w_obj):
 raise OperationError(space.w_TypeError, space.wrap(
@@ -69,3 +69,4 @@
 assert isinstance(w_obj, W_ComplexObject)
 result.c_real = w_obj.realval
 result.c_imag = w_obj.imagval
+return 0
diff --git a/pypy/module/cpyext/include/complexobject.h 
b/pypy/module/cpyext/include/complexobject.h
--- a/pypy/module/cpyext/include/complexobject.h
+++ b/pypy/module/cpyext/include/complexobject.h
@@ -15,7 +15,7 @@
 } Py_complex;
 
 /* generated function */
-PyAPI_FUNC(void) _PyComplex_AsCComplex(PyObject *, Py_complex *);
+PyAPI_FUNC(int) _PyComplex_AsCComplex(PyObject *, Py_complex *);
 PyAPI_FUNC(PyObject *) _PyComplex_FromCComplex(Py_complex *);
 
 Py_LOCAL_INLINE(Py_complex) PyComplex_AsCComplex(PyObject *obj)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Avoid "if obj:" where obj is potentially a W_Root. Notably, if it is a

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82227:9ead1cf8ed7e
Date: 2016-02-13 17:31 +0100
http://bitbucket.org/pypy/pypy/changeset/9ead1cf8ed7e/

Log:Avoid "if obj:" where obj is potentially a W_Root. Notably, if it is
a W_BoolObject then this complains.

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
@@ -260,18 +260,16 @@
 """Increment the reference counter of the PyObject and return it.
 Can be called with either a PyObject or a W_Root.
 """
-if obj:
-if is_pyobj(obj):
-pyobj = rffi.cast(PyObject, obj)
-else:
-pyobj = as_pyobj(space, obj)
+if is_pyobj(obj):
+pyobj = rffi.cast(PyObject, obj)
+else:
+pyobj = as_pyobj(space, obj)
+if pyobj:
 assert pyobj.c_ob_refcnt > 0
 pyobj.c_ob_refcnt += 1
 if not is_pyobj(obj):
 keepalive_until_here(obj)
-return pyobj
-else:
-return lltype.nullptr(PyObject.TO)
+return pyobj
 INTERPLEVEL_API['make_ref'] = make_ref
 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix with comment

2016-02-13 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82228:72c05e2cc492
Date: 2016-02-13 17:37 +0100
http://bitbucket.org/pypy/pypy/changeset/72c05e2cc492/

Log:fix with comment

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
@@ -14,13 +14,16 @@
 
 PyDict_Check, PyDict_CheckExact = build_type_checkers("Dict")
 
-@cpython_api([PyObject, PyObject], PyObject, error=CANNOT_FAIL)
+@cpython_api([PyObject, PyObject], PyObject, error=CANNOT_FAIL, 
result_borrowed=True)
 def PyDict_GetItem(space, w_dict, w_key):
 try:
 w_res = space.getitem(w_dict, w_key)
 except:
 return None
-return borrow_from(w_dict, w_res)
+# NOTE: this works so far because all our dict strategies store
+# *values* as full objects, which stay alive as long as the dict is
+# alive and not modified.
+return w_res
 
 @cpython_api([PyObject, PyObject, PyObject], rffi.INT_real, error=-1)
 def PyDict_SetItem(space, w_dict, w_key, w_obj):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix weakrefobject

2016-02-14 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82229:cba976d16588
Date: 2016-02-14 10:43 +0100
http://bitbucket.org/pypy/pypy/changeset/cba976d16588/

Log:fix weakrefobject

diff --git a/pypy/module/cpyext/weakrefobject.py 
b/pypy/module/cpyext/weakrefobject.py
--- a/pypy/module/cpyext/weakrefobject.py
+++ b/pypy/module/cpyext/weakrefobject.py
@@ -37,17 +37,19 @@
 """
 return PyWeakref_GET_OBJECT(space, w_ref)
 
-@cpython_api([PyObject], PyObject)
+@cpython_api([PyObject], PyObject, result_borrowed=True)
 def PyWeakref_GET_OBJECT(space, w_ref):
 """Similar to PyWeakref_GetObject(), but implemented as a macro that does 
no
 error checking.
 """
-return borrow_from(w_ref, space.call_function(w_ref))
+return space.call_function(w_ref)
 
 @cpython_api([PyObject], PyObject)
 def PyWeakref_LockObject(space, w_ref):
 """Return the referenced object from a weak reference.  If the referent is
 no longer live, returns None. This function returns a new reference.
+
+(A PyPy extension that may not be useful any more: use
+PyWeakref_GetObject() and Py_INCREF().)
 """
 return space.call_function(w_ref)
-
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: fix

2016-02-14 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82231:29943ebc709d
Date: 2016-02-14 11:07 +0100
http://bitbucket.org/pypy/pypy/changeset/29943ebc709d/

Log:fix

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
@@ -160,11 +160,11 @@
 """
 #state = space.fromcache(RefcountState)
 w_type = space.type(w_obj)
-if w_type.is_cpytype():
-ZZZ # py_obj = state.get_from_lifeline(w_obj)
-if py_obj:
-Py_IncRef(space, py_obj)
-return py_obj
+#if w_type.is_cpytype():
+#py_obj = state.get_from_lifeline(w_obj)
+#if py_obj:
+#Py_IncRef(space, py_obj)
+#return py_obj
 
 typedescr = get_typedescr(w_obj.typedef)
 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


  1   2   3   4   5   6   7   8   9   10   >