Skip to content

Commit

Permalink
Better workaround for #define long long long
Browse files Browse the repository at this point in the history
  • Loading branch information
culler committed Sep 13, 2024
1 parent b40e067 commit e78066f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
14 changes: 12 additions & 2 deletions cypari/_pari.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ from cpython.object cimport Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, Py_GT

from .paridecl cimport *
from .paripriv cimport *

# cdef extern from *:
# """
# /* Undo the damage caused by PARI's ridiculous
# * #define long long long
# */
# #if defined long
# #undef long
# #endif
# """
# pass

cimport libc.stdlib
from libc.stdio cimport *

Expand Down Expand Up @@ -116,5 +128,3 @@ include "convert.pyx"
include "handle_error.pyx"
include "closure.pyx"
include "gen.pyx"


2 changes: 0 additions & 2 deletions cypari/cypari.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@
#define set_gcoeff(x, i, j, z) (gcoeff((x), (i), (j)) = (z))
#define set_uel(x, n, z) (uel((x), (n)) = (z))

/* Undo the damage caused by Pari's ridiculous hack for 64 bit windows.*/
#undef long
17 changes: 15 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,21 @@ def run(self):
# if not os.path.exists(os.path.join('cypari', '_pari.c')):
# sys.exit(no_cython_message)
from Cython.Build import cythonize
cythonize([os.path.join('cypari', '_pari.pyx')],
compiler_directives={'language_level':2})
_pari_pyx = os.path.join('cypari', '_pari.pyx')
_pari_c = os.path.join('cypari', '_pari.c')
cythonize([_pari_pyx],
compiler_directives={'language_level':2})
with open('_pari.c', 'w') as outfile:
with open(_pari_c) as infile:
for line in infile.readlines():
if line.find('pycore') >= 0:
outfile.write(
' #undef long\n%s'
' #define long long long\n' %line)
else:
outfile.write(line)
os.unlink(_pari_c)
os.rename('_pari.c', _pari_c)
build_ext.run(self)

class CyPariSourceDist(sdist):
Expand Down

0 comments on commit e78066f

Please sign in to comment.