Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion buildconfig/stubs/pygame/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ from .base import (
BufferError as BufferError,
HAVE_NEWBUF as HAVE_NEWBUF,
error as error,
get_array_interface as get_array_interface,
get_error as get_error,
get_init as get_init,
get_sdl_byteorder as get_sdl_byteorder,
Expand Down
3 changes: 0 additions & 3 deletions buildconfig/stubs/pygame/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ def set_error(error_msg: str, /) -> None: ...
def get_sdl_version(linked: bool = True) -> Tuple[int, int, int]: ...
def get_sdl_byteorder() -> int: ...
def register_quit(callable: Callable[[], Any], /) -> None: ...

# undocumented part of pygame API, kept here to make stubtest happy
def get_array_interface(arg: Any, /) -> dict: ...
3 changes: 0 additions & 3 deletions buildconfig/stubs/pygame/bufferproxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ class BufferProxy:
parent: Any
length: int
raw: bytes
# possibly going to be deprecated/removed soon, in which case these
# typestubs must be removed too
__array_interface__: Dict[str, Any]
__array_struct__: Any
@overload
def __init__(self) -> None: ...
@overload
Expand Down
1 change: 0 additions & 1 deletion buildconfig/stubs/pygame/color.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Color(Collection[int]):
hsla: Tuple[float, float, float, float]
i1i2i3: Tuple[float, float, float]
__hash__: None # type: ignore
__array_struct__: Any
@overload
def __init__(self, r: int, g: int, b: int, a: int = 255) -> None: ...
@overload
Expand Down
4 changes: 0 additions & 4 deletions buildconfig/stubs/pygame/mixer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ class Sound:
maxtime: int = 0,
fade_ms: int = 0,
) -> Channel: ...
# possibly going to be deprecated/removed soon, in which case these
# typestubs must be removed too
__array_interface__: Dict[str, Any]
__array_struct__: Any
def stop(self) -> None: ...
def fadeout(self, time: int, /) -> None: ...
def set_volume(self, value: float, /) -> None: ...
Expand All @@ -70,7 +67,6 @@ class Sound:
def get_length(self) -> float: ...
def get_raw(self) -> bytes: ...


class Channel:
def __init__(self, id: int) -> None: ...
@property
Expand Down
3 changes: 0 additions & 3 deletions buildconfig/stubs/pygame/pixelarray.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class PixelArray:
ndim: int
shape: Tuple[int, ...]
strides: Tuple[int, ...]
# possibly going to be deprecated/removed soon, in which case these
# typestubs must be removed too
__array_interface__: Dict[str, Any]
__array_struct__: Any
def __init__(self, surface: Surface) -> None: ...
def __enter__(self) -> PixelArray: ...
def __exit__(self, *args, **kwargs) -> None: ...
Expand Down
11 changes: 3 additions & 8 deletions docs/reST/c_api/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,14 @@ C header: src_c/include/pygame.h
Return a Python array interface object representation of buffer *view_p*.
On failure raise a Python exception and return *NULL*.

.. c:function:: PyObject* pgBuffer_AsArrayStruct(Py_buffer *view_p)

Return a Python array struct object representation of buffer *view_p*.
On failure raise a Python exception and return *NULL*.

.. c:function:: int pgObject_GetBuffer(PyObject *obj, pg_buffer *pg_view_p, int flags)

Request a buffer for object *obj*.
Argument *flags* are PyBUF options.
Return the buffer description in *pg_view_p*.
An object may support the Python buffer interface, the NumPy array interface,
or the NumPy array struct interface.
Return ``0`` on success, raise a Python exception and return ``-1`` on failure.
An object may support the Python buffer interface or the NumPy python
object array interface. Return ``0`` on success, raise a Python exception
and return ``-1`` on failure.

.. c:function:: void pgBuffer_Release(Pg_buffer *pg_view_p)

Expand Down
2 changes: 1 addition & 1 deletion docs/reST/ref/freetype.rst
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ loaded. This module must be imported explicitly to be used. ::
| :sl:`Render text into an array of ints`
| :sg:`render_raw_to(array, text, dest=None, style=STYLE_DEFAULT, rotation=0, size=0, invert=False) -> Rect`

