From 39acff076893739fde58197f8e41f79e55e813d0 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 20:11:25 +0400 Subject: [PATCH 1/7] Rename ImPlatform to ImagingPlatform --- src/libImaging/ImDib.h | 2 +- src/libImaging/Imaging.h | 2 +- src/libImaging/{ImPlatform.h => ImagingPlatform.h} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/libImaging/{ImPlatform.h => ImagingPlatform.h} (100%) diff --git a/src/libImaging/ImDib.h b/src/libImaging/ImDib.h index 91ff3f322ff..e188ffc8e54 100644 --- a/src/libImaging/ImDib.h +++ b/src/libImaging/ImDib.h @@ -12,7 +12,7 @@ #ifdef _WIN32 -#include "ImPlatform.h" +#include "ImagingPlatform.h" #if defined(__cplusplus) extern "C" { diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index 321dce988c3..c3c23f88b9a 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -10,7 +10,7 @@ * See the README file for information on usage and redistribution. */ -#include "ImPlatform.h" +#include "ImagingPlatform.h" #if defined(__cplusplus) extern "C" { diff --git a/src/libImaging/ImPlatform.h b/src/libImaging/ImagingPlatform.h similarity index 100% rename from src/libImaging/ImPlatform.h rename to src/libImaging/ImagingPlatform.h From 9470bba4c6b7b18bc26fb11c821584e16584aac3 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 20:40:04 +0400 Subject: [PATCH 2/7] Remove weird comments --- src/encode.c | 7 ------- src/libImaging/Jpeg2K.h | 7 ------- src/libImaging/Jpeg2KDecode.c | 7 ------- src/libImaging/Jpeg2KEncode.c | 7 ------- 4 files changed, 28 deletions(-) diff --git a/src/encode.c b/src/encode.c index 529982dadc5..1a4cd489da2 100644 --- a/src/encode.c +++ b/src/encode.c @@ -1411,10 +1411,3 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) { } #endif - -/* - * Local Variables: - * c-basic-offset: 4 - * End: - * - */ diff --git a/src/libImaging/Jpeg2K.h b/src/libImaging/Jpeg2K.h index e8d92f7b6bc..6fbbf7311a1 100644 --- a/src/libImaging/Jpeg2K.h +++ b/src/libImaging/Jpeg2K.h @@ -104,10 +104,3 @@ typedef struct { int plt; } JPEG2KENCODESTATE; - -/* - * Local Variables: - * c-basic-offset: 4 - * End: - * - */ diff --git a/src/libImaging/Jpeg2KDecode.c b/src/libImaging/Jpeg2KDecode.c index 5b3d7ffc424..61bb396eb5c 100644 --- a/src/libImaging/Jpeg2KDecode.c +++ b/src/libImaging/Jpeg2KDecode.c @@ -980,10 +980,3 @@ ImagingJpeg2KVersion(void) { } #endif /* HAVE_OPENJPEG */ - -/* - * Local Variables: - * c-basic-offset: 4 - * End: - * - */ diff --git a/src/libImaging/Jpeg2KEncode.c b/src/libImaging/Jpeg2KEncode.c index cb21a186c0b..d30ccde603e 100644 --- a/src/libImaging/Jpeg2KEncode.c +++ b/src/libImaging/Jpeg2KEncode.c @@ -652,10 +652,3 @@ ImagingJpeg2KEncodeCleanup(ImagingCodecState state) { } #endif /* HAVE_OPENJPEG */ - -/* - * Local Variables: - * c-basic-offset: 4 - * End: - * - */ From 1348161fc6fdda4797c19cab768b6b6f49d275c9 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 20:34:55 +0400 Subject: [PATCH 3/7] Drop support of not C99+ compilers (including old MSVC) --- src/_imagingcms.c | 6 ---- src/display.c | 6 ---- src/libImaging/Dib.c | 3 +- src/libImaging/Draw.c | 1 - src/libImaging/ImDib.h | 2 -- src/libImaging/ImagingPlatform.h | 61 +++++--------------------------- src/libImaging/QuantOctree.c | 2 +- src/libImaging/QuantTypes.h | 9 ++--- 8 files changed, 13 insertions(+), 77 deletions(-) diff --git a/src/_imagingcms.c b/src/_imagingcms.c index bafe787a743..225bb215855 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -619,12 +619,6 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) { #ifdef _WIN32 -#ifdef _WIN64 -#define F_HANDLE "K" -#else -#define F_HANDLE "k" -#endif - static PyObject * cms_get_display_profile_win32(PyObject *self, PyObject *args) { char filename[MAX_PATH]; diff --git a/src/display.c b/src/display.c index b4e2e38991a..f6380dff399 100644 --- a/src/display.c +++ b/src/display.c @@ -34,12 +34,6 @@ #include "libImaging/ImDib.h" -#if SIZEOF_VOID_P == 8 -#define F_HANDLE "K" -#else -#define F_HANDLE "k" -#endif - typedef struct { PyObject_HEAD ImagingDIB dib; } ImagingDisplayObject; diff --git a/src/libImaging/Dib.c b/src/libImaging/Dib.c index c69e9e552ae..a34fba85aa2 100644 --- a/src/libImaging/Dib.c +++ b/src/libImaging/Dib.c @@ -19,10 +19,9 @@ * See the README file for information on usage and redistribution. */ -#include "Imaging.h" - #ifdef _WIN32 +#include "Imaging.h" #include "ImDib.h" char * diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index f1c8ffcff8d..5c61e0e7ed3 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -35,7 +35,6 @@ #include "Imaging.h" #include -#include #define CEIL(v) (int)ceil(v) #define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v)) diff --git a/src/libImaging/ImDib.h b/src/libImaging/ImDib.h index e188ffc8e54..a0c2348fd08 100644 --- a/src/libImaging/ImDib.h +++ b/src/libImaging/ImDib.h @@ -12,8 +12,6 @@ #ifdef _WIN32 -#include "ImagingPlatform.h" - #if defined(__cplusplus) extern "C" { #endif diff --git a/src/libImaging/ImagingPlatform.h b/src/libImaging/ImagingPlatform.h index f6e7fb6b921..e28415d5bb1 100644 --- a/src/libImaging/ImagingPlatform.h +++ b/src/libImaging/ImagingPlatform.h @@ -7,7 +7,7 @@ * Copyright (c) Fredrik Lundh 1995-2003. */ -#include "Python.h" +#include /* Check that we have an ANSI compliant compiler */ #ifndef HAVE_PROTOTYPES @@ -17,34 +17,25 @@ #error Sorry, this library requires ANSI header files. #endif -#if defined(PIL_NO_INLINE) -#define inline -#else #if defined(_MSC_VER) && !defined(__GNUC__) #define inline __inline #endif -#endif - -#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include -#ifdef __CYGWIN__ -#undef _WIN64 -#undef _WIN32 -#undef __WIN32__ -#undef WIN32 +#ifdef _WIN64 +#define F_HANDLE "K" +#else +#define F_HANDLE "k" #endif -#else /* not WIN */ -/* For System that are not Windows, we'll need to define these. */ -/* We have to define them instead of using typedef because the JPEG lib also +#endif /* _WIN32 */ + +/* We have to define types instead of using typedef because the JPEG lib also defines their own types with the same names, so we need to be able to undef ours before including the JPEG code. */ - -#if __STDC_VERSION__ >= 199901L /* C99+ */ - #include #define INT8 int8_t @@ -54,45 +45,11 @@ #define INT32 int32_t #define UINT32 uint32_t -#else /* < C99 */ - -#define INT8 signed char - -#if SIZEOF_SHORT == 2 -#define INT16 short -#elif SIZEOF_INT == 2 -#define INT16 int -#else -#error Cannot find required 16-bit integer type -#endif - -#if SIZEOF_SHORT == 4 -#define INT32 short -#elif SIZEOF_INT == 4 -#define INT32 int -#elif SIZEOF_LONG == 4 -#define INT32 long -#else -#error Cannot find required 32-bit integer type -#endif - -#define UINT8 unsigned char -#define UINT16 unsigned INT16 -#define UINT32 unsigned INT32 - -#endif /* < C99 */ - -#endif /* not WIN */ - /* assume IEEE; tweak if necessary (patches are welcome) */ #define FLOAT16 UINT16 #define FLOAT32 float #define FLOAT64 double -#ifdef _MSC_VER -typedef signed __int64 int64_t; -#endif - #ifdef __GNUC__ #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #endif diff --git a/src/libImaging/QuantOctree.c b/src/libImaging/QuantOctree.c index 7e02ebf65bc..7e1a5489963 100644 --- a/src/libImaging/QuantOctree.c +++ b/src/libImaging/QuantOctree.c @@ -28,7 +28,7 @@ #include #include -#include "ImagingUtils.h" +#include "Imaging.h" #include "QuantOctree.h" typedef struct _ColorBucket { diff --git a/src/libImaging/QuantTypes.h b/src/libImaging/QuantTypes.h index 986b70806dc..e01023de7e1 100644 --- a/src/libImaging/QuantTypes.h +++ b/src/libImaging/QuantTypes.h @@ -9,15 +9,10 @@ * See the README file for information on usage and redistribution. */ -#ifndef __TYPES_H__ -#define __TYPES_H__ +#ifndef __QUANTTYPES_H__ +#define __QUANTTYPES_H__ -#ifdef _MSC_VER -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; -#else #include -#endif typedef union { struct { From 81ce71e0ec40086a1509f2332690466ae61383e9 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 21:09:14 +0400 Subject: [PATCH 4/7] Move include Python.h to ImagingPlatform --- Tests/test_image_access.py | 2 +- src/_imaging.c | 3 --- src/_imagingcms.c | 12 ++++-------- src/_imagingft.c | 4 +--- src/_imagingmath.c | 6 ++---- src/_imagingmorph.c | 1 - src/_imagingtk.c | 1 - src/_webp.c | 3 +-- src/decode.c | 4 ---- src/display.c | 3 --- src/encode.c | 5 +---- src/libImaging/ImagingPlatform.h | 1 + src/libImaging/codec_fd.c | 1 - src/map.c | 2 -- src/outline.c | 2 -- src/path.c | 3 +-- 16 files changed, 12 insertions(+), 41 deletions(-) diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index bb30b462d2f..4e3435cfeec 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -282,7 +282,7 @@ def test_embeddable(self) -> None: home = sys.prefix.replace("\\", "\\\\") fh.write( f""" -#include "Python.h" +#include int main(int argc, char* argv[]) {{ diff --git a/src/_imaging.c b/src/_imaging.c index 07d9a64ccff..04ed5545cf1 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -71,9 +71,6 @@ * See the README file for information on usage and redistribution. */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - #ifdef HAVE_LIBJPEG #include "jconfig.h" #endif diff --git a/src/_imagingcms.c b/src/_imagingcms.c index 225bb215855..8103b3d5eb3 100644 --- a/src/_imagingcms.c +++ b/src/_imagingcms.c @@ -26,15 +26,11 @@ kevin@cazabon.com\n\ https://www.cazabon.com\n\ " -#define PY_SSIZE_T_CLEAN -#include "Python.h" // Include before wchar.h so _GNU_SOURCE is set -#include "wchar.h" -#include "datetime.h" +#include "libImaging/Imaging.h" // Include before wchar.h so _GNU_SOURCE is set -#include "lcms2.h" -#include "libImaging/Imaging.h" - -#define PYCMSVERSION "1.0.0 pil" +#include +#include +#include /* version history */ diff --git a/src/_imagingft.c b/src/_imagingft.c index f8143e0cc32..6f94c906a2b 100644 --- a/src/_imagingft.c +++ b/src/_imagingft.c @@ -18,10 +18,8 @@ * Copyright (c) 1998-2007 by Secret Labs AB */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Imaging.h" +#include "thirdparty/pythoncapi_compat.h" #include #include FT_FREETYPE_H diff --git a/src/_imagingmath.c b/src/_imagingmath.c index 550a1090382..bfbd648b4fd 100644 --- a/src/_imagingmath.c +++ b/src/_imagingmath.c @@ -13,12 +13,10 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" - #include "libImaging/Imaging.h" -#include "math.h" -#include "float.h" +#include +#include #define MAX_INT32 2147483647.0 #define MIN_INT32 -2147483648.0 diff --git a/src/_imagingmorph.c b/src/_imagingmorph.c index 614dfbe7fe7..c7548b4e953 100644 --- a/src/_imagingmorph.c +++ b/src/_imagingmorph.c @@ -11,7 +11,6 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" #include "libImaging/Imaging.h" #define LUT_SIZE (1 << 9) diff --git a/src/_imagingtk.c b/src/_imagingtk.c index c70d044bb86..076995daf27 100644 --- a/src/_imagingtk.c +++ b/src/_imagingtk.c @@ -12,7 +12,6 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" #include "libImaging/Imaging.h" #include "Tk/_tkmini.h" diff --git a/src/_webp.c b/src/_webp.c index f59ad30367b..9e66cdb8c20 100644 --- a/src/_webp.c +++ b/src/_webp.c @@ -1,6 +1,5 @@ -#define PY_SSIZE_T_CLEAN -#include #include "libImaging/Imaging.h" + #include #include #include diff --git a/src/decode.c b/src/decode.c index 51d0aced2bd..d002f0649af 100644 --- a/src/decode.c +++ b/src/decode.c @@ -29,11 +29,7 @@ /* FIXME: make these pluggable! */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - #include "libImaging/Imaging.h" - #include "libImaging/Bit.h" #include "libImaging/Bcn.h" #include "libImaging/Gif.h" diff --git a/src/display.c b/src/display.c index f6380dff399..07801679769 100644 --- a/src/display.c +++ b/src/display.c @@ -22,9 +22,6 @@ * See the README file for information on usage and redistribution. */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - #include "libImaging/Imaging.h" /* -------------------------------------------------------------------- */ diff --git a/src/encode.c b/src/encode.c index 1a4cd489da2..f828401b6dd 100644 --- a/src/encode.c +++ b/src/encode.c @@ -22,11 +22,8 @@ /* FIXME: make these pluggable! */ -#define PY_SSIZE_T_CLEAN -#include "Python.h" - -#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Imaging.h" +#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Gif.h" #ifdef HAVE_UNISTD_H diff --git a/src/libImaging/ImagingPlatform.h b/src/libImaging/ImagingPlatform.h index e28415d5bb1..78d27067c30 100644 --- a/src/libImaging/ImagingPlatform.h +++ b/src/libImaging/ImagingPlatform.h @@ -7,6 +7,7 @@ * Copyright (c) Fredrik Lundh 1995-2003. */ +#define PY_SSIZE_T_CLEAN #include /* Check that we have an ANSI compliant compiler */ diff --git a/src/libImaging/codec_fd.c b/src/libImaging/codec_fd.c index 5261681107b..f5541c332f2 100644 --- a/src/libImaging/codec_fd.c +++ b/src/libImaging/codec_fd.c @@ -1,4 +1,3 @@ -#include "Python.h" #include "Imaging.h" Py_ssize_t diff --git a/src/map.c b/src/map.c index c66702981d3..2fcaa74d222 100644 --- a/src/map.c +++ b/src/map.c @@ -18,8 +18,6 @@ * FIXME: should move the memory mapping primitives into libImaging! */ -#include "Python.h" - #include "libImaging/Imaging.h" /* compatibility wrappers (defined in _imaging.c) */ diff --git a/src/outline.c b/src/outline.c index 27cc255cf84..b84bef437c3 100644 --- a/src/outline.c +++ b/src/outline.c @@ -17,8 +17,6 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" - #include "libImaging/Imaging.h" /* -------------------------------------------------------------------- */ diff --git a/src/path.c b/src/path.c index b96e8b78a70..78a4f09f500 100644 --- a/src/path.c +++ b/src/path.c @@ -25,9 +25,8 @@ * See the README file for information on usage and redistribution. */ -#include "Python.h" -#include "thirdparty/pythoncapi_compat.h" #include "libImaging/Imaging.h" +#include "thirdparty/pythoncapi_compat.h" #include From fec83b58af438e7b71c5102ce592ede32c58a921 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 21:14:51 +0400 Subject: [PATCH 5/7] Move import math.h to ImagingPlatform --- src/_imaging.c | 2 -- src/_imagingmath.c | 1 - src/libImaging/ColorLUT.c | 1 - src/libImaging/Draw.c | 2 -- src/libImaging/Effects.c | 2 -- src/libImaging/Fill.c | 2 -- src/libImaging/Imaging.h | 4 ---- src/libImaging/ImagingPlatform.h | 3 +++ src/libImaging/Palette.c | 2 -- src/libImaging/Quant.c | 1 - src/libImaging/Reduce.c | 2 -- src/libImaging/Resample.c | 2 -- src/path.c | 2 -- 13 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index 04ed5545cf1..b40560772d1 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -87,8 +87,6 @@ #include "libImaging/Imaging.h" -#define _USE_MATH_DEFINES -#include #include #undef VERBOSE diff --git a/src/_imagingmath.c b/src/_imagingmath.c index bfbd648b4fd..54b49ee6246 100644 --- a/src/_imagingmath.c +++ b/src/_imagingmath.c @@ -15,7 +15,6 @@ #include "libImaging/Imaging.h" -#include #include #define MAX_INT32 2147483647.0 diff --git a/src/libImaging/ColorLUT.c b/src/libImaging/ColorLUT.c index 5559de689b2..33633f555d1 100644 --- a/src/libImaging/ColorLUT.c +++ b/src/libImaging/ColorLUT.c @@ -1,5 +1,4 @@ #include "Imaging.h" -#include /* 8 bits for result. Table can overflow [0, 1.0] range, so we need extra bits for overflow and negative values. diff --git a/src/libImaging/Draw.c b/src/libImaging/Draw.c index 5c61e0e7ed3..730bba8acec 100644 --- a/src/libImaging/Draw.c +++ b/src/libImaging/Draw.c @@ -34,8 +34,6 @@ #include "Imaging.h" -#include - #define CEIL(v) (int)ceil(v) #define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v)) diff --git a/src/libImaging/Effects.c b/src/libImaging/Effects.c index 93e7af0bce9..64d6188d917 100644 --- a/src/libImaging/Effects.c +++ b/src/libImaging/Effects.c @@ -17,8 +17,6 @@ #include "Imaging.h" -#include - Imaging ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) { /* Generate a Mandelbrot set covering the given extent */ diff --git a/src/libImaging/Fill.c b/src/libImaging/Fill.c index 8fb481e7e4d..1e4bb9ba0b5 100644 --- a/src/libImaging/Fill.c +++ b/src/libImaging/Fill.c @@ -17,8 +17,6 @@ #include "Imaging.h" -#include "math.h" - Imaging ImagingFill(Imaging im, const void *colour) { int x, y; diff --git a/src/libImaging/Imaging.h b/src/libImaging/Imaging.h index c3c23f88b9a..34ffae0f324 100644 --- a/src/libImaging/Imaging.h +++ b/src/libImaging/Imaging.h @@ -16,10 +16,6 @@ extern "C" { #endif -#ifndef M_PI -#define M_PI 3.1415926535897932384626433832795 -#endif - /* -------------------------------------------------------------------- */ /* diff --git a/src/libImaging/ImagingPlatform.h b/src/libImaging/ImagingPlatform.h index 78d27067c30..3a3875daf6e 100644 --- a/src/libImaging/ImagingPlatform.h +++ b/src/libImaging/ImagingPlatform.h @@ -10,6 +10,9 @@ #define PY_SSIZE_T_CLEAN #include +#define _USE_MATH_DEFINES +#include + /* Check that we have an ANSI compliant compiler */ #ifndef HAVE_PROTOTYPES #error Sorry, this library requires support for ANSI prototypes. diff --git a/src/libImaging/Palette.c b/src/libImaging/Palette.c index 78916bca52b..032ce8ab26a 100644 --- a/src/libImaging/Palette.c +++ b/src/libImaging/Palette.c @@ -18,8 +18,6 @@ #include "Imaging.h" -#include - ImagingPalette ImagingPaletteNew(const char *mode) { /* Create a palette object */ diff --git a/src/libImaging/Quant.c b/src/libImaging/Quant.c index a489a882db2..147d8ae52cb 100644 --- a/src/libImaging/Quant.c +++ b/src/libImaging/Quant.c @@ -1428,7 +1428,6 @@ quantize( } #ifdef TEST_NEAREST_NEIGHBOUR -#include { uint32_t bestmatch, bestdist, dist; HashTable *h2; diff --git a/src/libImaging/Reduce.c b/src/libImaging/Reduce.c index 022daa0003f..6da18d773d5 100644 --- a/src/libImaging/Reduce.c +++ b/src/libImaging/Reduce.c @@ -1,7 +1,5 @@ #include "Imaging.h" -#include - #define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F)) UINT32 diff --git a/src/libImaging/Resample.c b/src/libImaging/Resample.c index 222d6bca433..0cc8c2b69c3 100644 --- a/src/libImaging/Resample.c +++ b/src/libImaging/Resample.c @@ -1,7 +1,5 @@ #include "Imaging.h" -#include - #define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F)) struct filter { diff --git a/src/path.c b/src/path.c index 78a4f09f500..d42b021dac9 100644 --- a/src/path.c +++ b/src/path.c @@ -28,8 +28,6 @@ #include "libImaging/Imaging.h" #include "thirdparty/pythoncapi_compat.h" -#include - /* compatibility wrappers (defined in _imaging.c) */ extern int PyImaging_CheckBuffer(PyObject *buffer); From 4c5345cf5356aa91561a5e097d1c87e5216e23ce Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 23:24:29 +0400 Subject: [PATCH 6/7] Remove add-imaging-libs option --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 863d102cf85..2c5a765dcc6 100644 --- a/setup.py +++ b/setup.py @@ -333,7 +333,6 @@ def __iter__(self): ("disable-platform-guessing", None, "Disable platform guessing on Linux"), ("debug", None, "Debug logging"), ] - + [("add-imaging-libs=", None, "Add libs to _imaging build")] ) @staticmethod @@ -344,7 +343,6 @@ def initialize_options(self): self.disable_platform_guessing = self.check_configuration( "platform-guessing", "disable" ) - self.add_imaging_libs = "" build_ext.initialize_options(self) for x in self.feature: setattr(self, f"disable_{x}", self.check_configuration(x, "disable")) @@ -821,7 +819,7 @@ def build_extensions(self): # # core library - libs = self.add_imaging_libs.split() + libs = [] defs = [] if feature.tiff: libs.append(feature.tiff) From 3de19ad30537ca3abbc09ea8971f231f64f4ec3b Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Sun, 1 Sep 2024 23:32:43 +0400 Subject: [PATCH 7/7] 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 */ /* -------------------------------------------------------------------- */