Skip to content

Commit

Permalink
Merge pull request #1523 from heinezen/cython3
Browse files Browse the repository at this point in the history
Fix Cython 3 problems
  • Loading branch information
TheJJ committed Jul 23, 2023
2 parents c442dc9 + b5c80ce commit 3ca720b
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 46 deletions.
5 changes: 3 additions & 2 deletions openage/convert/service/export/interface/visgrep.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2020 the openage authors. See copying.md for legal info.
# Copyright 2016-2023 the openage authors. See copying.md for legal info.

# If you wanna boost speed even further:
# cython: profile=False
Expand Down Expand Up @@ -302,7 +302,8 @@ cdef visgrep_cli(geom_params, metric_params, img_params):
"""

cdef image_t img, find
cdef vector[image_t] matches
# cdef vector[pixel_t[:, :, :]] matches
cdef list matches

pt_match = FoundResult(0, Point(0, 0))
results = []
Expand Down
8 changes: 4 additions & 4 deletions openage/convert/service/export/opus/opus.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2020 the openage authors. See copying.md for legal info.
# Copyright 2018-2023 the openage authors. See copying.md for legal info.

cdef extern from "opus/opus.h":
ctypedef struct OpusEncoder:
Expand All @@ -16,9 +16,9 @@ cdef extern from "opus/opus.h":

cdef extern from "opus/opus_defines.h":
# Errors
const int OPUS_OK = 0
const int OPUS_ALLOC_FAIL = -7
const int OPUS_OK
const int OPUS_ALLOC_FAIL
# Application
const int OPUS_APPLICATION_AUDIO = 2049
const int OPUS_APPLICATION_AUDIO
# Macros
int OPUS_GET_LOOKAHEAD(opus_int32 *x)
20 changes: 10 additions & 10 deletions openage/convert/service/export/png/libpng.pxd
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Copyright 2020-2020 the openage authors. See copying.md for legal info.
# Copyright 2020-2023 the openage authors. See copying.md for legal info.

from libc.stdio cimport FILE

cdef extern from "png.h":
const char PNG_LIBPNG_VER_STRING[]
const int PNG_COLOR_TYPE_RGBA = 6
const int PNG_INTERLACE_NONE = 0
const int PNG_COMPRESSION_TYPE_DEFAULT = 0
const int PNG_FILTER_TYPE_DEFAULT = 0
const int PNG_TRANSFORM_IDENTITY = 0
const int PNG_IMAGE_VERSION = 1
const char PNG_FORMAT_RGBA = 0x03
const int PNG_COLOR_TYPE_RGBA
const int PNG_INTERLACE_NONE
const int PNG_COMPRESSION_TYPE_DEFAULT
const int PNG_FILTER_TYPE_DEFAULT
const int PNG_TRANSFORM_IDENTITY
const int PNG_IMAGE_VERSION
const char PNG_FORMAT_RGBA

const unsigned int PNG_FILTER_NONE = 0x08
const unsigned int PNG_ALL_FILTERS = 0xF8
const unsigned int PNG_FILTER_NONE
const unsigned int PNG_ALL_FILTERS

ctypedef unsigned char png_byte
ctypedef const png_byte *png_const_bytep
Expand Down
4 changes: 2 additions & 2 deletions openage/convert/value_object/read/media/slp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ cdef class SLPFrame:

cdef vector[pixel] create_palette_color_row(self,
const uint8_t[::1] &data_raw,
Py_ssize_t rowid) except +:
Py_ssize_t rowid):
"""
create palette indices (colors) for the given rowid.
"""
Expand Down Expand Up @@ -1134,7 +1134,7 @@ cdef class SLPFrame32:

cdef vector[pixel32] create_palette_color_row(self,
const uint8_t[::1] &data_raw,
Py_ssize_t rowid) except +:
Py_ssize_t rowid):
"""
create palette indices (colors) for the given rowid.
"""
Expand Down
2 changes: 1 addition & 1 deletion openage/convert/value_object/read/media/smp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ cdef class SMPLayer:

cdef vector[pixel] create_color_row(self,
const uint8_t[::1] &data_raw,
Py_ssize_t rowid) except +:
Py_ssize_t rowid):
"""
extract colors (pixels) for the given rowid.
"""
Expand Down
2 changes: 1 addition & 1 deletion openage/convert/value_object/read/media/smx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ cdef class SMXLayer:
Py_ssize_t rowid,
int cmd_offset,
int color_offset,
int chunk_pos) except +:
int chunk_pos):
"""
Extract colors (pixels) for the given rowid.
Expand Down
8 changes: 4 additions & 4 deletions openage/cppinterface/exctranslate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cdef extern from "traceback.h":
void _PyTraceback_Add(const char *funcname, const char *filename, int lineno)


