-
-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove array struct support #2635
base: main
Are you sure you want to change the base?
Remove array struct support #2635
Conversation
95c914b
to
c05426b
Compare
@@ -485,7 +485,7 @@ typedef enum { | |||
#define PYGAMEAPI_PIXELARRAY_NUMSLOTS 2 | |||
#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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a bad breaking change?
@@ -2281,7 +1753,7 @@ MODINIT_DEFINE(base) | |||
c_api[11] = pg_mod_autoquit; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I don't understand the C API, but this looks wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this test gone? It looks to be related to the buffer interface not the array struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall.
I don't think anyone will miss any of this array stuff as it looks like it never gets used anymore.
Fixes #1497, fixes #405