1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-23 23:28:24 +00:00

Minor code fixes. (#489)

* Minor code fixes.

* Switch logging macros to functions.
This commit is contained in:
Brenden Matthews 2018-05-12 21:09:24 -04:00 committed by GitHub
parent 4b92556fca
commit a9e968956d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 41 deletions

View File

@ -2067,7 +2067,7 @@ int extract_variable_text_internal(struct text_object *retval,
} catch (obj_create_error &e) { } catch (obj_create_error &e) {
free(buf); free(buf);
free(orig_p); free(orig_p);
throw e; throw;
} }
if (obj != nullptr) { if (obj != nullptr) {
append_object(retval, obj); append_object(retval, obj);

View File

@ -285,10 +285,7 @@ void cimlib_render(int x, int y, int width, int height) {
imlib_free_image(); imlib_free_image();
} }
void print_image_callback(struct text_object *obj, char *p, void print_image_callback(struct text_object *obj, char *,
int p_max_size) { int) {
p = p; // just a trick to make the compiler happy about this being non-const
(void)p_max_size;
cimlib_add_image(obj->data.s); cimlib_add_image(obj->data.s);
} }

View File

@ -65,7 +65,7 @@ void clean_up(void *memtofree1, void *memtofree2);
void clean_up_without_threads(void *memtofree1, void *memtofree2); void clean_up_without_threads(void *memtofree1, void *memtofree2);
template <typename... Args> template <typename... Args>
void gettextize_format(const char *format, Args &&... args) { inline void gettextize_format(const char *format, Args &&... args) {
fprintf(stderr, _(format), args...); fprintf(stderr, _(format), args...);
} }
@ -73,26 +73,28 @@ void gettextize_format(const char *format, Args &&... args) {
// "format not a string literal and no format arguments" warning // "format not a string literal and no format arguments" warning
inline void gettextize_format(const char *format) { fputs(_(format), stderr); } inline void gettextize_format(const char *format) { fputs(_(format), stderr); }
#define NORM_ERR(...) \ template <typename... Args>
do { \ void NORM_ERR(const char *format, Args &&... args) {
fprintf(stderr, PACKAGE_NAME ": "); \ fprintf(stderr, PACKAGE_NAME ": ");
gettextize_format(__VA_ARGS__); \ gettextize_format(format, args...);
fputs("\n", stderr); \ fputs("\n", stderr);
} while (0)
/* critical error */
#define CRIT_ERR(memtofree1, memtofree2, ...) \
{ \
NORM_ERR(__VA_ARGS__); \
clean_up(memtofree1, memtofree2); \
exit(EXIT_FAILURE); \
} }
#define THREAD_CRIT_ERR(memtofree1, memtofree2, ...) \ /* critical error */
{ \ template <typename... Args>
NORM_ERR(__VA_ARGS__); \ inline void CRIT_ERR(void *memtofree1, void *memtofree2, const char *format,
clean_up_without_threads(memtofree1, memtofree2); \ Args &&... args) {
return; \ NORM_ERR(format, args...);
clean_up(memtofree1, memtofree2);
exit(EXIT_FAILURE);
}
template <typename... Args>
inline void THREAD_CRIT_ERR(void *memtofree1, void *memtofree2,
const char *format, Args &&... args) {
NORM_ERR(format, args...);
clean_up_without_threads(memtofree1, memtofree2);
return;
} }
namespace conky { namespace conky {
@ -104,15 +106,21 @@ class error : public std::runtime_error {
/* debugging output */ /* debugging output */
extern int global_debug_level; extern int global_debug_level;
#define __DBGP(level, ...) \ template <typename... Args>
do { \ inline void __DBGP(const int level, const char *format, Args &&... args) {
if (global_debug_level > level) { \ if (global_debug_level > level) {
fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__); \ fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__);
gettextize_format(__VA_ARGS__); \ gettextize_format(format, args...);
fputs("\n", stderr); \ fputs("\n", stderr);
} \ }
} while (0) }
#define DBGP(...) __DBGP(0, __VA_ARGS__) template <typename... Args>
#define DBGP2(...) __DBGP(1, __VA_ARGS__) void DBGP(const char *format, Args &&... args) {
__DBGP(0, format, args...);
}
template <typename... Args>
void DBGP2(const char *format, Args &&... args) {
__DBGP(1, format, args...);
}
#endif /* _LOGGING_H */ #endif /* _LOGGING_H */

View File

@ -37,15 +37,12 @@ void gen_free_opaque(struct text_object *obj) {
free_and_zero(obj->data.opaque); free_and_zero(obj->data.opaque);
} }
int gen_false_iftest(struct text_object *obj) { int gen_false_iftest(struct text_object *) {
(void)obj;
return 0; return 0;
} }
void gen_print_nothing(struct text_object *obj, char *p, int p_max_size) { void gen_print_nothing(struct text_object *, char *, int) {
(void)obj; // literally does nothing
p = p; // just a trick to make the compiler happy about this being non-const
(void)p_max_size;
} }
void gen_print_obj_data_s(struct text_object *obj, char *p, int p_max_size) { void gen_print_obj_data_s(struct text_object *obj, char *p, int p_max_size) {