Y Giridhar Appaji Nag <[EMAIL PROTECTED]> writes:

> In Python 2.5, PyString_AsStringAndSize takes Py_ssize_t* instead of int* as
> its last argument.  This causes ELinks 0.12 build failures on 64bit archs if
> Python 2.5 is used for building the Python hooks.

Does ELinks 0.11 also fail to build?  Does it work correctly?

The Python scripting module is marked as experimental, so build
failures caused by it might not have to be fixed in the stable
elinks-0.11 branch.  OTOH, if it builds but corrupts memory at
runtime, that's more serious.

> I understand that the way to fix this sort of a thing in ELinks is to define a
> new type (say Py_ssize_t_T) that maps to the right thing.  What would be the
> best place to do it? src/osdep/types.h doesn't look to the right place because
> I will have to include Python.h (and hence python patchlevel.h) and define
> Py_ssize_t_T conditionally depending on PY_VERSION_HEX.
>
> Or do you suggest that I just fix this in src/scripting/python/hooks.c where
> PyString_AsStringAndSize is used? i.e. cast the third argument conditionally
> or declare len conditionally there.

I think we should copy this code snippet from the public-domain
PEP 353 <http://www.python.org/dev/peps/pep-0353/>:

#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif

into src/scripting/python/core.h, with a comment saying where it
came from.  Then also change python_menu() to use Py_ssize_t for
the result of PySequence_Length(items) and return NULL if length
exceeds INT_MAX.  That and script_hook_pre_format_html() are the
only relevant uses of int in /src/scripting/python/, I think.

If we used an ELinks-specific name for the type, I think it ought
not to begin with "Py_".  But the Python people appear to condone
defining Py_ssize_t outside the Python core so we can as well use
that name.

Instead of checking PY_VERSION_HEX, we could make the configure
script check whether Py_ssize_t is defined.  However, that would
require more code and would probably slow down the build a bit.

Attachment: pgpy3HQ0cmIGp.pgp
Description: PGP signature

_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev

Reply via email to