Remove array struct support#2635
Conversation
95c914b to
c05426b
Compare
| #define PYGAMEAPI_COLOR_NUMSLOTS 5 | ||
| #define PYGAMEAPI_MATH_NUMSLOTS 2 | ||
| #define PYGAMEAPI_BASE_NUMSLOTS 29 | ||
| #define PYGAMEAPI_BASE_NUMSLOTS 28 |
There was a problem hiding this comment.
This seems like a bad breaking change?
| c_api[12] = pg_RGBAFromObj; | ||
| c_api[13] = pgBuffer_AsArrayInterface; | ||
| c_api[14] = pgBuffer_AsArrayStruct; | ||
| c_api[14] = pg_SetDefaultConvertFormat; |
There was a problem hiding this comment.
Maybe I don't understand the C API, but this looks wrong?
There was a problem hiding this comment.
The reason this is done this way is so that I don't have to renumber all the slots. I also changed the include/_pygame.h file, so it still works. And as far as I know, we are more lenient towards C API changes than python API ones and only code that use pgBuffer_AsArrayStruct would break (which should be very few, as most if not all code should have migrated to the buffer protocol) so I removed it.
But I can also leave this as a dummy function, that just sets an exception or warning, so that there is a bit of time to migrate off of it.
c05426b to
0f5de9f
Compare
|
This PR has conflicts that need resolving |
| PAI_ARR_HAS_DESCR = 0x800 | ||
|
|
||
|
|
||
| class ArrayInterface: |
There was a problem hiding this comment.
This PR is removing a lot of tests, some removals are justified, but I wonder if this class can be, say, rewritten to use the array interface, or the new buffer interface to test that?
There was a problem hiding this comment.
I think there is already a class like this for the buffer interface called buftools.py
| @unittest.skipIf(IS_PYPY, "newbuf with ctypes") | ||
| def test_PgObject_AsBuffer_PyBUF_flags(self): | ||
| from pygame.bufferproxy import BufferProxy | ||
| import ctypes | ||
|
|
||
| is_lil_endian = pygame.get_sdl_byteorder() == pygame.LIL_ENDIAN | ||
| fsys, frev = ("<", ">") if is_lil_endian else (">", "<") | ||
| buftools = self.buftools | ||
| Importer = buftools.Importer | ||
| e = arrinter.Exporter( | ||
| (10, 2), typekind="f", itemsize=ctypes.sizeof(ctypes.c_double) | ||
| ) | ||
| a = BufferProxy(e) | ||
| b = Importer(a, buftools.PyBUF_SIMPLE) | ||
| self.assertEqual(b.ndim, 0) | ||
| self.assertTrue(b.format is None) | ||
| self.assertEqual(b.len, e.len) | ||
| self.assertEqual(b.itemsize, e.itemsize) | ||
| self.assertTrue(b.shape is None) | ||
| self.assertTrue(b.strides is None) | ||
| self.assertTrue(b.suboffsets is None) | ||
| self.assertFalse(b.readonly) | ||
| self.assertEqual(b.buf, e.data) | ||
| b = Importer(a, buftools.PyBUF_WRITABLE) | ||
| self.assertEqual(b.ndim, 0) | ||
| self.assertTrue(b.format is None) | ||
| self.assertEqual(b.len, e.len) | ||
| self.assertEqual(b.itemsize, e.itemsize) | ||
| self.assertTrue(b.shape is None) | ||
| self.assertTrue(b.strides is None) | ||
| self.assertTrue(b.suboffsets is None) | ||
| self.assertFalse(b.readonly) | ||
| self.assertEqual(b.buf, e.data) | ||
| b = Importer(a, buftools.PyBUF_ND) | ||
| self.assertEqual(b.ndim, e.nd) | ||
| self.assertTrue(b.format is None) | ||
| self.assertEqual(b.len, a.length) | ||
| self.assertEqual(b.itemsize, e.itemsize) | ||
| self.assertEqual(b.shape, e.shape) | ||
| self.assertTrue(b.strides is None) | ||
| self.assertTrue(b.suboffsets is None) | ||
| self.assertFalse(b.readonly) | ||
| self.assertEqual(b.buf, e.data) | ||
| e = arrinter.Exporter((5, 10), typekind="i", itemsize=2, strides=(24, 2)) | ||
| a = BufferProxy(e) | ||
| b = Importer(a, buftools.PyBUF_STRIDES) | ||
| self.assertEqual(b.ndim, e.nd) | ||
| self.assertTrue(b.format is None) | ||
| self.assertEqual(b.len, e.len) | ||
| self.assertEqual(b.itemsize, e.itemsize) | ||
| self.assertEqual(b.shape, e.shape) | ||
| self.assertEqual(b.strides, e.strides) | ||
| self.assertTrue(b.suboffsets is None) | ||
| self.assertFalse(b.readonly) | ||
| self.assertEqual(b.buf, e.data) | ||
| b = Importer(a, buftools.PyBUF_FULL_RO) | ||
| self.assertEqual(b.ndim, e.nd) | ||
| self.assertEqual(b.format, "=h") | ||
| self.assertEqual(b.len, e.len) | ||
| self.assertEqual(b.itemsize, e.itemsize) | ||
| self.assertEqual(b.shape, e.shape) | ||
| self.assertEqual(b.strides, e.strides) | ||
| self.assertTrue(b.suboffsets is None) | ||
| self.assertFalse(b.readonly) | ||
| self.assertEqual(b.buf, e.data) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_SIMPLE) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_WRITABLE) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_WRITABLE) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_ND) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_C_CONTIGUOUS) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_F_CONTIGUOUS) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_ANY_CONTIGUOUS) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_CONTIG) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_SIMPLE) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_ND) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_C_CONTIGUOUS) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_F_CONTIGUOUS) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_ANY_CONTIGUOUS) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_CONTIG) | ||
| e = arrinter.Exporter( | ||
| (3, 5, 10), | ||
| typekind="i", | ||
| itemsize=2, | ||
| strides=(120, 24, 2), | ||
| flags=arrinter.PAI_ALIGNED, | ||
| ) | ||
| a = BufferProxy(e) | ||
| b = Importer(a, buftools.PyBUF_FULL_RO) | ||
| self.assertEqual(b.ndim, e.nd) | ||
| self.assertEqual(b.format, frev + "h") | ||
| self.assertEqual(b.len, e.len) | ||
| self.assertEqual(b.itemsize, e.itemsize) | ||
| self.assertEqual(b.shape, e.shape) | ||
| self.assertEqual(b.strides, e.strides) | ||
| self.assertTrue(b.suboffsets is None) | ||
| self.assertTrue(b.readonly) | ||
| self.assertEqual(b.buf, e.data) | ||
| self.assertRaises(BufferError, Importer, a, buftools.PyBUF_FULL) | ||
|
|
There was a problem hiding this comment.
Why is this test gone? It looks to be related to the buffer interface not the array struct.
MyreMylar
left a comment
There was a problem hiding this comment.
LGTM overall.
I don't think anyone will miss any of this array stuff as it looks like it never gets used anymore.
|
I'll close this because this seems like too much to push through in one PR, and there's a lot of conflicts now too. I'll split this up into smaller PRs if/when I have time. |
Fixes #1497, fixes #405