[Cython] segfault in 'async def' coroutines

2016-05-15 Thread Yury Selivanov

Hi,

Under some circumstances, in asyncio code that runs in uvloop [1],
cython code segfaults in cython/Cython/Utility/Coroutine.c:


  static PyObject *
  __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
  {
Py_INCREF(self->gi_qualname);
return self->gi_qualname;
  }


"self->gi_qualname" can be NULL.  The correct code is probably:


  __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
  {
if (self->gi_qualname == NULL) { return __pyx_empty_unicode; }
Py_INCREF(self->gi_qualname);
return self->gi_qualname;
  }


Thanks,
Yury
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


[Cython] async def coroutines miss __module__

2016-05-15 Thread Yury Selivanov

In CPython:

>>> async def foo(): pass
>>> foo.__module__
'__main__'

In Cython, async def coroutines lack __module__ attribute

Yury
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] segfault in 'async def' coroutines

2016-05-15 Thread Yury Selivanov

I've just discovered that same thing has to be fixed for
__name__.

On 2016-05-14 5:31 PM, Yury Selivanov wrote:

Hi,

Under some circumstances, in asyncio code that runs in uvloop [1],
cython code segfaults in cython/Cython/Utility/Coroutine.c:


  static PyObject *
  __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
  {
Py_INCREF(self->gi_qualname);
return self->gi_qualname;
  }


"self->gi_qualname" can be NULL.  The correct code is probably:


  __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
  {
if (self->gi_qualname == NULL) { return __pyx_empty_unicode; }
Py_INCREF(self->gi_qualname);
return self->gi_qualname;
  }


Thanks,
Yury


___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] segfault in 'async def' coroutines

2016-05-16 Thread Yury Selivanov



On 2016-05-16 3:58 AM, Stefan Behnel wrote:

Yury Selivanov schrieb am 14.05.2016 um 23:31:

Under some circumstances, in asyncio code that runs in uvloop [1],
cython code segfaults in cython/Cython/Utility/Coroutine.c:


   static PyObject *
   __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
   {
 Py_INCREF(self->gi_qualname);
 return self->gi_qualname;
   }


"self->gi_qualname" can be NULL.  The correct code is probably:


   __Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
   {
 if (self->gi_qualname == NULL) { return __pyx_empty_unicode; }
 Py_INCREF(self->gi_qualname);
 return self->gi_qualname;
   }

I wonder why it can be NULL. It's supposed to be set to a string constant
at creation time. See GeneratorDefNode in Nodes.py. Is there anything
special you are doing with these objects? Could you try to figure out how
the ones that have a NULL value here are created?


It's probably because asyncio Future and Task have __del__ methods
which (may) try to call repr on coroutines.  At that point of time,
maybe the GC breaks the refs.

Would you be able to fix the refs for qualname/name?

Yury
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] segfault in 'async def' coroutines

2016-05-17 Thread Yury Selivanov



On 2016-05-17 1:32 AM, Stefan Behnel wrote:

And finally, since both name values are guaranteed to be strings (the
setter checks their type), I wonder if we shouldn't just make sure they are
*exactly*  Unicode strings by converting any subtypes, and then remove their
Py_CLEAR() from the tp_clear() function. Strings can't participate in
reference cycles, and we could thus report the actual names even during
garbage collection.


This sounds like a really nice solution, Stefan.

Yury
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] segfault in 'async def' coroutines

2016-05-19 Thread Yury Selivanov
Stefan, any ETA on this?  For now I have to patch the C file generated 
by Cython (otherwise uvloop segfaults), and that's kind of fragile.


Yury

On 2016-05-17 11:31 AM, Yury Selivanov wrote:



On 2016-05-17 1:32 AM, Stefan Behnel wrote:

And finally, since both name values are guaranteed to be strings (the
setter checks their type), I wonder if we shouldn't just make sure 
they are
*exactly*  Unicode strings by converting any subtypes, and then 
remove their

Py_CLEAR() from the tp_clear() function. Strings can't participate in
reference cycles, and we could thus report the actual names even during
garbage collection.


This sounds like a really nice solution, Stefan.

Yury


___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Cython 0.25 beta

2016-10-18 Thread Yury Selivanov

Please also take a look at https://github.com/cython/cython/issues/1493


On 2016-10-10 3:50 PM, Robert Bradshaw wrote:

Thanks for all of those to tested the alpha release. I think we've managed
to fix all the issues and regressions raised in that thread; here's a beta
that's likely to turn into a release candidate.

https://github.com/cython/cython/archive/0.25b0.zip



___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Cython 0.25 released

2016-10-25 Thread Yury Selivanov

Congrats on the release!

It seems though that it's slightly broken: 
https://github.com/cython/cython/issues/1496.



Yury

On 2016-10-25 4:34 PM, Robert Bradshaw wrote:

I'm happy to announce the release of Cython 0.25 which has numerous
new features and bug fixes. It is available at
https://pypi.python.org/pypi/Cython

We have also moved bug tracking from trac.cython.org to github issues.
However, user support still remains at cython-users@, please refrain
from filing issues until you have confirmed an actual bug.

- Robert


Features added
--

* def/cpdef methods of cdef classes benefit from Cython's internal function
   implementation, which enables introspection and line profiling for them.
   Implementation sponsored by Turbostream (www.turbostream-cfd.com).

* The distutils extension ``Cython.Distutils.build_ext`` has now been updated
   to use cythonize which properly handles dependencies.  The old extension can
   still be found in ``Cython.Distutils.old_build_ext`` and is now deprecated.

* Calls to Python functions are faster, following the recent "FastCall"
   optimisations that Victor Stinner implemented for CPython 3.6.
   See https://bugs.python.org/issue27128 and related issues.

* The new METH_FASTCALL calling convention for PyCFunctions is supported
   in CPython 3.6.  See https://bugs.python.org/issue27810

* C++ classes can now have typedef members. STL containers updated with
   value_type.

* Support for bazel using a the pyx_library rule in //Tools:rules.bzl.

* Initial support for using Cython modules in Pyston.  Patch by Daetalus.

* Dynamic Python attributes are allowed on cdef classes if an attribute
   ``cdef dict __dict__`` is declared in the class.  Patch by empyrical.

* Cython implemented C++ classes can make direct calls to base class methods.
   Patch by empyrical.

* New directive ``cython.no_gc`` to fully disable GC for a cdef class.
   Patch by Claudio Freire.

* Buffer variables are no longer excluded from ``locals()``.
   Patch by da-woods.

* Building f-strings is faster, especially when formatting C integers.

* for-loop iteration over "std::string".

* ``libc/math.pxd`` provides ``e`` and ``pi`` as alias constants to simplify
   usage as a drop-in replacement for Python's math module.

* Speed up cython.inline().

* Binary lshift operations with small constant Python integers are faster.

* Some integer operations on Python long objects are faster in Python 2.7.

* Support for the C++ ``typeid`` operator.

Significant Bugs fixed
--

* Division of complex numbers avoids overflow by using Smith's method.

* Some function signatures in ``libc.math`` and ``numpy.pxd`` were incorrect.
   Patch by Michael Seifert.

Other changes
-

* The "%%cython" IPython/jupyter magic now defaults to the language level of
   the current jupyter kernel.  The language level can be set explicitly with
   "%%cython -2" or "%%cython -3".
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel