From e78066fd1ff48afb29a8950166b5d7d4baa1dc22 Mon Sep 17 00:00:00 2001 From: Marc Culler Date: Thu, 12 Sep 2024 19:55:09 -0500 Subject: [PATCH] Better workaround for #define long long long --- cypari/_pari.pyx | 14 ++++++++++++-- cypari/cypari.h | 2 -- setup.py | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cypari/_pari.pyx b/cypari/_pari.pyx index e846964..69bf17e 100644 --- a/cypari/_pari.pyx +++ b/cypari/_pari.pyx @@ -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 * @@ -116,5 +128,3 @@ include "convert.pyx" include "handle_error.pyx" include "closure.pyx" include "gen.pyx" - - diff --git a/cypari/cypari.h b/cypari/cypari.h index 9b07a96..54d83dd 100644 --- a/cypari/cypari.h +++ b/cypari/cypari.h @@ -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 diff --git a/setup.py b/setup.py index 21c0ac4..e1b7899 100644 --- a/setup.py +++ b/setup.py @@ -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):