|
|
50a37d |
From e705cd1476f04a918aae34f638b502116cb12eba Mon Sep 17 00:00:00 2001
|
|
|
50a37d |
From: Jon Dufresne <jon.dufresne@gmail.com>
|
|
|
50a37d |
Date: Tue, 3 Apr 2018 20:36:09 -0700
|
|
|
50a37d |
Subject: [PATCH] Fix dereferencing type-punned pointer will break
|
|
|
50a37d |
strict-aliasing
|
|
|
50a37d |
|
|
|
50a37d |
Compiler warning appeared as:
|
|
|
50a37d |
|
|
|
50a37d |
src/path.c:574:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
|
|
|
50a37d |
Py_TYPE(&item)->tp_name);
|
|
|
50a37d |
^~~~~~~
|
|
|
50a37d |
|
|
|
50a37d |
As item is already of type PyObject*, and the Py_TYPE macro is
|
|
|
50a37d |
equivalent to (((PyObject*)(o))->ob_type), no need for the dereference.
|
|
|
50a37d |
|
|
|
50a37d |
https://docs.python.org/3/c-api/structures.html#c.Py_TYPE
|
|
|
50a37d |
---
|
|
|
50a37d |
Tests/test_imagepath.py | 5 +++++
|
|
|
50a37d |
src/path.c | 2 +-
|
|
|
50a37d |
2 files changed, 6 insertions(+), 1 deletion(-)
|
|
|
50a37d |
|
|
|
50a37d |
diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py
|
|
|
50a37d |
index 14cc4d14b..98a6d3416 100644
|
|
|
50a37d |
--- a/Tests/test_imagepath.py
|
|
|
50a37d |
+++ b/Tests/test_imagepath.py
|
|
|
50a37d |
@@ -17,6 +17,11 @@ def test_path(self):
|
|
|
50a37d |
self.assertEqual(p[0], (0.0, 1.0))
|
|
|
50a37d |
self.assertEqual(p[-1], (8.0, 9.0))
|
|
|
50a37d |
self.assertEqual(list(p[:1]), [(0.0, 1.0)])
|
|
|
50a37d |
+ with self.assertRaises(TypeError) as cm:
|
|
|
50a37d |
+ p['foo']
|
|
|
50a37d |
+ self.assertEqual(
|
|
|
50a37d |
+ str(cm.exception),
|
|
|
50a37d |
+ "Path indices must be integers, not str")
|
|
|
50a37d |
self.assertEqual(
|
|
|
50a37d |
list(p),
|
|
|
50a37d |
[(0.0, 1.0), (2.0, 3.0), (4.0, 5.0), (6.0, 7.0), (8.0, 9.0)])
|
|
|
50a37d |
diff --git a/src/path.c b/src/path.c
|
|
|
50a37d |
index b56ea838e..d1c18c8ed 100644
|
|
|
50a37d |
--- a/src/path.c
|
|
|
50a37d |
+++ b/src/path.c
|
|
|
50a37d |
@@ -571,7 +571,7 @@ path_subscript(PyPathObject* self, PyObject* item) {
|
|
|
50a37d |
else {
|
|
|
50a37d |
PyErr_Format(PyExc_TypeError,
|
|
|
50a37d |
"Path indices must be integers, not %.200s",
|
|
|
50a37d |
- Py_TYPE(&item)->tp_name);
|
|
|
50a37d |
+ Py_TYPE(item)->tp_name);
|
|
|
50a37d |
return NULL;
|
|
|
50a37d |
}
|
|
|
50a37d |
}
|