From f330955043cbe2b690bef33943ac035bf25155b5 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 25 Aug 2011 23:43:02 +0000 Subject: [PATCH] Update siplib to version 4.12.4 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@68904 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- sip/siplib/LICENSE | 2 +- sip/siplib/apiversions.c | 2 +- sip/siplib/bool.cpp | 2 +- sip/siplib/descriptors.c | 2 +- sip/siplib/objmap.c | 2 +- sip/siplib/qtlib.c | 2 +- sip/siplib/sip.h | 12 ++- sip/siplib/sipint.h | 2 +- sip/siplib/siplib.c | 153 ++++++++++++++++++++++++++------------- sip/siplib/threads.c | 2 +- sip/siplib/voidptr.c | 6 +- 11 files changed, 120 insertions(+), 67 deletions(-) diff --git a/sip/siplib/LICENSE b/sip/siplib/LICENSE index b2570095..32120bfc 100644 --- a/sip/siplib/LICENSE +++ b/sip/siplib/LICENSE @@ -12,7 +12,7 @@ hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use SIP alone or in any derivative version, provided, however, that Riverbank's License Agreement and Riverbank's notice of -copyright, e.g., "Copyright (c) 2010 Riverbank Computing Limited; All Rights +copyright, e.g., "Copyright (c) 2011 Riverbank Computing Limited; All Rights Reserved" are retained in SIP alone or in any derivative version prepared by Licensee. diff --git a/sip/siplib/apiversions.c b/sip/siplib/apiversions.c index 7d86c769..159d6f26 100644 --- a/sip/siplib/apiversions.c +++ b/sip/siplib/apiversions.c @@ -1,7 +1,7 @@ /* * The implementation of the supprt for setting API versions. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * diff --git a/sip/siplib/bool.cpp b/sip/siplib/bool.cpp index 910ef0ba..d2454a80 100644 --- a/sip/siplib/bool.cpp +++ b/sip/siplib/bool.cpp @@ -1,6 +1,6 @@ // This contains all the C++ code that is needed by the sip module. // -// Copyright (c) 2010 Riverbank Computing Limited +// Copyright (c) 2011 Riverbank Computing Limited // // This file is part of SIP. // diff --git a/sip/siplib/descriptors.c b/sip/siplib/descriptors.c index 0cc3d86c..16a05b81 100644 --- a/sip/siplib/descriptors.c +++ b/sip/siplib/descriptors.c @@ -1,7 +1,7 @@ /* * The implementation of the different descriptors. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * diff --git a/sip/siplib/objmap.c b/sip/siplib/objmap.c index 785b58ec..1dc49197 100644 --- a/sip/siplib/objmap.c +++ b/sip/siplib/objmap.c @@ -2,7 +2,7 @@ * This module implements a hash table class for mapping C/C++ addresses to the * corresponding wrapped Python object. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * diff --git a/sip/siplib/qtlib.c b/sip/siplib/qtlib.c index 8e6b761c..b7c03d3e 100644 --- a/sip/siplib/qtlib.c +++ b/sip/siplib/qtlib.c @@ -2,7 +2,7 @@ * The SIP library code that implements the interface to the optional module * supplied Qt support. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * diff --git a/sip/siplib/sip.h b/sip/siplib/sip.h index ae26a315..23fd80ee 100644 --- a/sip/siplib/sip.h +++ b/sip/siplib/sip.h @@ -1,7 +1,7 @@ /* * The SIP module interface. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * @@ -54,8 +54,8 @@ extern "C" { /* * Define the SIP version number. */ -#define SIP_VERSION 0x040c01 -#define SIP_VERSION_STR "4.12.1-snapshot-baf837919f74" +#define SIP_VERSION 0x040c04 +#define SIP_VERSION_STR "4.12.4" /* @@ -1553,9 +1553,13 @@ typedef struct _sipQtAPI { #define sipIsExactWrappedType(wt) (sipTypeAsPyTypeObject((wt)->type) == (PyTypeObject *)(wt)) -#define sipConvertFromSliceObject(o,len,start,stop,step,slen) \ +#if PY_VERSION_HEX >= 0x03020000 +#define sipConvertFromSliceObject PySlice_GetIndicesEx +#else +#define sipConvertFromSliceObject(o, len, start, stop, step, slen) \ PySlice_GetIndicesEx((PySliceObject *)(o), (len), (start), (stop), \ (step), (slen)) +#endif /* diff --git a/sip/siplib/sipint.h b/sip/siplib/sipint.h index 3091924b..4aa6e972 100644 --- a/sip/siplib/sipint.h +++ b/sip/siplib/sipint.h @@ -1,7 +1,7 @@ /* * This file defines the SIP library internal interfaces. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * diff --git a/sip/siplib/siplib.c b/sip/siplib/siplib.c index 8419d137..17e66dca 100644 --- a/sip/siplib/siplib.c +++ b/sip/siplib/siplib.c @@ -1,7 +1,7 @@ /* * SIP library code. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * @@ -2478,9 +2478,9 @@ static int sip_api_parse_result(int *isErr, PyObject *method, PyObject *res, case 'o': { #if defined(HAVE_LONG_LONG) - unsigned PY_LONG_LONG v = PyLong_AsUnsignedLongLong(arg); + unsigned PY_LONG_LONG v = PyLong_AsUnsignedLongLongMask(arg); #else - unsigned long v = PyLong_AsUnsignedLong(arg); + unsigned long v = PyLong_AsUnsignedLongMask(arg); #endif if (PyErr_Occurred()) @@ -2767,6 +2767,12 @@ static unsigned long sip_api_long_as_unsigned_long(PyObject *o) { long v = PyInt_AsLong(o); + /* + * Strictly speaking this should be changed to be consistent with the + * use of PyLong_AsUnsignedLongMask(). However as it's such an old + * version of Python we choose to leave it as it is. + */ + if (v < 0) { PyErr_SetString(PyExc_OverflowError, @@ -2779,7 +2785,13 @@ static unsigned long sip_api_long_as_unsigned_long(PyObject *o) } #endif - return PyLong_AsUnsignedLong(o); + /* + * Note that we now ignore any overflow so that (for example) a negative + * integer will be converted to an unsigned as C/C++ would do. We don't + * bother to check for overflow when converting to small C/C++ types (short + * etc.) so at least this is consistent. + */ + return PyLong_AsUnsignedLongMask(o); } @@ -2811,9 +2823,18 @@ static int sip_api_parse_kwd_args(PyObject **parseErrp, PyObject *sipArgs, int ok; va_list va; - /* Initialise the return of any unused keyword arguments. */ if (unused != NULL) + { + /* Initialise the return of any unused keyword arguments. */ *unused = NULL; + } + else if (sipKwdArgs != NULL && kwdlist == NULL) + { + /* __init__ methods avoid the normal Python checks. */ + PyErr_SetString(PyExc_TypeError, + "keyword arguments are not supported"); + return FALSE; + } va_start(va, fmt); ok = parseKwdArgs(parseErrp, sipArgs, sipKwdArgs, kwdlist, unused, fmt, @@ -4298,9 +4319,9 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (arg != NULL) { #if defined(HAVE_LONG_LONG) - unsigned PY_LONG_LONG v = PyLong_AsUnsignedLongLong(arg); + unsigned PY_LONG_LONG v = PyLong_AsUnsignedLongLongMask(arg); #else - unsigned long v = PyLong_AsUnsignedLong(arg); + unsigned long v = PyLong_AsUnsignedLongMask(arg); #endif if (PyErr_Occurred()) @@ -6755,11 +6776,11 @@ static PyObject *detail_FromFailure(PyObject *failure_obj) { #if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromFormat( - "keyword argument '%s' has unexpected type '%s'", + "argument '%s' has unexpected type '%s'", failure->arg_name, Py_TYPE(failure->detail_obj)->tp_name); #else detail = PyString_FromFormat( - "keyword argument '%s' has unexpected type '%s'", + "argument '%s' has unexpected type '%s'", failure->arg_name, Py_TYPE(failure->detail_obj)->tp_name); #endif } @@ -7580,65 +7601,75 @@ static PyObject *sip_api_is_py_method(sip_gilstate_t *gil, char *pymc, for (i = 0; i < PyTuple_GET_SIZE(mro); ++i) { - PyObject *cls_dict; + PyObject *cls_dict, *cls_attr; cls = PyTuple_GET_ITEM(mro, i); #if PY_MAJOR_VERSION >= 3 cls_dict = ((PyTypeObject *)cls)->tp_dict; #else - // Allow for classic classes as mixins. + /* Allow for classic classes as mixins. */ if (PyClass_Check(cls)) cls_dict = ((PyClassObject *)cls)->cl_dict; else cls_dict = ((PyTypeObject *)cls)->tp_dict; #endif - if (cls_dict != NULL && (reimp = PyDict_GetItem(cls_dict, mname_obj)) != NULL) + /* + * Check any possible reimplementation is not the wrapped C++ method or + * a default special method implementation.. + */ + if (cls_dict != NULL && (cls_attr = PyDict_GetItem(cls_dict, mname_obj)) != NULL && Py_TYPE(cls_attr) != &sipMethodDescr_Type && Py_TYPE(cls_attr) != &PyWrapperDescr_Type) { - /* - * Check any reimplementation is Python code and is not the wrapped - * C++ method. - */ - if (PyMethod_Check(reimp)) - { - /* It's already a method but make sure it is bound. */ - if (PyMethod_GET_SELF(reimp) != NULL) - { - Py_INCREF(reimp); - } - else - { -#if PY_MAJOR_VERSION >= 3 - reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp), - (PyObject *)sipSelf); -#else - reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp), - (PyObject *)sipSelf, PyMethod_GET_CLASS(reimp)); -#endif - } - - break; - } - - if (PyFunction_Check(reimp)) - { -#if PY_MAJOR_VERSION >= 3 - reimp = PyMethod_New(reimp, (PyObject *)sipSelf); -#else - reimp = PyMethod_New(reimp, (PyObject *)sipSelf, cls); -#endif - - break; - } - - reimp = NULL; + reimp = cls_attr; + break; } } Py_DECREF(mname_obj); - if (reimp == NULL) + if (reimp != NULL) + { + /* + * Emulate the behaviour of a descriptor to make sure we return a bound + * method. + */ + if (PyMethod_Check(reimp)) + { + /* It's already a method but make sure it is bound. */ + if (PyMethod_GET_SELF(reimp) != NULL) + { + Py_INCREF(reimp); + } + else + { +#if PY_MAJOR_VERSION >= 3 + reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp), + (PyObject *)sipSelf); +#else + reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp), + (PyObject *)sipSelf, PyMethod_GET_CLASS(reimp)); +#endif + } + } + else if (PyFunction_Check(reimp)) + { +#if PY_MAJOR_VERSION >= 3 + reimp = PyMethod_New(reimp, (PyObject *)sipSelf); +#else + reimp = PyMethod_New(reimp, (PyObject *)sipSelf, cls); +#endif + } + else + { + /* + * We don't know what it is so just return and assume that an + * appropriate exception will be raised later on. + */ + Py_INCREF(reimp); + } + } + else { /* Use the fast track in future. */ *pymc = 1; @@ -8299,9 +8330,15 @@ static void sip_api_call_hook(const char *hookname) if ((dictofmods = PyImport_GetModuleDict()) == NULL) return; +#if PY_MAJOR_VERSION >= 3 + /* Get the builtins module. */ + if ((mod = PyDict_GetItemString(dictofmods, "builtins")) == NULL) + return; +#else /* Get the __builtin__ module. */ if ((mod = PyDict_GetItemString(dictofmods, "__builtin__")) == NULL) return; +#endif /* Get it's dictionary. */ if ((dict = PyModule_GetDict(mod)) == NULL) @@ -9192,9 +9229,9 @@ static void sipSimpleWrapper_releasebuffer(sipSimpleWrapper *self, const sipClassTypeDef *ctd; if ((ptr = getPtrTypeDef(self, &ctd)) == NULL) - return -1; + return; - return ctd->ctd_releasebuffer((PyObject *)self, ptr, buf); + ctd->ctd_releasebuffer((PyObject *)self, ptr, buf); } #endif @@ -10662,7 +10699,11 @@ static int convertToWCharArray(PyObject *obj, wchar_t **ap, SIP_SSIZE_T *aszp) if ((wc = sip_api_malloc(ulen * sizeof (wchar_t))) == NULL) return -1; +#if PY_VERSION_HEX >= 0x03020000 + ulen = PyUnicode_AsWideChar(obj, wc, ulen); +#else ulen = PyUnicode_AsWideChar((PyUnicodeObject *)obj, wc, ulen); +#endif if (ulen < 0) { @@ -10713,7 +10754,11 @@ static int convertToWChar(PyObject *obj, wchar_t *ap) if (PyUnicode_GET_SIZE(obj) != 1) return -1; +#if PY_VERSION_HEX >= 0x03020000 + if (PyUnicode_AsWideChar(obj, ap, 1) != 1) +#else if (PyUnicode_AsWideChar((PyUnicodeObject *)obj, ap, 1) != 1) +#endif return -1; return 0; @@ -10769,7 +10814,11 @@ static int convertToWCharString(PyObject *obj, wchar_t **ap) if ((wc = sip_api_malloc((ulen + 1) * sizeof (wchar_t))) == NULL) return -1; +#if PY_VERSION_HEX >= 0x03020000 + ulen = PyUnicode_AsWideChar(obj, wc, ulen); +#else ulen = PyUnicode_AsWideChar((PyUnicodeObject *)obj, wc, ulen); +#endif if (ulen < 0) { diff --git a/sip/siplib/threads.c b/sip/siplib/threads.c index 0854a0ae..acd89328 100644 --- a/sip/siplib/threads.c +++ b/sip/siplib/threads.c @@ -3,7 +3,7 @@ * C++ classes that provide a thread interface to interact properly with the * Python threading infrastructure. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * diff --git a/sip/siplib/voidptr.c b/sip/siplib/voidptr.c index c5f24833..e0bf09d0 100644 --- a/sip/siplib/voidptr.c +++ b/sip/siplib/voidptr.c @@ -1,7 +1,7 @@ /* * SIP library code. * - * Copyright (c) 2010 Riverbank Computing Limited + * Copyright (c) 2011 Riverbank Computing Limited * * This file is part of SIP. * @@ -429,7 +429,7 @@ static PyObject *sipVoidPtr_subscript(PyObject *self, PyObject *key) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx((PySliceObject *)key, v->size, &start, &stop, &step, &slicelength) < 0) + if (sipConvertFromSliceObject(key, v->size, &start, &stop, &step, &slicelength) < 0) return NULL; if (step != 1) @@ -486,7 +486,7 @@ static int sipVoidPtr_ass_subscript(PyObject *self, PyObject *key, { Py_ssize_t stop, step; - if (PySlice_GetIndicesEx((PySliceObject *)key, v->size, &start, &stop, &step, &size) < 0) + if (sipConvertFromSliceObject(key, v->size, &start, &stop, &step, &size) < 0) return -1; if (step != 1)