2

I have the following code in test.pyx

cdef class Test:
    cdef long long i

    def __cinit__(self, long long i):
        self.i = i

    def __truediv__(Test self, Test other):
        return Test(self.i / other.i)

In a short python script I have this:

import test
print('Done')

When I run the script after compiling test.pyx, I get the following output along with a Windows Error dialog "python.exe has stopped working".

Done

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Note that I never call the compiled code, only import it. Also note that the crash only occurs after the python script completes execution. I've noticed that changing i from a long long to just a long causes the error to go away. Is there something basic I'm missing, or is division by a long long not always safe?

Some information about my setup if it makes a difference:

OS: Windows 7, 64-bit

Python version: 3.4.2, MSC v 1600 32 bit

Cython version: 0.22

Compiler: mingw32

EDIT: Additional Notes

  • Also tested on Python 2.7.9 32 bit with the same results
  • Replacing / with // gives the same result
  • If all code involving division is removed (commented out, removed by the compiler, etc.), the error disappears
  • The compiled code seems to be functioning properly when called even though Python crashes upon completion.
11
  • Does anything different happen if you use //? May 20, 2015 at 2:47
  • No, same result. However, I noticed that changing __truediv__ to just __div__ makes the error disappear. However, that may just be because __div__ isn't used in Python 3 and just gets removed by the compiler.
    – Mobious
    May 20, 2015 at 3:59
  • 1
    FYI, no crash on OS X, Cython 0.22, Python 2.7.9. Sometimes, on Windows, my experience is that you need to use the exact same compiler as Python uses to avoid ABI incompatibility (long long division might be one of those places where the MinGW ABI and the MSVC ABI differ). Try using the Microsoft compiler if available.
    – nneonneo
    May 20, 2015 at 4:57
  • No crash on Win8.1 using MinGW and Cython 20.1. What happens if you run the Python command line and import this thing as a module? At the prompt can you print it, do a dir() on it, inspect its attributes and do all the minimal stuff you can with any module? May 20, 2015 at 5:06
  • @nneonneo Thanks for the info. I'll see what I can do about trying a different compiler.
    – Mobious
    May 20, 2015 at 6:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.