cdef void PyTraceback_Add(const char *functionname, const char *filename, int lineno) with gil:
cdef void PyTraceback_Add(const char *functionname, const char *filename, int lineno) noexcept with gil:
"""
Add a new traceback stack frame.
Redirects to Python's internal _PyTraceback_Add function.
Expand All @@ -71,7 +71,7 @@ class CPPException(Exception):
self.typename = typename


cdef void py_add_backtrace_frame_from_symbol(const backtrace_symbol *symbol) with gil: # noexcept
cdef void py_add_backtrace_frame_from_symbol(const backtrace_symbol *symbol) noexcept with gil:
"""
For use as a callback with Error->backtrace->get_symbols(), from within
raise_exception.
Expand All @@ -87,7 +87,7 @@ cdef Func1[void, const backtrace_symbol *] py_backtrace_adder
py_backtrace_adder.bind_noexcept0(py_add_backtrace_frame_from_symbol)


cdef void raise_cpp_error_common(Error *cpp_error_obj, object obj_to_raise):
cdef void raise_cpp_error_common(Error *cpp_error_obj, object obj_to_raise) noexcept:
"""
Common code that is used by both raise_cpp_error and raise_cpp_pyexception.
Expand Down Expand Up @@ -167,7 +167,7 @@ cdef void raise_cpp_pyexception(PyException *cpp_pyexception_obj) except * with
# No new data was added during its C++ life.


cdef cppbool check_exception() with gil:
cdef cppbool check_exception() noexcept with gil:
# see the doc of the function pointer in exctranslate.h
return (PyErr_Occurred() != NULL)

Expand Down
6 changes: 3 additions & 3 deletions openage/cppinterface/pyobject.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015-2017 the openage authors. See copying.md for legal info.
# Copyright 2015-2023 the openage authors. See copying.md for legal info.

from libc.stdint cimport int64_t
from libcpp cimport bool as cppbool
Expand Down Expand Up @@ -57,11 +57,11 @@ import builtins
import importlib


cdef void xincref(PyObject *ptr) with gil:
cdef void xincref(PyObject *ptr) noexcept with gil:
Py_XINCREF(ptr)


cdef void xdecref(PyObject *ptr) with gil:
cdef void xdecref(PyObject *ptr) noexcept with gil:
Py_XDECREF(ptr)


Expand Down
12 changes: 1 addition & 11 deletions openage/game/main_cpp.pyx
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# Copyright 2015-2018 the openage authors. See copying.md for legal info.
# Copyright 2015-2023 the openage authors. See copying.md for legal info.

from cpython.ref cimport PyObject
from libcpp.memory cimport make_unique
from libcpp.string cimport string
from libcpp.vector cimport vector

from libopenage.main cimport main_arguments, run_game as run_game_cpp
from libopenage.util.path cimport Path as Path_cpp
from libopenage.pyinterface.pyobject cimport PyObj
from libopenage.error.handlers cimport set_exit_ok


cdef extern from "Python.h":
void PyEval_InitThreads()


def run_game(args, root_path):
"""
Launches the game after arguments were translated.
Expand All @@ -39,9 +32,6 @@ def run_game(args, root_path):
# opengl debugging
args_cpp.gl_debug = args.gl_debug

# create the gil, because now starts the multithread part!
PyEval_InitThreads()

# run the game!
with nogil:
result = run_game_cpp(args_cpp)
Expand Down
7 changes: 0 additions & 7 deletions openage/main/main_cpp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ from libopenage.pyinterface.pyobject cimport PyObj
from libopenage.error.handlers cimport set_exit_ok


cdef extern from "Python.h":
void PyEval_InitThreads()


def run_game(args, root_path):
"""
Launches the game after arguments were translated.
Expand Down Expand Up @@ -45,9 +41,6 @@ def run_game(args, root_path):
else:
args_cpp.mods = vector[string]()

# create the gil, because now starts the multithread part!
PyEval_InitThreads()

# run the game!
with nogil:
result = run_game_cpp(args_cpp)
Expand Down
7 changes: 6 additions & 1 deletion run.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ which satisifies that requirement.
"""

if __name__ == '__main__@SOME_UNDEFINED_VARIABLE_CMAKE_WILL_REMOVE@':
# This is stupid but without it, Cython/Python cannot find the openage module.
import os
import sys
sys.path.append(os.getcwd())

from openage.__main__ import main
main()
else:
print("Running this in the source directory is not supported.",
"Please use `make run` or `bin/run.py` to start instead.")
"Please use `make run` or `bin/run.py` to start instead.")

0 comments on commit 3ca720b

Please sign in to comment.