Skip to content

Commit

Permalink
Fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
ufleisch authored and supermihi committed Mar 16, 2024
1 parent 829c09c commit 50dd829
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
31 changes: 24 additions & 7 deletions src/ctypes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -53,9 +60,6 @@ cdef extern from 'taglib/audioproperties.h' namespace 'TagLib::AudioProperties':
Average = 1
Accurate = 2

cdef extern from 'taglib/tiostream.h' namespace 'TagLib':
ctypedef FileName

cdef extern from 'taglib/tfile.h' namespace 'TagLib':
cdef cppclass File:
AudioProperties *audioProperties()
Expand All @@ -67,20 +71,33 @@ cdef extern from 'taglib/tfile.h' namespace 'TagLib':
void removeUnsupportedProperties(StringList&)


cdef extern from 'taglib/tiostream.h' namespace 'TagLib':
IF UNAME_SYSNAME != "Windows":
ctypedef char* FileName
ELSE:
cdef cppclass FileName:
FileName(const wchar_t*)

cdef extern from 'taglib/fileref.h' namespace 'TagLib':
cdef cppclass FileRef:
FileRef(const char*, boolean, ReadStyle) except +
FileRef(FileName, boolean, ReadStyle) except +
File* file()

AudioProperties *audioProperties()
bint save() except +
PropertyMap properties()
PropertyMap setProperties(PropertyMap&)
void removeUnsupportedProperties(StringList&)

cdef inline FileRef* create_wrapper(unicode path) except +:
cdef FileName fn = path.encode('utf-8')
return new FileRef(fn, True, ReadStyle.Average)
IF UNAME_SYSNAME != "Windows":
return new FileRef(path.encode('utf-8'), True, ReadStyle.Average)
ELSE:
cdef wchar_t *wchar_path = PyUnicode_AsWideCharString(<PyObject*>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
int TAGLIB_MINOR_VERSION
4 changes: 2 additions & 2 deletions src/taglib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
return ctypes.TAGLIB_MAJOR_VERSION, ctypes.TAGLIB_MINOR_VERSION

0 comments on commit 50dd829

Please sign in to comment.