-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean dlopen #135
Clean dlopen #135
Conversation
Be aware that a dot in the given search name influences whether
BTW: On Windows, when |
This installs Is MSYS2's fontconfig aware of fonts in that folder? Afaik the default FontConfig configuration reads fonts from WINDOWSFONTDIR... |
You know that the explicit library names for Windows introduced in 4b73af3 open the door to DLL hell? The dot in the search name triggers Until now, without the When the DLLs are detected by So please: Remove the |
I'm not sure to understand this very well, but here's what I understand. I think that CairoCFFI in this pull request doesn't use
Tests are broken on Windows and Mac before 4b73af3, with I think that with the current code, using The documentation also says that:
Maybe that's what we should do, instead of using explicit filenames. Searching in the early commits could help to understand why it was not enough, and why we had to add this custom WeasyPrint's
The bugs happen in tests using the toy font implementation in Cairo, I think that it doesn't use FontConfig at all. I think that Cairo is able to find installed fonts, but the default font may be monospace. Using |
Default font for Windows is supposed to be Arial, and the second failing test uses |
There is no magic in def _load_backend_lib(backend, name, flags):
import os
[...]
first_error = None
if '.' in name or '/' in name or os.sep in name:
try:
return backend.load_library(name, flags)
except OSError as e:
first_error = e
import ctypes.util
path = ctypes.util.find_library(name)
if path is None:
[...]
raise OSError(msg)
return backend.load_library(path, flags) To load cairo (or any other GTK library) on Windows the searchname for loading should be the filename of the dll without These are the names for GTK3 on Windows: cairo = ffi.dlopen('libcairo-2')
gdk_pixbuf = ffi.dlopen('libgdk_pixbuf-2.0-0')
gobject = ffi.dlopen('libgobject-2.0-0')
glib = ffi.dlopen('libglib-2.0-0')
# Don't know the name for gdk because there is (besides libgdk_pixbuf-2.0-0.dll)
# no libgdk*.dll in my GTK folder. At least if we want to avoid the magic of |
The explicit filenames (aka dots and slashes) can be a fallback for Linux systems where Dunno whether it helps OS X, too, have no idea how darwin finds and loads libraries- |
OMG, yes, you are right! |
💣 stupid 💣 insane 💣 Favouring this one: lib = ffi.dlopen(ctypes.util.find_library(lib_name) or lib_name) Nevertheless the search name for a Windows dlls should be the filename. The |
Yes, but (after a quick look at the source code) I guess that's only the case when Cairo is not compiled with support for FreeType. The MSYS2 Cairo has FreeType/FontConfig support afaik an then... CAIRO_FONT_FAMILY_DEFAULT == CAIRO_FT_FONT_FAMILY_DEFAULT == "". My experience with my Cairo is that it defaults to DejaVu unless told otherwise. |
Oh WOW 🎉 only just noticed: you got it 🥇 (forget that stupid isort) |
For the records: cairocffi uses cffi in out-of-line mode. That is If the path isn't an absolute one, the OS will apply its own algorithms to resolve the given string. This involves the current working directory, environment variables and default search paths. Since (at least on Linux and OS X) you never know for sure the prefix and suffix of a requested library file, we (cairoffi.dlopen) should call The Python function
So far so good -- if But sometimes
Additional challenge: |
You're right. fa7d93a takes the idea but keeps the signature. As the library name was useless before fa7d93a, we're at least sure that the fallback works on 3 OSes on Travis and on my Linux. After the commit, the library name works on my computer for sure, but maybe it doesn't on Windows and Mac.
Of course, we'll probably have to add other filenames. |
Oh, and this PR now fixes #95. |
Oh no, please don't do this!
The |
I'd really like to have this signature: def dlopen(ffi, *names, *filenames)
... |
BTW: It's not about writing a universal ffi.dlopen, it's only about Cairo and Pixbuf. |
I'm quite sure (90%) that these are the names we should search for with
|
If you don't like two list parameters, this might work, too: def dlopen(ffi, posix_name, win_name, *filenames)
...
Though, two lists are more flexible. |
Well… Why not. |
Version 1.7.0 ............. Released on 2024-04-27 * Drop Python 3.7 support, add Python 3.12 support * `#221 <https://github.com/Kozea/cairocffi/pull/225>`_: Add environment variable to set folder where DLLs are installed on Windows * `#225 <https://github.com/Kozea/cairocffi/pull/225>`_: Use Ruff instead of Flake8 and isort Version 1.6.1 ............. Released on 2023-07-24 * `#217 <https://github.com/Kozea/cairocffi/issues/217>`_: Repair installation with PyInstaller Version 1.6.0 ............. Released on 2023-06-12 **This version uses a new CFFI mode that may break your program.** CairoCFFI now uses Flit for packaging and is also distributed as a Python wheel. Please test carefully and don’t hesitate to report issues before using it in production. * `#216 <https://github.com/Kozea/cairocffi/pull/216>`_: Use ABI-level in-line CFFI mode Version 1.5.1 ............. Released on 2023-04-15 * `#212 <https://github.com/Kozea/cairocffi/issues/212>`_: Bring back XCB support during wheel generation Version 1.5.0 ............. Released on 2023-03-17 * `#106 <https://github.com/Kozea/cairocffi/issues/106>`_, `#200 <https://github.com/Kozea/cairocffi/issues/200>`_: Fallback to manual PNG file creation on hardened systems * `#210 <https://github.com/Kozea/cairocffi/pull/210>`_: Use pyproject.toml for packaging and remove other useless files Version 1.4.0 ............. Released on 2022-09-23 * `#205 <https://github.com/Kozea/cairocffi/pull/205>`_: Use pikepdf to parse generated PDF * `#171 <https://github.com/Kozea/cairocffi/pull/171>`_: Don’t use deprecated pytest-runner anymore Version 1.3.0 ............. Released on 2021-10-04 * `2cd512d <https://github.com/Kozea/cairocffi/commit/2cd512d>`_: Drop Python 3.6 support * `#196 <https://github.com/Kozea/cairocffi/pull/196>`_: Fix import `constants.py` import * `#169 <https://github.com/Kozea/cairocffi/pull/169>`_: Add extra library name "cairo-2.dll" * `#178 <https://github.com/Kozea/cairocffi/pull/178>`_: Workaround for testing date string with cairo 1.17.4 * `#186 <https://github.com/Kozea/cairocffi/pull/186>`_: Fix link in documentation * `#195 <https://github.com/Kozea/cairocffi/pull/195>`_: Fix typo in documentation * `#184 <https://github.com/Kozea/cairocffi/pull/184>`_, `a4fc2a7 <https://github.com/Kozea/cairocffi/commit/a4fc2a7>`_: Clean .gitignore Version 1.2.0 ............. Released on 2020-10-29 * `#152 <https://github.com/Kozea/cairocffi/pull/152>`_: Add NumPy support * `#143 <https://github.com/Kozea/cairocffi/issues/143>`_: Make write_to_png function work on hardened systems * `#156 <https://github.com/Kozea/cairocffi/pull/156>`_: Use major version name to open shared libraries * `#165 <https://github.com/Kozea/cairocffi/pull/165>`_: Don’t list setuptools as required for installation Version 1.1.0 ............. Released on 2019-09-05 * `#135 <https://github.com/Kozea/cairocffi/pull/135>`_, `#127 <https://github.com/Kozea/cairocffi/pull/127>`_, `#119 <https://github.com/Kozea/cairocffi/pull/119>`_: Clean the way external libraries are found * `#126 <https://github.com/Kozea/cairocffi/pull/126>`_: Remove const char* elements from cdef * Support Cairo features up to 1.17.2 * Fix documentation generation Version 1.0.2 ............. Released on 2019-02-15 * `#123 <https://github.com/Kozea/cairocffi/issues/123>`_: Rely on a recent version of setuptools to handle VERSION Version 1.0.1 ............. Released on 2019-02-12 * `#120 <https://github.com/Kozea/cairocffi/issues/120>`_: Don't delete _generated modules on ffi_build import Version 1.0.0 ............. Released on 2019-02-08 6 years after its first release, cairocffi can now be considered as stable. * Drop Python 2.6, 2.7 and 3.4 support * Test with Python 3.7 * Clean code, tests and packaging
Using
dlopen
's version from WeasyPrint should be enough, as it's widely tested. It's much simpler and should help debugging in the future.We should at least add CI for Windows and macOS before merging.