DRYer
This commit is contained in:
parent
7d6d8efc26
commit
b4a96428f3
@ -42,7 +42,7 @@ grman_realloc(GraphicsManager *old, index_type lines, index_type columns) {
|
||||
} else {
|
||||
self->images_capacity = old->images_capacity; self->images = old->images; self->image_count = old->image_count;
|
||||
old->images = NULL;
|
||||
grman_free(old);
|
||||
Py_DECREF(old);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -64,12 +64,13 @@ free_image(Image *img) {
|
||||
free_load_data(&(img->load_data));
|
||||
}
|
||||
|
||||
GraphicsManager*
|
||||
grman_free(GraphicsManager* self) {
|
||||
for (size_t i = 0; i < self->image_count; i++) free_image(self->images + i);
|
||||
free(self->images);
|
||||
static void
|
||||
dealloc(GraphicsManager* self) {
|
||||
if (self->images) {
|
||||
for (size_t i = 0; i < self->image_count; i++) free_image(self->images + i);
|
||||
free(self->images);
|
||||
}
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static size_t internal_id_counter = 1;
|
||||
@ -426,11 +427,6 @@ new(PyTypeObject UNUSED *type, PyObject *args, PyObject UNUSED *kwds) {
|
||||
return ans;
|
||||
}
|
||||
|
||||
static void
|
||||
dealloc(GraphicsManager* self) {
|
||||
grman_free(self);
|
||||
}
|
||||
|
||||
static inline PyObject*
|
||||
image_as_dict(Image *img) {
|
||||
#define U(x) #x, img->x
|
||||
|
||||
@ -49,5 +49,4 @@ PyTypeObject GraphicsManager_Type;
|
||||
|
||||
GraphicsManager* grman_realloc(GraphicsManager *, index_type lines, index_type columns);
|
||||
void grman_clear(GraphicsManager*);
|
||||
GraphicsManager* grman_free(GraphicsManager*);
|
||||
const char* grman_handle_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_t *payload);
|
||||
|
||||
@ -213,8 +213,7 @@ static void
|
||||
dealloc(Screen* self) {
|
||||
pthread_mutex_destroy(&self->read_buf_lock);
|
||||
pthread_mutex_destroy(&self->write_buf_lock);
|
||||
if (self->main_grman) { self->main_grman = grman_free(self->main_grman); }
|
||||
if (self->alt_grman) { self->alt_grman = grman_free(self->alt_grman); }
|
||||
Py_CLEAR(self->grman); Py_CLEAR(self->alt_grman);
|
||||
PyMem_RawFree(self->write_buf);
|
||||
Py_CLEAR(self->callbacks);
|
||||
Py_CLEAR(self->test_child);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user