Skip to content

Remove surflock as the module #3417

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/Setup.Android.SDL2.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ mouse src_c/mouse.c $(SDL) $(DEBUG)
rect src_c/rect.c src_c/pgcompat_rect.c $(SDL) $(DEBUG)
rwobject src_c/rwobject.c $(SDL) $(DEBUG)
surface src_c/simd_blitters_sse2.c src_c/simd_blitters_avx2.c src_c/surface.c src_c/alphablit.c src_c/surface_fill.c src_c/simd_surface_fill_avx2.c src_c/simd_surface_fill_sse2.c $(SDL) $(DEBUG)
surflock src_c/surflock.c $(SDL) $(DEBUG)
time src_c/time.c $(SDL) $(DEBUG)
joystick src_c/joystick.c $(SDL) $(DEBUG)
draw src_c/draw.c $(SDL) $(DEBUG)
Expand Down
1 change: 0 additions & 1 deletion buildconfig/Setup.Emscripten.SDL2.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ mouse src_c/void.c
pixelcopy src_c/void.c
pixelarray src_c/void.c
surface src_c/void.c
surflock src_c/void.c
rect src_c/void.c
rwobject src_c/void.c
system src_c/void.c
Expand Down
1 change: 0 additions & 1 deletion buildconfig/Setup.SDL2.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ mouse src_c/mouse.c $(SDL) $(DEBUG)
rect src_c/rect.c src_c/pgcompat_rect.c $(SDL) $(DEBUG)
rwobject src_c/rwobject.c $(SDL) $(DEBUG)
surface src_c/simd_blitters_sse2.c src_c/simd_blitters_avx2.c src_c/surface.c src_c/alphablit.c src_c/surface_fill.c src_c/simd_surface_fill_avx2.c src_c/simd_surface_fill_sse2.c $(SDL) $(DEBUG)
surflock src_c/surflock.c $(SDL) $(DEBUG)
time src_c/time.c $(SDL) $(DEBUG)
joystick src_c/joystick.c $(SDL) $(DEBUG)
draw src_c/draw.c $(SDL) $(DEBUG)
Expand Down
1 change: 0 additions & 1 deletion buildconfig/stubs/gen_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"rect",
"rwobject",
"surface",
"surflock",
"sysfont",
"_debug",
"system",
Expand Down
1 change: 0 additions & 1 deletion buildconfig/stubs/pygame/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ from . import (
rect as rect,
rwobject as rwobject,
surface as surface,
surflock as surflock,
sysfont as sysfont,
_debug as _debug,
system as system,
Expand Down
2 changes: 0 additions & 2 deletions buildconfig/stubs/pygame/surflock.pyi

This file was deleted.

1 change: 0 additions & 1 deletion docs/reST/c_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pygame C API
c_api/rect.rst
c_api/rwobject.rst
c_api/surface.rst
c_api/surflock.rst
c_api/version.rst
c_api/window.rst

Expand Down
31 changes: 31 additions & 0 deletions docs/reST/c_api/surface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,34 @@ Header file: src_c/include/pygame.h

The C version of the :py:meth:`pygame.Surface.blit` method.
Return ``1`` on success, ``0`` on an exception.

.. c:function:: void pgSurface_Prep(pgSurfaceObject *surfobj)

If *surfobj* is a subsurface, then lock the parent surface with *surfobj*
the owner of the lock.

.. c:function:: void pgSurface_Unprep(pgSurfaceObject *surfobj)

If *surfobj* is a subsurface, then release its lock on the parent surface.

.. c:function:: int pgSurface_Lock(pgSurfaceObject *surfobj)

Lock pygame surface *surfobj*, with *surfobj* owning its own lock.

.. c:function:: int pgSurface_LockBy(pgSurfaceObject *surfobj, PyObject *lockobj)

Lock pygame surface *surfobj* with Python object *lockobj* the owning
the lock.

The surface will keep a weak reference to object *lockobj*,
and eventually remove the lock on itself if *lockobj* is garbage collected.
However, it is best if *lockobj* also keep a reference to the locked surface
and call to :c:func:`pgSurface_UnLockBy` when finished with the surface.

.. c:function:: int pgSurface_UnLock(pgSurfaceObject *surfobj)

Remove the pygame surface *surfobj* object's lock on itself.

.. c:function:: int pgSurface_UnLockBy(pgSurfaceObject *surfobj, PyObject *lockobj)

Remove the lock on pygame surface *surfobj* owned by Python object *lockobj*.
47 changes: 0 additions & 47 deletions docs/reST/c_api/surflock.rst

This file was deleted.

3 changes: 1 addition & 2 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,7 @@ typedef enum {
#define PYGAMEAPI_RECT_NUMSLOTS 10
#define PYGAMEAPI_JOYSTICK_NUMSLOTS 3
#define PYGAMEAPI_DISPLAY_NUMSLOTS 2
#define PYGAMEAPI_SURFACE_NUMSLOTS 4
#define PYGAMEAPI_SURFLOCK_NUMSLOTS 6
#define PYGAMEAPI_SURFACE_NUMSLOTS 10
#define PYGAMEAPI_RWOBJECT_NUMSLOTS 5
#define PYGAMEAPI_PIXELARRAY_NUMSLOTS 2
#define PYGAMEAPI_COLOR_NUMSLOTS 5
Expand Down
40 changes: 13 additions & 27 deletions src_c/include/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,44 +340,32 @@ typedef struct {
(*(int (*)(pgSurfaceObject *, pgSurfaceObject *, SDL_Rect *, SDL_Rect *, \
int))PYGAMEAPI_GET_SLOT(surface, 2))

#define import_pygame_surface() \
do { \
IMPORT_PYGAME_MODULE(surface); \
if (PyErr_Occurred() != NULL) \
break; \
IMPORT_PYGAME_MODULE(surflock); \
} while (0)

#define pgSurface_New(surface) pgSurface_New2((surface), 1)
#define pgSurface_NewNoOwn(surface) pgSurface_New2((surface), 0)

#endif /* ~PYGAMEAPI_SURFACE_INTERNAL */

/*
* SURFLOCK module
* auto imported/initialized by surface
*/
#ifndef PYGAMEAPI_SURFLOCK_INTERNAL
#define pgSurface_Prep(x) \
if ((x)->subsurface) \
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 0)))(x)
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surface, 4)))(x)

