mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Bug 1015: Define and use Py_ssize_t.
This commit is contained in:
parent
5e4a565603
commit
a833d6d093
1
NEWS
1
NEWS
@ -225,6 +225,7 @@ have already been considered.
|
||||
not sorted
|
||||
- (bugfix 968) assertion width > 0 failed in copy_chars called from
|
||||
justify_line
|
||||
- bug 1015: incompatible pointer type for PyString_AsStringAndSize
|
||||
* Already backported to a previous release but not listed there:
|
||||
- (enhancement) Activate link only when onClick returns true.
|
||||
Fixed bug 786 in ELinks 0.11.2.
|
||||
|
@ -6,6 +6,19 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
/* PyString_AsStringAndSize() takes a Py_ssize_t * in Python 2.5 but
|
||||
* an int * in Python 2.4. To be compatible with both, ELinks uses
|
||||
* Py_ssize_t and defines it here if necessary. The public-domain
|
||||
* PEP 353 <http://www.python.org/dev/peps/pep-0353/> suggests the
|
||||
* following snippet, so we can use the Py_ssize_t name even though
|
||||
* Python generally reserves names starting with "Py_". */
|
||||
#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
|
||||
/* End of PEP 353 snippet. */
|
||||
|
||||
struct module;
|
||||
|
||||
extern struct session *python_ses;
|
||||
|
@ -103,11 +103,16 @@ script_hook_pre_format_html(va_list ap, void *data)
|
||||
|
||||
if (result != Py_None) {
|
||||
unsigned char *str;
|
||||
int len;
|
||||
Py_ssize_t len;
|
||||
|
||||
if (PyString_AsStringAndSize(result, (char **) &str, &len) != 0)
|
||||
goto error;
|
||||
|
||||
/* This assumes the Py_ssize_t len is not too large to
|
||||
* fit in the off_t parameter of normalize_cache_entry().
|
||||
* add_fragment() itself seems to assume the same thing,
|
||||
* and there is no standard OFF_MAX macro against which
|
||||
* ELinks could check the value. */
|
||||
(void) add_fragment(cached, 0, str, len);
|
||||
normalize_cache_entry(cached, len);
|
||||
}
|
||||
|
@ -79,7 +79,8 @@ python_menu(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyObject *items;
|
||||
enum python_menu_type menu_type = PYTHON_MENU_DEFAULT;
|
||||
int length, i;
|
||||
Py_ssize_t length;
|
||||
int i;
|
||||
struct menu_item *menu;
|
||||
struct memory_list *ml = NULL;
|
||||
static char *kwlist[] = {"items", "type", NULL};
|
||||
@ -104,7 +105,7 @@ python_menu(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
return NULL;
|
||||
}
|
||||
length = PySequence_Length(items);
|
||||
if (length == -1) return NULL;
|
||||
if (length == -1 || length > INT_MAX) return NULL;
|
||||
else if (length == 0) goto success;
|
||||
|
||||
if (menu_type < 0 || menu_type >= PYTHON_MENU_MAX) {
|
||||
|
Loading…
Reference in New Issue
Block a user