diff --git a/mx_util.h b/mx_util.h index d4a9e2c..63af526 100644 --- a/mx_util.h +++ b/mx_util.h @@ -38,6 +38,22 @@ #undef mx_free_null #define mx_free_null(a) do { free(a); (a) = NULL; } while(0) +#undef _mx_cleanup_ +#define _mx_cleanup_(x) __attribute__((cleanup(x))) + +static inline void __mx_free(void *ptr) { + free(*(void **)ptr); +} + +#undef _mx_cleanup_free_ +#define _mx_cleanup_free_ _mx_cleanup_(__mx_free) + +#undef likely +#define likely(x) __builtin_expect((x),1) + +#undef unlikely +#define unlikely(x) __builtin_expect((x),0) + int mx_strbeginswith(char *str, const char *start, char **endptr); int mx_stribeginswith(char *str, const char *start, char **endptr); int mx_strbeginswithany(char *str, char **starts, char **endptr); diff --git a/mxq_job.c b/mxq_job.c index 2cef544..b8ee941 100644 --- a/mxq_job.c +++ b/mxq_job.c @@ -414,7 +414,7 @@ int mxq_job_set_tmpfilenames(struct mxq_group *g, struct mxq_job *j) int res; if (!streq(j->job_stdout, "/dev/null")) { - _cleanup_free_ char *dir = NULL; + _mx_cleanup_free_ char *dir = NULL; dir = mx_dirname_forever(j->job_stdout); @@ -424,7 +424,7 @@ int mxq_job_set_tmpfilenames(struct mxq_group *g, struct mxq_job *j) } if (!streq(j->job_stderr, "/dev/null")) { - _cleanup_free_ char *dir = NULL; + _mx_cleanup_free_ char *dir = NULL; if (streq(j->job_stderr, j->job_stdout)) { j->tmp_stderr = j->tmp_stdout; diff --git a/mxq_mysql.c b/mxq_mysql.c index 944a4cb..8acc470 100644 --- a/mxq_mysql.c +++ b/mxq_mysql.c @@ -17,6 +17,7 @@ #include #include "mx_log.h" +#include "mx_util.h" #include "mxq_mysql.h" #include "mxq_util.h" @@ -63,7 +64,7 @@ void mxq_mysql_close(MYSQL *mysql) { int mxq_mysql_query(MYSQL *mysql, const char *fmt, ...) { va_list ap; - _cleanup_free_ char *query = NULL; + _mx_cleanup_free_ char *query = NULL; int res; size_t len; @@ -86,7 +87,7 @@ int mxq_mysql_query(MYSQL *mysql, const char *fmt, ...) MYSQL_RES *mxq_mysql_query_with_result(MYSQL *mysql, const char *fmt, ...) { va_list ap; - _cleanup_free_ char *query = NULL; + _mx_cleanup_free_ char *query = NULL; MYSQL_RES *mres; size_t len; int res; @@ -260,7 +261,7 @@ char *mxq_mysql_escape_str(MYSQL *mysql, char *s) char *mxq_mysql_escape_strvec(MYSQL *mysql, char **sv) { char *quoted = NULL; - _cleanup_free_ char *s = NULL; + _mx_cleanup_free_ char *s = NULL; size_t len; s = strvec_to_str(sv); diff --git a/mxq_util.c b/mxq_util.c index 195978b..055921f 100644 --- a/mxq_util.c +++ b/mxq_util.c @@ -15,6 +15,8 @@ #include #include "mx_log.h" +#include "mx_util.h" + #include "mxq_util.h" @@ -370,7 +372,7 @@ int mxq_setenv(const char *name, const char *value) int mxq_setenvf(const char *name, char *fmt, ...) { va_list ap; - _cleanup_free_ char *value = NULL; + _mx_cleanup_free_ char *value = NULL; size_t len; int res; diff --git a/mxq_util.h b/mxq_util.h index 5dc320a..91a5b38 100644 --- a/mxq_util.h +++ b/mxq_util.h @@ -31,17 +31,6 @@ void strvec_free(char **strvec); #define free_null(a) do { free((a)); (a) = NULL; } while(0) -#define _cleanup_(x) __attribute__((cleanup(x))) - -static inline void freep(void *p) { - free(*(void**) p); -} - -#define _cleanup_free_ _cleanup_(freep) - -#define likely(x) __builtin_expect((x),1) -#define unlikely(x) __builtin_expect((x),0) - int mxq_setenv(const char *name, const char *value); int mxq_setenvf(const char *name, char *fmt, ...); diff --git a/mxqsub.c b/mxqsub.c index 7bdfc7b..7d7ba94 100644 --- a/mxqsub.c +++ b/mxqsub.c @@ -153,10 +153,10 @@ static int mxq_mysql_load_group(MYSQL *mysql, struct mxq_job *j) unsigned int num_rows; unsigned int num_fields; - _cleanup_free_ char *q_group_name = NULL; - _cleanup_free_ char *q_user_name = NULL; - _cleanup_free_ char *q_user_group = NULL; - _cleanup_free_ char *q_job_command = NULL; + _mx_cleanup_free_ char *q_group_name = NULL; + _mx_cleanup_free_ char *q_user_name = NULL; + _mx_cleanup_free_ char *q_user_group = NULL; + _mx_cleanup_free_ char *q_job_command = NULL; struct mxq_group *g; @@ -247,10 +247,10 @@ static int mxq_mysql_load_group(MYSQL *mysql, struct mxq_job *j) static int mxq_mysql_add_group(MYSQL *mysql, struct mxq_job *j) { - _cleanup_free_ char *q_group_name = NULL; - _cleanup_free_ char *q_user = NULL; - _cleanup_free_ char *q_group = NULL; - _cleanup_free_ char *q_command = NULL; + _mx_cleanup_free_ char *q_group_name = NULL; + _mx_cleanup_free_ char *q_user = NULL; + _mx_cleanup_free_ char *q_group = NULL; + _mx_cleanup_free_ char *q_command = NULL; int len; int res; @@ -310,11 +310,11 @@ static int mxq_mysql_add_group(MYSQL *mysql, struct mxq_job *j) static int mxq_mysql_add_job(MYSQL *mysql, struct mxq_job *j) { - _cleanup_free_ char *q_workdir = NULL; - _cleanup_free_ char *q_argv = NULL; - _cleanup_free_ char *q_stdout = NULL; - _cleanup_free_ char *q_stderr = NULL; - _cleanup_free_ char *q_submit_host = NULL; + _mx_cleanup_free_ char *q_workdir = NULL; + _mx_cleanup_free_ char *q_argv = NULL; + _mx_cleanup_free_ char *q_stdout = NULL; + _mx_cleanup_free_ char *q_stderr = NULL; + _mx_cleanup_free_ char *q_submit_host = NULL; int len; int res; @@ -411,10 +411,10 @@ int main(int argc, char *argv[]) char *arg_mysql_default_file; char *arg_mysql_default_group; - _cleanup_free_ char *current_workdir = NULL; - _cleanup_free_ char *arg_stdout_absolute = NULL; - _cleanup_free_ char *arg_stderr_absolute = NULL; - _cleanup_free_ char *arg_args = NULL; + _mx_cleanup_free_ char *current_workdir = NULL; + _mx_cleanup_free_ char *arg_stdout_absolute = NULL; + _mx_cleanup_free_ char *arg_stderr_absolute = NULL; + _mx_cleanup_free_ char *arg_args = NULL; int flags = 0;