Imaging as shared lib by homm · Pull Request #8340 · python-pillow/Pillow

Build with python ./setup.py develop --pillow-configuration=parallel=1.

Currently, the _imaging extension contains a batch of very useful functions and types that are not available in other extensions (such as _webp or _imagingcms). As a result, these other extensions do not utilize the useful functions from _imaging (for example, _webp is the only extension that uses ImagingSectionEnter/Leave) and do not perform any type checking. Here is a typical code example from extensions that use the Imaging type:

static PyObject *
cms_transform_apply(CmsTransformObject *self, PyObject *args) {
    Py_ssize_t idIn;
    Py_ssize_t idOut;
    Imaging im;
    Imaging imOut;

    int result;

    if (!PyArg_ParseTuple(args, "nn:apply", &idIn, &idOut)) {
        return NULL;
    }

    im = (Imaging)idIn;
    imOut = (Imaging)idOut;

    result = pyCMSdoTransform(im, imOut, self->transform);

    return Py_BuildValue("i", result);
}

So, it just converts an arbitrary Py_ssize_t to a pointer, which is not safe. What I'm trying to achieve is to use the _imaging extension as a library for other extensions. Unfortunately, as I see it, this is only possible by changing the name to lib_imaging since gcc -l always appends the lib prefix and there is no way to specify the full library name.