From 3de19ad30537ca3abbc09ea8971f231f64f4ec3b Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 23:32:43 +0400 Subject: [PATCH] lib_imaging POC --- docs/reference/internal_modules.rst | 2 +- setup.py | 20 +++++++++++++++----- src/PIL/features.py | 4 ++-- src/_imaging.c | 10 +++++----- src/_webp.c | 10 ---------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/reference/internal_modules.rst b/docs/reference/internal_modules.rst index 2fb4ff8c018..51f77ab8bc7 100644 --- a/docs/reference/internal_modules.rst +++ b/docs/reference/internal_modules.rst @@ -73,7 +73,7 @@ on some Python versions. :mod:`PIL.Image.core` Module ---------------------------- -.. module:: PIL._imaging +.. module:: PIL.lib_imaging .. module:: PIL.Image.core An internal interface module previously known as :mod:`~PIL._imaging`, diff --git a/setup.py b/setup.py index 2c5a765dcc6..ef4129a6ece 100644 --- a/setup.py +++ b/setup.py @@ -14,11 +14,14 @@ import struct import subprocess import sys +import sysconfig import warnings from setuptools import Extension, setup from setuptools.command.build_ext import build_ext +EXT_SUFFIX, _, _ = sysconfig.get_config_var("EXT_SUFFIX").rpartition(".") + def get_version(): version_file = "src/PIL/_version.py" @@ -411,7 +414,7 @@ def _update_extension(self, name, libraries, define_macros=None, sources=None): if FUZZING_BUILD: extension.language = "c++" extension.extra_link_args = ["--stdlib=libc++"] - break + return extension def _remove_extension(self, name): for extension in self.extensions: @@ -854,7 +857,7 @@ def build_extensions(self): defs.append(("PILLOW_VERSION", f'"{PILLOW_VERSION}"')) - self._update_extension("PIL._imaging", libs, defs) + self._update_extension("PIL.lib_imaging", libs, defs) # # additional libraries @@ -891,8 +894,15 @@ def build_extensions(self): self._remove_extension("PIL._imagingcms") if feature.webp: - libs = [feature.webp, feature.webp + "mux", feature.webp + "demux"] - self._update_extension("PIL._webp", libs) + libs = [ + f"_imaging{EXT_SUFFIX}", + feature.webp, + feature.webp + "mux", + feature.webp + "demux", + ] + ext = self._update_extension("PIL._webp", libs) + ext.library_dirs.append(f"{self.build_lib}/PIL/") + ext.runtime_library_dirs.append("$ORIGIN") else: self._remove_extension("PIL._webp") @@ -972,7 +982,7 @@ def debug_build(): for src_file in _LIB_IMAGING: files.append(os.path.join("src/libImaging", src_file + ".c")) ext_modules = [ - Extension("PIL._imaging", files), + Extension("PIL.lib_imaging", files), Extension("PIL._imagingft", ["src/_imagingft.c"]), Extension("PIL._imagingcms", ["src/_imagingcms.c"]), Extension("PIL._webp", ["src/_webp.c"]), diff --git a/src/PIL/features.py b/src/PIL/features.py index 24c5ee978b3..d8eb421ede5 100644 --- a/src/PIL/features.py +++ b/src/PIL/features.py @@ -12,7 +12,7 @@ from ._deprecate import deprecate modules = { - "pil": ("PIL._imaging", "PILLOW_VERSION"), + "pil": ("PIL.lib_imaging", "PILLOW_VERSION"), "tkinter": ("PIL._tkinter_finder", "tk_version"), "freetype2": ("PIL._imagingft", "freetype2_version"), "littlecms2": ("PIL._imagingcms", "littlecms_version"), @@ -128,7 +128,7 @@ def get_supported_codecs() -> list[str]: "harfbuzz": ("PIL._imagingft", "HAVE_HARFBUZZ", "harfbuzz_version"), "libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO", "libjpeg_turbo_version"), "libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT", "imagequant_version"), - "xcb": ("PIL._imaging", "HAVE_XCB", None), + "xcb": ("PIL.lib_imaging", "HAVE_XCB", None), } diff --git a/src/_imaging.c b/src/_imaging.c index b40560772d1..0a770655d43 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -4412,15 +4412,15 @@ setup_module(PyObject *m) { } PyMODINIT_FUNC -PyInit__imaging(void) { +PyInit_lib_imaging(void) { PyObject *m; static PyModuleDef module_def = { PyModuleDef_HEAD_INIT, - "_imaging", /* m_name */ - NULL, /* m_doc */ - -1, /* m_size */ - functions, /* m_methods */ + "lib_imaging", /* m_name */ + NULL, /* m_doc */ + -1, /* m_size */ + functions, /* m_methods */ }; m = PyModule_Create(&module_def); diff --git a/src/_webp.c b/src/_webp.c index 9e66cdb8c20..eaef92e32f5 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -16,16 +16,6 @@ #error libwebp 0.5.0 and above is required. Upgrade libwebp or build Pillow with --disable-webp flag #endif -void -ImagingSectionEnter(ImagingSectionCookie *cookie) { - *cookie = (PyThreadState *)PyEval_SaveThread(); -} - -void -ImagingSectionLeave(ImagingSectionCookie *cookie) { - PyEval_RestoreThread((PyThreadState *)*cookie); -} - /* -------------------------------------------------------------------- */ /* WebP Muxer Error Handling */ /* -------------------------------------------------------------------- */