Skip to content

Commit e8d517e

Browse files
authored
Merge pull request #2973 from Starbuck5/remove-obsolete-surflock-functions
Remove obsolete surflock functions
2 parents d766565 + 9778f43 commit e8d517e

File tree

5 files changed

+13
-120
lines changed

5 files changed

+13
-120
lines changed

docs/reST/c_api/surflock.rst

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,6 @@ This extension module implements SDL surface locking for the
1515
Header file: src_c/include/pygame.h
1616

1717

18-
.. c:type:: pgLifetimeLockObject
19-
20-
.. c:member:: PyObject *surface
21-
22-
An SDL locked pygame surface.
23-
24-
.. c:member:: PyObject *lockobj
25-
26-
The Python object which owns the lock on the surface.
27-
This field does not own a reference to the object.
28-
29-
The lifetime lock type instance.
30-
A lifetime lock pairs a locked pygame surface with
31-
the Python object that locked the surface for modification.
32-
The lock is removed automatically when the lifetime lock instance
33-
is garbage collected.
34-
35-
.. c:var:: PyTypeObject *pgLifetimeLock_Type
36-
37-
The pygame internal surflock lifetime lock object type.
38-
39-
.. c:function:: int pgLifetimeLock_Check(PyObject *x)
40-
41-
Return true if Python object *x* is a :c:data:`pgLifetimeLock_Type` instance,
42-
false otherwise.
43-
This will return false on :c:data:`pgLifetimeLock_Type` subclass instances as well.
44-
4518
.. c:function:: void pgSurface_Prep(pgSurfaceObject *surfobj)
4619
4720
If *surfobj* is a subsurface, then lock the parent surface with *surfobj*
@@ -72,11 +45,3 @@ Header file: src_c/include/pygame.h
7245
.. c:function:: int pgSurface_UnLockBy(pgSurfaceObject *surfobj, PyObject *lockobj)
7346
7447
Remove the lock on pygame surface *surfobj* owned by Python object *lockobj*.
75-
76-
.. c:function:: PyObject *pgSurface_LockLifetime(PyObject *surfobj, PyObject *lockobj)
77-
78-
Lock pygame surface *surfobj* for Python object *lockobj* and return a
79-
new :c:data:`pgLifetimeLock_Type` instance for the lock.
80-
81-
This function is not called anywhere within pygame.
82-
It and pgLifetimeLock_Type are candidates for removal.

src_c/_pygame.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,6 @@ struct pgEventObject {
485485
PyObject *dict;
486486
};
487487

488-
/*
489-
* surflock module internals
490-
*/
491-
typedef struct {
492-
PyObject_HEAD PyObject *surface;
493-
PyObject *lockobj;
494-
PyObject *weakrefs;
495-
} pgLifetimeLockObject;
496-
497488
/*
498489
* surface module internals
499490
*/
@@ -542,7 +533,7 @@ typedef enum {
542533
#define PYGAMEAPI_JOYSTICK_NUMSLOTS 3
543534
#define PYGAMEAPI_DISPLAY_NUMSLOTS 2
544535
#define PYGAMEAPI_SURFACE_NUMSLOTS 4
545-
#define PYGAMEAPI_SURFLOCK_NUMSLOTS 8
536+
#define PYGAMEAPI_SURFLOCK_NUMSLOTS 6
546537
#define PYGAMEAPI_RWOBJECT_NUMSLOTS 5
547538
#define PYGAMEAPI_PIXELARRAY_NUMSLOTS 2
548539
#define PYGAMEAPI_COLOR_NUMSLOTS 5

src_c/include/_pygame.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -354,32 +354,25 @@ typedef struct {
354354
* auto imported/initialized by surface
355355
*/
356356
#ifndef PYGAMEAPI_SURFLOCK_INTERNAL
357-
#define pgLifetimeLock_Type (*(PyTypeObject *)PYGAMEAPI_GET_SLOT(surflock, 0))
358-
359-
#define pgLifetimeLock_Check(x) ((x)->ob_type == &pgLifetimeLock_Type)
360-
361357
#define pgSurface_Prep(x) \
362358
if ((x)->subsurface) \
363-
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 1)))(x)
359+
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 0)))(x)
364360

365361
#define pgSurface_Unprep(x) \
366362
if ((x)->subsurface) \
367-
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 2)))(x)
363+
(*(*(void (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 1)))(x)
368364

369365
#define pgSurface_Lock \
370-
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 3))
366+
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 2))
371367

372368
#define pgSurface_Unlock \
373-
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 4))
369+
(*(int (*)(pgSurfaceObject *))PYGAMEAPI_GET_SLOT(surflock, 3))
374370

375371
#define pgSurface_LockBy \
376-
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 5))
372+
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 4))
377373

