Skip to content

Commit

Permalink
Merge pull request #5194 from radarhere/python310
Browse files Browse the repository at this point in the history
PyModule_AddObject fix for Python 3.10
  • Loading branch information
radarhere authored Jan 12, 2021
2 parents 2ffbd5f + f9c2834 commit 543fa2c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test_script:
- cd c:\pillow
- '%PYTHON%\%EXECUTABLE% -m pip install pytest pytest-cov'
- c:\"Program Files (x86)"\"Windows Kits"\10\Debuggers\x86\gflags.exe /p /enable %PYTHON%\%EXECUTABLE%
- '%PYTHON%\%EXECUTABLE% -c "from PIL import Image"'
- '%PYTHON%\%EXECUTABLE% -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests'
#- '%PYTHON%\%EXECUTABLE% test-installed.py -v -s %TEST_OPTIONS%' TODO TEST_OPTIONS with pytest?

Expand Down
2 changes: 2 additions & 0 deletions .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

set -e

python3 -c "from PIL import Image"

python3 -bb -m pytest -v -x -W always --cov PIL --cov Tests --cov-report term Tests
1 change: 1 addition & 0 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ jobs:
- name: Test Pillow
run: |
python3 selftest.py --installed
python3 -c "from PIL import Image"
python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
- name: Upload coverage
Expand Down
21 changes: 15 additions & 6 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -4134,28 +4134,34 @@ setup_module(PyObject *m) {
}
#endif

PyObject *have_libjpegturbo;
#ifdef LIBJPEG_TURBO_VERSION
PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", Py_True);
have_libjpegturbo = Py_True;
#define tostr1(a) #a
#define tostr(a) tostr1(a)
PyDict_SetItemString(
d, "libjpeg_turbo_version", PyUnicode_FromString(tostr(LIBJPEG_TURBO_VERSION)));
#undef tostr
#undef tostr1
#else
PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", Py_False);
have_libjpegturbo = Py_False;
#endif
Py_INCREF(have_libjpegturbo);
PyModule_AddObject(m, "HAVE_LIBJPEGTURBO", have_libjpegturbo);

PyObject *have_libimagequant;
#ifdef HAVE_LIBIMAGEQUANT
PyModule_AddObject(m, "HAVE_LIBIMAGEQUANT", Py_True);
have_libimagequant = Py_True;
{
extern const char *ImagingImageQuantVersion(void);
PyDict_SetItemString(
d, "imagequant_version", PyUnicode_FromString(ImagingImageQuantVersion()));
}
#else
PyModule_AddObject(m, "HAVE_LIBIMAGEQUANT", Py_False);
have_libimagequant = Py_False;
#endif
Py_INCREF(have_libimagequant);
PyModule_AddObject(m, "HAVE_LIBIMAGEQUANT", have_libimagequant);

#ifdef HAVE_LIBZ
/* zip encoding strategies */
Expand Down Expand Up @@ -4189,11 +4195,14 @@ setup_module(PyObject *m) {
}
#endif

PyObject *have_xcb;
#ifdef HAVE_XCB
PyModule_AddObject(m, "HAVE_XCB", Py_True);
have_xcb = Py_True;
#else
PyModule_AddObject(m, "HAVE_XCB", Py_False);
have_xcb = Py_False;
#endif
Py_INCREF(have_xcb);
PyModule_AddObject(m, "HAVE_XCB", have_xcb);

PyDict_SetItemString(d, "PILLOW_VERSION", PyUnicode_FromString(version));

Expand Down
14 changes: 10 additions & 4 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,20 +920,26 @@ static PyMethodDef webpMethods[] = {

void
addMuxFlagToModule(PyObject *m) {
PyObject *have_webpmux;
#ifdef HAVE_WEBPMUX
PyModule_AddObject(m, "HAVE_WEBPMUX", Py_True);
have_webpmux = Py_True;
#else
PyModule_AddObject(m, "HAVE_WEBPMUX", Py_False);
have_webpmux = Py_False;
#endif
Py_INCREF(have_webpmux);
PyModule_AddObject(m, "HAVE_WEBPMUX", have_webpmux);
}

void
addAnimFlagToModule(PyObject *m) {
PyObject *have_webpanim;
#ifdef HAVE_WEBPANIM
PyModule_AddObject(m, "HAVE_WEBPANIM", Py_True);
have_webpanim = Py_True;
#else
PyModule_AddObject(m, "HAVE_WEBPANIM", Py_False);
have_webpanim = Py_False;
#endif
Py_INCREF(have_webpanim);
PyModule_AddObject(m, "HAVE_WEBPANIM", have_webpanim);
}

void
Expand Down

0 comments on commit 543fa2c

Please sign in to comment.