memory allocation helper macros
This commit is contained in:
parent
a19a3d2515
commit
4b89994ff4
@ -119,5 +119,21 @@ char * py_str_to_c_str(PyObject *value, const char *encoding);
|
||||
#define MEMBER(type, attr, attr_type, docstr)\
|
||||
{#attr, attr_type, offsetof(type, attr), 0, PyDoc_STR(docstr)}
|
||||
|
||||
/* Helpers for memory allocation */
|
||||
|
||||
|
||||
#define MALLOC(ptr, size, label) \
|
||||
ptr = realloc(ptr, size * sizeof(char));\
|
||||
if (ptr == NULL) {\
|
||||
err = GIT_ERROR;\
|
||||
giterr_set_oom();\
|
||||
goto label;\
|
||||
}\
|
||||
|
||||
#define FREE(to_free)\
|
||||
if (to_free != NULL) { free(to_free); to_free = NULL; }
|
||||
#define FREE_FUNC(to_free, fnct)\
|
||||
if (to_free != NULL) { fnct(to_free); to_free = NULL; }
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user