378374
#define pgSurface_UnlockBy \
379-
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 6))
380-
381-
#define pgSurface_LockLifetime \
382-
(*(PyObject * (*)(PyObject *, PyObject *)) PYGAMEAPI_GET_SLOT(surflock, 7))
375+
(*(int (*)(pgSurfaceObject *, PyObject *))PYGAMEAPI_GET_SLOT(surflock, 5))
383376
#endif
384377

385378
/*

src_c/static.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ PyInit_pygame_static()
334334
#undef pgSurface_UnlockBy
335335
#undef pgSurface_Prep
336336
#undef pgSurface_Unprep
337-
#undef pgLifetimeLock_Type
338-
#undef pgSurface_LockLifetime
339337

340338
#include "surflock.c"
341339

src_c/surflock.c

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ pgSurface_LockBy(pgSurfaceObject *, PyObject *);
3939
static int
4040
pgSurface_UnlockBy(pgSurfaceObject *, PyObject *);
4141

42-
static void
43-
_lifelock_dealloc(PyObject *);
44-
4542
static void
4643
pgSurface_Prep(pgSurfaceObject *surfobj)
4744
{
@@ -169,51 +166,6 @@ pgSurface_UnlockBy(pgSurfaceObject *surfobj, PyObject *lockobj)
169166
return noerror;
170167
}
171168

172-
static PyTypeObject pgLifetimeLock_Type = {
173-
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "pygame.surflock.SurfLifeLock",
174-
.tp_basicsize = sizeof(pgLifetimeLockObject),
175-
.tp_dealloc = _lifelock_dealloc,
176-
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
177-
.tp_weaklistoffset = offsetof(pgLifetimeLockObject, weakrefs),
178-
};
179-
180-
/* lifetimelock object internals */
181-
static void
182-
_lifelock_dealloc(PyObject *self)
183-
{
184-
pgLifetimeLockObject *lifelock = (pgLifetimeLockObject *)self;
185-
186-
if (lifelock->weakrefs != NULL) {
187-
PyObject_ClearWeakRefs(self);
188-
}
189-
190-
pgSurface_UnlockBy((pgSurfaceObject *)lifelock->surface,
191-
lifelock->lockobj);
192-
Py_DECREF(lifelock->surface);
193-
Py_TYPE(self)->tp_free(self);
194-
}
195-
196-
static PyObject *
197-
pgSurface_LockLifetime(PyObject *surfobj, PyObject *lockobj)
198-
{
199-
pgLifetimeLockObject *life;
200-
if (surfobj == NULL) {
201-
return RAISE(pgExc_SDLError, SDL_GetError());
202-
}
203-
204-
life = PyObject_New(pgLifetimeLockObject, &pgLifetimeLock_Type);
205-
if (life != NULL) {
206-
life->surface = surfobj;
207-
life->lockobj = lockobj;
208-
life->weakrefs = NULL;
209-
Py_INCREF(surfobj);
210-
if (!pgSurface_LockBy((pgSurfaceObject *)surfobj, lockobj)) {
211-
return NULL;
212-
}
213-
}
214-
return (PyObject *)life;
215-
}
216-
217169
static PyMethodDef _surflock_methods[] = {{NULL, NULL, 0, NULL}};
218170

219171
/*DOC*/ static char _surflock_doc[] =
@@ -234,25 +186,19 @@ MODINIT_DEFINE(surflock)
234186
NULL,
235187
NULL};
236188

237-
if (PyType_Ready(&pgLifetimeLock_Type) < 0) {
238-
return NULL;
239-
}
240-
241189
/* Create the module and add the functions */
242190
module = PyModule_Create(&_module);
243191
if (module == NULL) {
244192
return NULL;
245193
}
246194

247195
/* export the c api */
248-
c_api[0] = &pgLifetimeLock_Type;
249-
c_api[1] = pgSurface_Prep;
250-
c_api[2] = pgSurface_Unprep;
251-
c_api[3] = pgSurface_Lock;
252-
c_api[4] = pgSurface_Unlock;
253-
c_api[5] = pgSurface_LockBy;
254-
c_api[6] = pgSurface_UnlockBy;
255-
c_api[7] = pgSurface_LockLifetime;
196+
c_api[0] = pgSurface_Prep;
197+
c_api[1] = pgSurface_Unprep;
198+
c_api[2] = pgSurface_Lock;
199+
c_api[3] = pgSurface_Unlock;
200+
c_api[4] = pgSurface_LockBy;
201+
c_api[5] = pgSurface_UnlockBy;
256202
apiobj = encapsulate_api(c_api, "surflock");
257203
if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj)) {
258204
Py_XDECREF(apiobj);

0 commit comments

Comments
 (0)