Skip to content

Commit

Permalink
mx_util: Adopt some functionality from mxq_util
Browse files Browse the repository at this point in the history
  • Loading branch information
mariux committed May 15, 2015
1 parent 1fec0c5 commit d220d6a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
16 changes: 16 additions & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions mxq_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions mxq_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <time.h>

#include "mx_log.h"
#include "mx_util.h"
#include "mxq_mysql.h"
#include "mxq_util.h"

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion mxq_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <time.h>
#include "mx_log.h"
#include "mx_util.h"

#include "mxq_util.h"


Expand Down Expand Up @@ -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;

Expand Down
11 changes: 0 additions & 11 deletions mxq_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);

Expand Down
34 changes: 17 additions & 17 deletions mxqsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit d220d6a

Please sign in to comment.