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