Skip to content

Commit

Permalink
PyModule_AddObject fix for Python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Mar 1, 2021
1 parent a0a5b7a commit 2ba5eb1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
32 changes: 21 additions & 11 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -4172,26 +4172,33 @@ setup_module(PyObject* m) {
}
#endif

PyObject *have_libjpegturbo;
#ifdef LIBJPEG_TURBO_VERSION
PyModule_AddObject(m, "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
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 @@ -4222,11 +4229,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
16 changes: 11 additions & 5 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,19 +861,25 @@ 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) {
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 addTransparencyFlagToModule(PyObject* m) {
Expand Down

0 comments on commit 2ba5eb1

Please sign in to comment.