#define pgSurface_Unprep(x) \
if ((x)->subsurface) \
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 1)))(x)
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surface, 5)))(x)

#define pgSurface_Lock \
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 2))
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surface, 6))

#define pgSurface_Unlock \
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 3))
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surface, 7))

#define pgSurface_LockBy \
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 4))
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surface, 8))

#define pgSurface_UnlockBy \
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 5))
#endif
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surface, 9))

#define import_pygame_surface() IMPORT_PYGAME_MODULE(surface)

#define pgSurface_New(surface) pgSurface_New2((surface), 1)
#define pgSurface_NewNoOwn(surface) pgSurface_New2((surface), 0)

#endif /* ~PYGAMEAPI_SURFACE_INTERNAL */

/*
* EVENT module
Expand Down Expand Up @@ -604,7 +592,6 @@ PYGAMEAPI_DEFINE_SLOTS(rect);
PYGAMEAPI_DEFINE_SLOTS(joystick);
PYGAMEAPI_DEFINE_SLOTS(display);
PYGAMEAPI_DEFINE_SLOTS(surface);
PYGAMEAPI_DEFINE_SLOTS(surflock);
PYGAMEAPI_DEFINE_SLOTS(event);
PYGAMEAPI_DEFINE_SLOTS(rwobject);
PYGAMEAPI_DEFINE_SLOTS(pixelarray);
Expand All @@ -620,7 +607,6 @@ PYGAMEAPI_EXTERN_SLOTS(rect);
PYGAMEAPI_EXTERN_SLOTS(joystick);
PYGAMEAPI_EXTERN_SLOTS(display);
PYGAMEAPI_EXTERN_SLOTS(surface);
PYGAMEAPI_EXTERN_SLOTS(surflock);
PYGAMEAPI_EXTERN_SLOTS(event);
PYGAMEAPI_EXTERN_SLOTS(rwobject);
PYGAMEAPI_EXTERN_SLOTS(pixelarray);
Expand Down
9 changes: 0 additions & 9 deletions src_c/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ surface = py.extension_module(
)
endif

surflock = py.extension_module(
'surflock',
'surflock.c',
c_args: warnings_error,
dependencies: pg_base_deps,
install: true,
subdir: pg,
)

time = py.extension_module(
'time',
'time.c',
Expand Down
18 changes: 6 additions & 12 deletions src_c/static.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ PyInit_rect(void);
PyMODINIT_FUNC
PyInit_geometry(void);
PyMODINIT_FUNC
PyInit_surflock(void);
PyMODINIT_FUNC
PyInit_rwobject(void);
PyMODINIT_FUNC
PyInit_bufferproxy(void);
Expand Down Expand Up @@ -289,7 +287,6 @@ PyInit_pygame_static()

load_submodule("pygame", PyInit_base(), "base");
load_submodule("pygame", PyInit_constants(), "constants");
load_submodule("pygame", PyInit_surflock(), "surflock");
load_submodule("pygame", PyInit_rwobject(), "rwobject");
load_submodule("pygame", PyInit_pg_math(), "math");
load_submodule("pygame", PyInit_display(), "display");
Expand Down Expand Up @@ -339,15 +336,6 @@ PyInit_pygame_static()
#include "rect.c"
#include "pgcompat_rect.c"

#undef pgSurface_Lock
#undef pgSurface_Unlock
#undef pgSurface_LockBy
#undef pgSurface_UnlockBy
#undef pgSurface_Prep
#undef pgSurface_Unprep

#include "surflock.c"

#undef pgColor_New
#undef pgColor_NewLength
#undef pg_RGBAFromObjEx
Expand All @@ -364,6 +352,12 @@ PyInit_pygame_static()
#undef pgSurface_New
#undef pgSurface_Type
#undef pgSurface_SetSurface
#undef pgSurface_Lock
#undef pgSurface_Unlock
#undef pgSurface_LockBy
#undef pgSurface_UnlockBy
#undef pgSurface_Prep
#undef pgSurface_Unprep

#include "surface.c"
#include "simd_blitters_avx2.c"
Expand Down
Loading
Loading