From 21569d5cf57436a47263cdae33187adc6eae2fb1 Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Sun, 10 Mar 2024 15:31:07 +0100 Subject: [PATCH 1/2] Fix macOS build --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 776022c..bd6df2f 100644 --- a/setup.py +++ b/setup.py @@ -47,6 +47,8 @@ def extension_kwargs(): str(taglib_install_dir / "lib"), str(taglib_install_dir / "lib64"), ], + extra_compile_args=["-std=c++17"], + extra_link_args=["-std=c++17"], ) From d879acc5b7504ab26db6f74476220d545ed76232 Mon Sep 17 00:00:00 2001 From: Urs Fleisch Date: Sun, 10 Mar 2024 15:37:36 +0100 Subject: [PATCH 2/2] Fix Windows build --- .github/workflows/default.yml | 4 ++-- src/ctypes.pxd | 21 +++++++++++++++------ src/taglib.pyx | 6 +++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index e619e4f..b2f1439 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -6,7 +6,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, macos-latest] #, windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} env: #CIBW_SKIP: "*p36-* *p37-*" @@ -41,7 +41,7 @@ jobs: path: dist retention-days: 5 - name: build binary wheels - uses: pypa/cibuildwheel@v2.16.2 + uses: pypa/cibuildwheel@v2.16.5 - name: upload wheels uses: actions/upload-artifact@v3 with: diff --git a/src/ctypes.pxd b/src/ctypes.pxd index 68cb903..8c04d6b 100644 --- a/src/ctypes.pxd +++ b/src/ctypes.pxd @@ -7,9 +7,16 @@ """This file contains the external C/C++ definitions used by taglib.pyx.""" +from libc.stddef cimport wchar_t from libcpp.list cimport list from libcpp.map cimport map from libcpp.string cimport string +from cpython.mem cimport PyMem_Free +from cpython.object cimport PyObject + + +cdef extern from "Python.h": + cdef wchar_t *PyUnicode_AsWideCharString(PyObject *path, Py_ssize_t *size) cdef extern from 'taglib/tstring.h' namespace 'TagLib::String': @@ -69,7 +76,7 @@ cdef extern from 'taglib/tiostream.h' namespace 'TagLib': ctypedef char* FileName ELSE: cdef cppclass FileName: - FileName(const char*) + FileName(const wchar_t*) cdef extern from 'taglib/fileref.h' namespace 'TagLib': cdef cppclass FileRef: @@ -82,13 +89,15 @@ cdef extern from 'taglib/fileref.h' namespace 'TagLib': PropertyMap setProperties(PropertyMap&) void removeUnsupportedProperties(StringList&) -cdef inline FileRef* create_wrapper(char* path) except +: +cdef inline FileRef* create_wrapper(unicode path) except +: IF UNAME_SYSNAME != "Windows": - return new FileRef(path, True, ReadStyle.Average) + return new FileRef(path.encode('utf-8'), True, ReadStyle.Average) ELSE: - cdef FileName fn = FileName(path) - return new FileRef(fn, True, ReadStyle.Average) + cdef wchar_t *wchar_path = PyUnicode_AsWideCharString(path, NULL) + cdef FileRef *file_ref = new FileRef(FileName(wchar_path), True, ReadStyle.Average) + PyMem_Free(wchar_path) + return file_ref cdef extern from 'taglib/taglib.h': int TAGLIB_MAJOR_VERSION - int TAGLIB_MINOR_VERSION \ No newline at end of file + int TAGLIB_MINOR_VERSION diff --git a/src/taglib.pyx b/src/taglib.pyx index e60d640..3bdf61a 100644 --- a/src/taglib.pyx +++ b/src/taglib.pyx @@ -81,7 +81,7 @@ cdef class File: path = path.decode('utf-8') path = Path(path) self.path = path - self.cFile = ctypes.create_wrapper(str(path).encode('utf-8')) + self.cFile = ctypes.create_wrapper(str(path)) if self.cFile is NULL or self.cFile.file() is NULL or not self.cFile.file().isValid(): raise OSError(f'Could not read file {path}') @@ -93,7 +93,7 @@ cdef class File: cdef void readProperties(self): """Convert the Taglib::PropertyMap of the wrapped Taglib::File object into a python dict. - + This method is not accessible from Python, and is called only once, immediately after object creation. """ @@ -219,4 +219,4 @@ def taglib_version() -> tuple[int, int]: circumstances (e.g. dynamic linking, or re-using the cythonized code after upgrading Taglib) the actually running Taglib version might be different. """ - return ctypes.TAGLIB_MAJOR_VERSION, ctypes.TAGLIB_MINOR_VERSION \ No newline at end of file + return ctypes.TAGLIB_MAJOR_VERSION, ctypes.TAGLIB_MINOR_VERSION