question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cpython to pyd binary - "long" converted to "int" badly before shift / division operator

See original GitHub issue

cython 0.29 python 3.6.6 compiler mingw-w64 os windows 7

command used: python setup.py build_ext --inplace

setup.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
extensions = [Extension("shiftoperator", ['shiftoperator.py']]
setup(
    ext_modules=cythonize(extensions)
)

shiftoperator.py:

#!python
#cython: language_level=3
def longtoint():
    value = 80082 # int using more than 2 bytes == long
    print(value)
    shiftedby3 = value>>3
    dividedby8 = value//8
    print(shiftedby3)
    print(dividedby8)
    shiftedby3 = 80082>>3
    dividedby8 = 80082//8
    print(shiftedby3)
    print(dividedby8)

test_shift.py

import shiftoperator
shiftoperator.longtoint()

with cpython shiftoperator.py library used:

C:\scripts\tests>python test_shift.py
80082
10010
10010
10010
10010

with binary shiftoperator.cp36-win_amd64.pyd used:

C:\scripts\tests>python test_shift.py
80082
1818
1818
10010
10010

it seems the higher bit (65536 before shifting / 8192 after shifting) is dropped before the shifting process is done in case original long is saved on a variable

Can you check? Thks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ducminh-phancommented, Oct 23, 2018

@gui36 I have a similar issue with my code and had a discussion in the cython-users Google group. The problem is in the header pyport.h, in which SIZEOF_VOID_P is defined based on whether MS_WIN64 is defined or not. The solution is to pass -DMS_WIN64 when compiling with MinGW.

0reactions
filips123commented, Dec 23, 2019

Is there any other possibility for building Cython packages with MinGW? Or maybe official Python team needs to support something?

As MinGW is the only lightweight compiler, in comparison to VS Build Tools, it would be very useful to support it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert integer to binary and then do a left bit shift in python
The problem is bin(i) returns a string, so I had to convert it into int but then using the shift operator shifts the...
Read more >
Troubleshooting and tips — Numba 0.50.1 documentation
A common reason for Numba failing to compile (especially in nopython mode) is a type inference failure, essentially Numba cannot work out what...
Read more >
Source Files and Compilation - Cython's Documentation
The cythonize command takes a .py or .pyx file and compiles it into a C/C++ file. It then compiles the C/C++ file into...
Read more >
Python | Binary list to integer - GeeksforGeeks
In this method, the entire list is first converted to string and then type conversion into int and then binary number is obtained....
Read more >
Representing Rational Numbers With Python Fractions
Convert between decimal and fractional notation; Perform rational number ... or a fraction, of two integers as long as the denominator is nonzero....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found