1
0
forked from GitHub/gf-core

remove the logging from libgu

This commit is contained in:
kr.angelov
2013-09-12 09:30:02 +00:00
parent 2105188bd0
commit 9c3dd1e1e1
11 changed files with 1 additions and 167 deletions

View File

@@ -21,7 +21,6 @@ guinclude_HEADERS = \
gu/hash.h \
gu/in.h \
gu/list.h \
gu/log.h \
gu/map.h \
gu/mem.h \
gu/out.h \
@@ -59,7 +58,6 @@ libgu_la_SOURCES = \
gu/hash.c \
gu/in.c \
gu/list.c \
gu/log.c \
gu/map.c \
gu/mem.c \
gu/out.c \

View File

@@ -1,7 +1,6 @@
#include <gu/choice.h>
#include <gu/seq.h>
#include <gu/assert.h>
#include <gu/log.h>
struct GuChoice {
GuBuf* path;
@@ -21,7 +20,6 @@ GuChoiceMark
gu_choice_mark(GuChoice* ch)
{
gu_assert(ch->path_idx <= gu_buf_length(ch->path));
gu_debug("%p@%d: mark", ch, ch->path_idx);
return (GuChoiceMark){ch->path_idx};
}
@@ -29,7 +27,6 @@ void
gu_choice_reset(GuChoice* ch, GuChoiceMark mark)
{
gu_assert(ch->path_idx <= gu_buf_length(ch->path));
gu_debug("%p@%d: reset %d", ch, ch->path_idx, mark.path_idx);
gu_require(mark.path_idx <= ch->path_idx );
ch->path_idx = mark.path_idx;
}
@@ -51,7 +48,6 @@ gu_choice_next(GuChoice* ch, int n_choices)
i = n_choices;
}
int ret = (i == 0) ? -1 : n_choices - i;
gu_debug("%p@%d: %d", ch, ch->path_idx, ret);
ch->path_idx++;
return ret;
}

View File

@@ -1,79 +0,0 @@
#include <gu/defs.h>
#include <gu/log.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
static int gu_log_depth = 0;
static bool
gu_log_match(const char* pat, size_t patlen, const char* str)
{
if (patlen > 0 && pat[patlen-1] == '*') {
return strncmp(pat, str, patlen-1) == 0;
} else if (strlen(str) == patlen) {
return strncmp(pat, str, patlen) == 0;
}
return false;
}
static bool
gu_log_enabled(const char* func, const char* file)
{
const char* cfg = getenv("GU_LOG");
if (cfg == NULL) {
return false;
}
const char* p = cfg;
while (true) {
size_t len = strcspn(p, ",");
if (gu_log_match(p, len, func)) {
return true;
}
if (gu_log_match(p, len, file)) {
return true;
}
if (p[len] == '\0') {
break;
}
p = &p[len + 1];
}
return false;
}
void
gu_log_full_v(GuLogKind kind, const char* func, const char* file, int line,
const char* fmt, va_list args)
{
(void) (kind && line);
if (!gu_log_enabled(func, file)) {
return;
}
if (kind == GU_LOG_KIND_EXIT) {
gu_log_depth--;
}
if (fmt) {
int indent = gu_min(32 + gu_log_depth, 48);
fprintf(stderr, "%-*s: ", indent, func);
vfprintf(stderr, fmt, args);
fputc('\n', stderr);
fflush(stderr);
}
if (kind == GU_LOG_KIND_ENTER) {
gu_log_depth++;
}
}
void
gu_log_full(GuLogKind kind, const char* func, const char* file, int line,
const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
gu_log_full_v(kind, func, file, line, fmt, args);
va_end(args);
}

View File

@@ -1,65 +0,0 @@
#ifndef GU_LOG_H_
#define GU_LOG_H_
#include <stdarg.h>
typedef enum GuLogKind {
GU_LOG_KIND_ENTER,
GU_LOG_KIND_EXIT,
GU_LOG_KIND_DEBUG,
GU_LOG_KIND_ERROR
} GuLogKind;
void
gu_log_full(GuLogKind kind, const char* func, const char* file, int line,
const char* fmt, ...);
void
gu_log_full_v(GuLogKind kind, const char* func, const char* file, int line,
const char* fmt, va_list args);
#ifndef NDEBUG
#define gu_logv(kind_, fmt_, args_) \
gu_log_full_v(kind_, __func__, __FILE__, __LINE__, fmt_, args_)
#define gu_log(kind_, ...) \
gu_log_full(kind_, __func__, __FILE__, __LINE__, __VA_ARGS__)
#else
static inline void
gu_logv(GuLogKind kind, const char* fmt, va_list args)
{
(void) kind;
(void) fmt;
(void) args;
}
static inline void
gu_log(GuLogKind kind, const char* fmt, ...)
{
(void) kind;
(void) fmt;
}
#endif
#define gu_enter(...) \
gu_log(GU_LOG_KIND_ENTER, __VA_ARGS__)
#define gu_exit(...) \
gu_log(GU_LOG_KIND_EXIT, __VA_ARGS__)
#define gu_debug(...) \
gu_log(GU_LOG_KIND_DEBUG, __VA_ARGS__)
#define gu_debugv(kind_, fmt_, args_) \
gu_logv(GU_LOG_KIND_DEBUG, fmt_, args_)
#endif // GU_LOG_H_

