[Cython] Cython 0.23: long + int == int
$ cython --version Cython version 0.23 $ python2.6 --version Python 2.6.8 $ cat testlong.pyx def f(x): return 0L + x $ python2.6 -c 'import pyximport as p; p.install(); import testlong; print type(testlong.f(42))' I added a long to an int, so I'd expect the result to be a long. This works correctly in Python 2.7: $ python2.7 -c 'import pyximport as p; p.install(); import testlong; print type(testlong.f(42))' It also worked correctly in Cython 0.22.1 + Python 2.6. -- Jakub Wilk ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] Cython 0.23: long + int == int
* Stefan Behnel , 2015-08-17, 20:33: $ cat testlong.pyx def f(x): return 0L + x $ python2.6 -c 'import pyximport as p; p.install(); import testlong; print type(testlong.f(42))' I added a long to an int, so I'd expect the result to be a long. [...] I understand that this is not entirely correct, but does it pose any problems in practice? It broke my test suite, which is how I noticed; but yeah, I don't think it's a big deal. -- Jakub Wilk ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
[Cython] Compiler crash in MarkOverflowingArithmetic
Tested with Cython 0.23.1 on i386. You will probably need a bigger number to trigger it on a 64-bit machine. $ cython test.pyx Error compiling Cython file: ... DEF X = 0x811C9DC5 cdef void f(): cdef unsigned int x = X ^ test.pyx:3:9: Compiler crash in MarkOverflowingArithmetic ModuleNode.body = StatListNode(test.pyx:2:5) StatListNode.stats[0] = CFuncDefNode(test.pyx:2:5, args = [...]/0, modifiers = [...]/0, visibility = 'private') CFuncDefNode.body = StatListNode(test.pyx:3:9) StatListNode.stats[0] = SingleAssignmentNode(test.pyx:3:9, first = True) Compiler crash traceback from this point on: File "/usr/local/lib/python2.7/dist-packages/Cython/Compiler/Visitor.py", line 183, in _visit return handler_method(obj) File "/usr/local/lib/python2.7/dist-packages/Cython/Compiler/TypeInference.py", line 327, in visit_SingleAssignmentNode self.visit_assignment(node.lhs, node.rhs) File "/usr/local/lib/python2.7/dist-packages/Cython/Compiler/TypeInference.py", line 321, in visit_assignment and Utils.long_literal(rhs.value)): File "/usr/local/lib/python2.7/dist-packages/Cython/Utils.py", line 318, in long_literal value = str_to_number(value) File "/usr/local/lib/python2.7/dist-packages/Cython/Utils.py", line 312, in str_to_number value = int(value, 0) ValueError: invalid literal for int() with base 0: '2166136261L' -- Jakub Wilk DEF X = 0x811C9DC5 cdef void f(): cdef unsigned int x = X ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
[Cython] DEF converts byte strings to unicode
DEF silently converts byte strings to Unicode strings: $ cat testcase.pyx DEF ABYTE = b'a' print type(ABYTE) $ python --version Python 2.7.10 $ python -c 'import pyximport as p; p.install(); import testcase' Tested with Cython 0.23.1. -- Jakub Wilk ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
[Cython] array->memoryview typecast causes compiler crash in AnalyseExpressionsTransform
In https://bugs.debian.org/793129 Dan Greene reported that trying to cast a pointer to a memoryview object causes a compiler crash: $ python -c 'import cython; cython.inline("NULL")' Compiling /home/jwilk/.cython/inline/_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx because it changed. [1/1] Cythonizing /home/jwilk/.cython/inline/_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx Error compiling Cython file: ... def __invoke(): NULL ^ .cython/inline/_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:5:4: Compiler crash in AnalyseExpressionsTransform ModuleNode.body = StatListNode(_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:4:0) StatListNode.stats[0] = DefNode(_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:4:0, modifiers = [...]/0, name = u'__invoke', py_wrapper_required = True, reqd_kw_flags_cname = '0', used = True) File 'Nodes.py', line 430, in analyse_expressions: StatListNode(_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:5:4, is_terminator = True) File 'Nodes.py', line 4741, in analyse_expressions: ExprStatNode(_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:5:4) File 'ExprNodes.py', line 460, in analyse_expressions: CythonArrayNode(_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:5:4, is_temp = True, mode = 'c', use_managed_ref = True) File 'ExprNodes.py', line 9567, in analyse_types: CythonArrayNode(_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:5:4, is_temp = True, mode = 'c', use_managed_ref = True) File 'ExprNodes.py', line 9582, in get_cython_array_type: CythonArrayNode(_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx:5:4, is_temp = True, mode = 'c', use_managed_ref = True) Compiler crash traceback from this point on: File "/home/jwilk/.local/lib/python2.7/site-packages/Cython/Compiler/ExprNodes.py", line 9582, in get_cython_array_type return env.global_scope().context.cython_scope.viewscope.lookup("array").type AttributeError: 'CythonScope' object has no attribute 'viewscope' Traceback (most recent call last): File "", line 1, in File "/home/jwilk/.local/lib/python2.7/site-packages/Cython/Shadow.py", line 114, in inline return cython_inline(f, *args, **kwds) File "/home/jwilk/.local/lib/python2.7/site-packages/Cython/Build/Inline.py", line 212, in cython_inline build_extension.extensions = cythonize([extension], include_path=cython_include_dirs, quiet=quiet) File "/home/jwilk/.local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 877, in cythonize cythonize_one(*args) File "/home/jwilk/.local/lib/python2.7/site-packages/Cython/Build/Dependencies.py", line 997, in cythonize_one raise CompileError(None, pyx_file) Cython.Compiler.Errors.CompileError: /home/jwilk/.cython/inline/_cython_inline_ad8e8c5018441f8a5417cab08ec65d13.pyx -- Jakub Wilk ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] DEF converts byte strings to unicode
I think something is still not quite right in Cython 0.23.2. Consider this code: DEF FOO = 'foo' print type('foo') print type(FOO) In Python 3, I get: -- Jakub Wilk ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] DEF converts byte strings to unicode
* Stefan Behnel , 2015-09-12, 18:14: My general recommendation is to a) avoid DEF, b) avoid DEF for string values, and c) avoid DEF for unprefixed string values, in that order. But b) and c) are only for advanced users. Fair enough. NB, there are examples that use DEFs with string values in the documentation[0]. You might want to fix them, or add appropriate warnings. [0] $ grep -r "DEF.*=.*['\"]" docs/ docs/src/reference/language_basics.rst:DEF FavouriteFood = "spam" docs/src/userguide/language_basics.rst:DEF FavouriteFood = "spam" -- Jakub Wilk ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] can we deprecate for-from loops?
* Stefan Behnel , 2015-10-11, 16:30: The syntax construct "for i from 0 <= i < 10" has been silently outdated for years. Can we start issuing a warning that normal range() loops are preferred? Hmm. AFAICS, Cython doesn't aways optimize range() loops that well... For the attached example code, Cython 0.23.4 generated nice for loops for the for_from() function: for (__pyx_t_1 = 0; __pyx_t_1 < 10; __pyx_t_1++) { ... for (__pyx_t_3 = 0; __pyx_t_3 < 10; __pyx_t_3++) { ... but not for the for_range() function: __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_tuple_, NULL); ... ... (The problem goes away if cdef the iteration variables, which I should do anyway, so it's not a big deal for me.) -- Jakub Wilk def for_from(): for i from 0 <= i < 10: for j from 0 <= j < 10: print(i + j) def for_range(): for i in range(10): for j in range(10): print(i + j) ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] Cython 3.0 alpha 4 released
Hi Stefan! Could you push the 3.0a4 tag to GitHub? -- Jakub Wilk ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel