Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=29d1cc65a279cc87c6e392ddc009ffb0df1cadf8
commit 29d1cc65a279cc87c6e392ddc009ffb0df1cadf8 Author: Michel Hermier <[email protected]> Date: Fri Aug 1 11:10:04 2014 +0200 libpacman: Add c++ style initializers to fcallback structures. diff --git a/lib/libpacman/cache.cpp b/lib/libpacman/cache.cpp index f33b9d6..0d25815 100644 --- a/lib/libpacman/cache.cpp +++ b/lib/libpacman/cache.cpp @@ -161,7 +161,7 @@ pmlist_t *_pacman_db_whatprovides(Database *db, char *package) { FPtrList *pkgs = NULL; FStrMatcher strmatcher = { NULL }; - FMatcher packagestrmatcher = { NULL }; + FMatcher packagestrmatcher; ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, NULL)); diff --git a/lib/libpacman/db.cpp b/lib/libpacman/db.cpp index 6b02cd2..2380d50 100644 --- a/lib/libpacman/db.cpp +++ b/lib/libpacman/db.cpp @@ -96,7 +96,7 @@ pmlist_t *Database::search(pmlist_t *needles) for(i = needles; i; i = i->next) { FStrMatcher strmatcher = { NULL }; - FMatcher packagestrmatcher = { NULL }; + FMatcher packagestrmatcher; const char *targ = i->data; if(f_strempty(targ)) { diff --git a/lib/libpacman/util.h b/lib/libpacman/util.h index d4f04eb..869eaf8 100644 --- a/lib/libpacman/util.h +++ b/lib/libpacman/util.h @@ -34,7 +34,11 @@ #define FREE(p) do { if (p) { free(p); p = NULL; } } while(0) +#if 1 +#define ASSERT(cond, action) do { if(!(cond)) { _pacman_log(PM_LOG_ERROR, _("ASSERT failed: %s"), #cond); action; } } while(0) +#else #define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0) +#endif #define STRNCPY(s1, s2, len) do { \ strncpy(s1, s2, (len)-1); \ diff --git a/lib/libpacman/util/fcallback.h b/lib/libpacman/util/fcallback.h index e6654fb..5a07b64 100644 --- a/lib/libpacman/util/fcallback.h +++ b/lib/libpacman/util/fcallback.h @@ -1,7 +1,7 @@ /* * fcallbacks.h * - * Copyright (c) 2013 by Michel Hermier <[email protected]> + * Copyright (c) 2013-2014 by Michel Hermier <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,16 @@ typedef int (*FComparatorFunc)(const void *ptr, const void *comparator_data); typedef struct FComparator FComparator; struct FComparator { +#ifdef __cplusplus + FComparator() + : fn(NULL), data(NULL) + { } + + FComparator(FComparatorFunc _fn, const void *_data) + : fn(_fn), data(_data) + { } +#endif + FComparatorFunc fn; const void *data; }; @@ -101,6 +111,16 @@ typedef int (*FMatcherFunc)(const void *ptr, const void *matcher_data); typedef struct FMatcher FMatcher; struct FMatcher { +#ifdef __cplusplus + FMatcher() + : fn(NULL), data(NULL) + { } + + FMatcher(FMatcherFunc _fn, const void *_data) + : fn(_fn), data(_data) + { } +#endif + FMatcherFunc fn; const void *data; }; @@ -194,6 +214,16 @@ typedef void (*FVisitorFunc)(void *ptr, void *visitor_data); typedef struct FVisitor FVisitor; struct FVisitor { +#ifdef __cplusplus + FVisitor() + : fn(NULL), data(NULL) + { } + + FVisitor(FVisitorFunc _fn, void *_data) + : fn(_fn), data(_data) + { } +#endif + FVisitorFunc fn; void *data; }; diff --git a/lib/libpacman/util/list.h b/lib/libpacman/util/list.h index 1528ed8..795878f 100644 --- a/lib/libpacman/util/list.h +++ b/lib/libpacman/util/list.h @@ -27,9 +27,12 @@ #ifdef __cplusplus extern "C" { -#endif +#define _FREELIST(p, f) do { if(p) { FVisitor visitor((FVisitorFunc)f, NULL); f_ptrlist_delete(p, &visitor); p = NULL; } } while(0) +#else #define _FREELIST(p, f) do { if(p) { FVisitor visitor = { .fn = (FVisitorFunc)f, .data = NULL, }; f_ptrlist_delete(p, &visitor); p = NULL; } } while(0) +#endif + #define FREELIST(p) _FREELIST(p, free) #define FREELISTPTR(p) _FREELIST(p, NULL) _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