View File

@@ -4,7 +4,6 @@
#include <gu/map.h>
#include <gu/assert.h>
#include <gu/prime.h>
#include <gu/log.h>
typedef enum {
GU_MAP_GENERIC,
@@ -185,7 +184,6 @@ gu_map_resize(GuMap* map)
}
gu_assert(data->n_entries > data->n_occupied);
gu_debug("Resized to %d entries", data->n_entries);
data->n_occupied = 0;
data->zero_idx = SIZE_MAX;

View File

@@ -21,7 +21,6 @@
#include <gu/fun.h>
#include <gu/bits.h>
#include <gu/assert.h>
#include <gu/log.h>
#include <string.h>
#include <stdlib.h>
@@ -60,7 +59,6 @@ gu_mem_realloc(void* p, size_t size)
if (size != 0 && buf == NULL) {
gu_fatal("Memory allocation failed");
}
gu_debug("%p %zu -> %p", p, size, buf); // strictly illegal
return buf;
}
@@ -71,14 +69,12 @@ gu_mem_alloc(size_t size)
if (buf == NULL) {
gu_fatal("Memory allocation failed");
}
gu_debug("%zu -> %p", size, buf);
return buf;
}
static void
gu_mem_free(void* p)
{
gu_debug("%p", p);
free(p);
}
@@ -180,7 +176,6 @@ gu_local_pool_(uint8_t* buf, size_t sz)
{
GuPool* pool = gu_init_pool(buf, sz);
pool->flags |= GU_POOL_LOCAL;
gu_debug("%p", pool);
return pool;
}
@@ -190,7 +185,6 @@ gu_new_pool(void)
size_t sz = GU_FLEX_SIZE(GuPool, init_buf, gu_mem_pool_initial_size);
uint8_t* buf = gu_mem_buf_alloc(sz, &sz);
GuPool* pool = gu_init_pool(buf, sz);
gu_debug("%p", pool);
return pool;
}
@@ -264,8 +258,6 @@ void*
gu_malloc_prefixed(GuPool* pool, size_t pre_align, size_t pre_size,
size_t align, size_t size)
{
gu_enter("-> %p %zu %zu %zu %zu",
pool, pre_align, pre_size, align, size);
void* ret = NULL;
if (pre_align == 0) {
pre_align = gu_alignof(GuMaxAlign);
@@ -291,7 +283,6 @@ gu_malloc_prefixed(GuPool* pool, size_t pre_align, size_t pre_size,
ret = gu_pool_malloc_aligned(pool, pre_align, pre_size,
align, size);
}
gu_exit("<- %p", ret);
return ret;
}
@@ -318,7 +309,6 @@ gu_pool_finally(GuPool* pool, GuFinalizer* finalizer)
void
gu_pool_free(GuPool* pool)
{
gu_debug("%p", pool);
GuFinalizerNode* node = pool->finalizers;
while (node) {
GuFinalizerNode* next = node->next;

View File

@@ -2,7 +2,6 @@
#include "linearizer.h"
#include <gu/map.h>
#include <gu/fun.h>
#include <gu/log.h>
#include <gu/choice.h>
#include <gu/seq.h>
#include <gu/file.h>

View File

@@ -2,7 +2,6 @@
#include <gu/seq.h>
#include <gu/assert.h>
#include <gu/log.h>
#include <gu/file.h>
#include <math.h>
#include <stdlib.h>

View File

@@ -1,6 +1,5 @@
#include <gu/variant.h>
#include <gu/map.h>
#include <gu/log.h>
#include <gu/enum.h>
#include <gu/file.h>
#include <pgf/pgf.h>

View File

@@ -1,6 +1,5 @@
#include <gu/variant.h>
#include <gu/map.h>
#include <gu/log.h>
#include <gu/enum.h>
#include <gu/file.h>
#include <pgf/pgf.h>

View File

@@ -5,7 +5,7 @@ include $(CLEAR_VARS)
jni_c_files := jpgf.c
pgf_c_files := data.c expr.c graphviz.c lexer.c linearizer.c literals.c parser.c parseval.c pgf.c printer.c reader.c reasoner.c jit.c
gu_c_files := assert.c choice.c exn.c fun.c in.c list.c map.c out.c str.c type.c utf8.c \
bits.c defs.c enum.c file.c hash.c log.c mem.c prime.c seq.c string.c ucs.c variant.c
bits.c defs.c enum.c file.c hash.c mem.c prime.c seq.c string.c ucs.c variant.c
LOCAL_MODULE := jpgf
LOCAL_SRC_FILES := $(addprefix ../../../runtime/java/, $(jni_c_files)) \