Render to an array object exposing an array struct interface. The array
Render to an array object exposing the buffer protocol. The array
must be two dimensional with integer items. The default *dest* value,
``None``, is equivalent to position (0, 0). See :meth:`render_to`.
As with the other render methods, *text* can be ``None`` to
Expand Down
8 changes: 5 additions & 3 deletions docs/reST/ref/pixelarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
for assignment. A pixel array sliced on a single column or row
returns a one dimensional pixel array. Arithmetic and other operations
are not supported. A pixel array can be safely assigned to itself.
Finally, pixel arrays export an array struct interface, allowing
them to interact with :mod:`pygame.pixelcopy` methods and NumPy
arrays.
Finally, pixel arrays export the buffer protocol as well as the python
array interface, allowing them to interact with :mod:`pygame.pixelcopy`
methods and NumPy arrays.

A PixelArray pixel item can be assigned a raw integer values, a
:class:`pygame.Color` instance, or a (r, g, b[, a]) tuple.
Expand Down Expand Up @@ -100,6 +100,8 @@
copying is implemented it is suggested PixelArray to PixelArray copies be
only between surfaces of identical format.

.. versionchanged:: 2.5.0 Removed array struct support

.. versionaddedold:: 1.9.4

- close() method was added. For explicitly cleaning up.
Expand Down
17 changes: 6 additions & 11 deletions docs/reST/ref/pixelcopy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@
| :sl:`pygame module for general pixel array copying`

The ``pygame.pixelcopy`` module contains functions for copying between
surfaces and objects exporting an array structure interface. It is a backend
for :mod:`pygame.surfarray`, adding NumPy support. But pixelcopy is more
general, and intended for direct use.

The array struct interface exposes an array's data in a standard way.
It was introduced in NumPy. In Python 2.7 and above it is replaced by the
new buffer protocol, though the buffer protocol is still a work in progress.
The array struct interface, on the other hand, is stable and works with earlier
Python versions. So for now the array struct interface is the predominate way
pygame handles array introspection.
surfaces and objects exporting the buffer protocol or the python array
interface. It is a backend for :mod:`pygame.surfarray`, which adds NumPy
support. But pixelcopy is more general, and intended for direct use.

For 2d arrays of integer pixel values, the values are mapped to the
pixel format of the related surface. To get the actual color of a pixel
value use :meth:`pygame.Surface.unmap_rgb`. 2d arrays can only be used
directly between surfaces having the same pixel layout.

New in pygame 1.9.2.
.. versionchanged:: 2.5.0 Removed array struct support

.. versionaddedold:: 1.9.2

.. function:: surface_to_array

Expand Down
3 changes: 1 addition & 2 deletions docs/reST/ref/surface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,7 @@
| :sg:`get_view(kind='2', /) -> BufferProxy`

Return an object which exports a surface's internal pixel buffer as
a C level array struct, Python level array interface or a C level
buffer interface. The new buffer protocol is supported.
a Python level array interface or a C level buffer interface.

The kind argument is the length 1 string '0', '1', '2', '3',
'r', 'g', 'b', or 'a'. The letters are case insensitive;
Expand Down
5 changes: 3 additions & 2 deletions docs/reST/ref/surfarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ will be locked during the lifetime of the array.

Create a new Surface that best resembles the data and format on the array.
The array can be 2D or 3D with any sized integer values. Function
make_surface uses the array struct interface to acquire array properties,
make_surface uses the buffer protocol to acquire array properties,
so is not limited to just NumPy arrays. See :mod:`pygame.pixelcopy`.

New in pygame 1.9.2: array struct interface support.
.. versionchanged:: 2.5.0 Removed array struct interface support.
.. versionaddedold:: 1.9.2 array struct interface support.

.. ## pygame.surfarray.make_surface ##

Expand Down
2 changes: 1 addition & 1 deletion src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,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
Copy link
Contributor

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?

#define PYGAMEAPI_EVENT_NUMSLOTS 8
#define PYGAMEAPI_WINDOW_NUMSLOTS 1
#define PYGAMEAPI_GEOMETRY_NUMSLOTS 1
Expand Down
Loading
Loading