From afcc535afc9ac0fdeb6d264334646797eeab8f92 Mon Sep 17 00:00:00 2001 From: Gabriel Pettier Date: Sun, 10 May 2020 15:48:08 +0200 Subject: [PATCH] actually use cython language_level=3 + fix issue! --- jnius/jnius_conversion.pxi | 2 +- setup.py | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/jnius/jnius_conversion.pxi b/jnius/jnius_conversion.pxi index bd85056..ef9b331 100644 --- a/jnius/jnius_conversion.pxi +++ b/jnius/jnius_conversion.pxi @@ -525,7 +525,7 @@ cdef jstring convert_pystr_to_java(JNIEnv *j_env, unicode py_uni) except NULL: py_bytes = py_uni.encode('utf-16') # skip byte-order mark buff = (py_bytes) + sizeof(jchar) - j_strlen = len(py_bytes) / sizeof(jchar) - 1 + j_strlen = int(len(py_bytes) / sizeof(jchar) - 1) j_str = j_env[0].NewString(j_env, buff, j_strlen) if j_str == NULL: diff --git a/setup.py b/setup.py index 3767012..da44eb3 100644 --- a/setup.py +++ b/setup.py @@ -98,30 +98,31 @@ compile_native_invocation_handler(*get_possible_homes(PLATFORM)) # generate the config.pxi with open(join(dirname(__file__), 'jnius', 'config.pxi'), 'w') as fd: fd.write('DEF JNIUS_PLATFORM = {0!r}\n\n'.format(PLATFORM)) - if not PY2: - fd.write('# cython: language_level=3\n\n') - fd.write('DEF JNIUS_PYTHON3 = True\n\n') - else: - fd.write('# cython: language_level=2\n\n') - fd.write('DEF JNIUS_PYTHON3 = False\n\n') + fd.write('DEF JNIUS_PYTHON3 = True\n\n') # pop setup.py from included files in the installed package SETUP_KWARGS['py_modules'].remove('setup') +ext_modules = [ + Extension( + 'jnius', [join('jnius', x) for x in FILES], + libraries=get_libraries(PLATFORM), + library_dirs=get_library_dirs(PLATFORM), + include_dirs=get_include_dirs(PLATFORM), + extra_link_args=EXTRA_LINK_ARGS, + ) +] + +for ext_mod in ext_modules: + ext_mod.cython_directives = {'language_level': 3} + + # create the extension setup( cmdclass={'build_ext': build_ext}, install_requires=INSTALL_REQUIRES, setup_requires=SETUP_REQUIRES, - ext_modules=[ - Extension( - 'jnius', [join('jnius', x) for x in FILES], - libraries=get_libraries(PLATFORM), - library_dirs=get_library_dirs(PLATFORM), - include_dirs=get_include_dirs(PLATFORM), - extra_link_args=EXTRA_LINK_ARGS, - ) - ], + ext_modules=ext_modules, extras_require={ 'dev': ['pytest', 'wheel', 'pytest-cov', 'pycodestyle'], 'ci': ['coveralls', 'pytest-rerunfailures', 'setuptools>=34.4.0'],