The Samba-Bugzilla – Attachment 14774 Details for
Bug 13748
pytalloc's tp_compare/tp_richcompare functions should return only -1, 0 or 1
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch: use a wrapper function to limit the returned value
cmp.diff (text/plain), 1.70 KB, created by
Adam Sampson
on 2019-01-16 11:33:25 UTC
(
hide
)
Description:
Patch: use a wrapper function to limit the returned value
Filename:
MIME Type:
Creator:
Adam Sampson
Created:
2019-01-16 11:33:25 UTC
Size:
1.70 KB
patch
obsolete
>Python tp_compare functions must return -1, 0 or 1. > >In addition, the original code assumes that the difference of two >pointers fits into an int, which isn't true on all platforms. > >diff -x config.log -x config.status -ru tmp/talloc-2.1.6/pytalloc.c work/talloc-2.1.6/pytalloc.c >--- tmp/talloc-2.1.6/pytalloc.c 2016-03-08 13:37:39.000000000 +0000 >+++ work/talloc-2.1.6/pytalloc.c 2016-03-09 13:18:36.382047572 +0000 >@@ -17,6 +17,7 @@ > along with this program. If not, see <http://www.gnu.org/licenses/>. > */ > >+#include <stddef.h> > #include <Python.h> > #include <talloc.h> > #include <pytalloc.h> >@@ -133,14 +134,23 @@ > return Py_NotImplemented; > } > #else >+static int signof(ptrdiff_t val) >+{ >+ if (val == 0) >+ return 0; >+ else if (val < 0) >+ return -1; >+ else >+ return 1; >+} > static int pytalloc_default_cmp(PyObject *_obj1, PyObject *_obj2) > { > pytalloc_Object *obj1 = (pytalloc_Object *)_obj1, > *obj2 = (pytalloc_Object *)_obj2; > if (obj1->ob_type != obj2->ob_type) >- return ((char *)obj1->ob_type - (char *)obj2->ob_type); >+ return signof((char *)obj1->ob_type - (char *)obj2->ob_type); > >- return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2)); >+ return signof((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2)); > } > #endif > >@@ -218,9 +228,9 @@ > pytalloc_BaseObject *obj1 = (pytalloc_BaseObject *)_obj1, > *obj2 = (pytalloc_BaseObject *)_obj2; > if (obj1->ob_type != obj2->ob_type) >- return ((char *)obj1->ob_type - (char *)obj2->ob_type); >+ return signof((char *)obj1->ob_type - (char *)obj2->ob_type); > >- return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2)); >+ return signof((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2)); > } > #endif >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 13748
: 14774