core API:
- debugging macros simplified - cleanup - h5_delete_attachment(): check of file mode added
This commit is contained in:
+66
-110
@@ -81,16 +81,6 @@ extern struct call_stack h5_call_stack;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
h5_call_stack_init (
|
||||
const char* fname,
|
||||
enum h5_rtypes type
|
||||
) {
|
||||
h5_call_stack.level = 0;
|
||||
h5_call_stack.entry[0].name = (char *)fname;
|
||||
h5_call_stack.entry[0].type = type;
|
||||
}
|
||||
|
||||
static inline void
|
||||
h5_call_stack_push (
|
||||
const char* fname,
|
||||
@@ -189,106 +179,6 @@ __attribute__ ((format (printf, 1, 2)))
|
||||
#endif
|
||||
;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// function enter macro
|
||||
#if defined(NDEBUG)
|
||||
|
||||
#define __API_ENTER(type, mask, fmt, ...) \
|
||||
h5_call_stack_init (__func__,e_##type); \
|
||||
type ret_value = (type)H5_ERR;
|
||||
|
||||
#define __FUNC_ENTER(type, mask, fmt, ...) \
|
||||
type ret_value = (type)H5_ERR;
|
||||
|
||||
#else // NDEBUG not defined
|
||||
|
||||
#define __API_ENTER(type, mask, fmt, ...) \
|
||||
h5_call_stack_push (__func__,e_##type); \
|
||||
type ret_value = (type)H5_ERR; \
|
||||
if (h5_log_level & mask ) { \
|
||||
h5_debug ("(" fmt ")", __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define __FUNC_ENTER(type, mask, fmt, ...) \
|
||||
type ret_value = (type)H5_ERR; \
|
||||
if (h5_log_level & mask ) { \
|
||||
h5_call_stack_push (__func__,e_##type); \
|
||||
h5_debug ("(" fmt ")", __VA_ARGS__); \
|
||||
} \
|
||||
|
||||
#endif
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define __API_LEAVE(expr) { \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
}
|
||||
|
||||
#define __FUNC_LEAVE(expr) { \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// function return macro
|
||||
#if defined(NDEBUG)
|
||||
|
||||
#define __API_RETURN(expr, mask) \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
done: \
|
||||
return ret_value;
|
||||
|
||||
#define __FUNC_RETURN(expr, mask) \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
done: \
|
||||
return ret_value;
|
||||
|
||||
#else // NDEBUG not defined
|
||||
|
||||
#define __API_RETURN(expr, mask) \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
done: \
|
||||
if (h5_log_level & mask ) { \
|
||||
char fmt[256]; \
|
||||
snprintf (fmt, sizeof(fmt), "return: %s", \
|
||||
h5_rfmts[h5_call_stack_get_type()]); \
|
||||
h5_debug (fmt, ret_value); \
|
||||
} \
|
||||
h5_call_stack_reset (); \
|
||||
return ret_value;
|
||||
|
||||
#define __FUNC_RETURN(expr, mask) \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
done: \
|
||||
if (h5_log_level & mask ) { \
|
||||
char fmt[256]; \
|
||||
snprintf (fmt, sizeof(fmt), "return: %s", \
|
||||
h5_rfmts[h5_call_stack_get_type()]); \
|
||||
h5_debug (fmt, ret_value); \
|
||||
h5_call_stack_pop(); \
|
||||
} \
|
||||
return ret_value;
|
||||
|
||||
#endif
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define H5_API_ENTER(type, fmt, ...) \
|
||||
__API_ENTER(type, H5_DEBUG_API, fmt, __VA_ARGS__)
|
||||
#define H5_API_LEAVE(expr) __API_LEAVE(expr)
|
||||
#define H5_API_RETURN(expr) __API_RETURN(expr, H5_DEBUG_API);
|
||||
|
||||
|
||||
#define TRY( func ) \
|
||||
if ((int64_t)(ptrdiff_t)(func) <= (int64_t)H5_ERR) { \
|
||||
goto done; \
|
||||
}
|
||||
|
||||
h5_err_t
|
||||
h5_set_loglevel (
|
||||
const h5_id_t);
|
||||
@@ -301,4 +191,70 @@ h5_get_loglevel (
|
||||
}
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// function enter macro
|
||||
#if defined(NDEBUG)
|
||||
|
||||
#define H5_API_ENTER(type, fmt, ...) \
|
||||
type ret_value = (type)H5_ERR;
|
||||
|
||||
#else // NDEBUG not defined
|
||||
|
||||
#define H5_API_ENTER(type, fmt, ...) \
|
||||
h5_call_stack_reset (); \
|
||||
type ret_value = (type)H5_ERR; \
|
||||
int __log__ = h5_log_level & H5_DEBUG_API; \
|
||||
if (__log__) { \
|
||||
h5_call_stack_push (__func__,e_##type); \
|
||||
h5_debug ("(" fmt ")", __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#endif
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define H5_LEAVE(expr) { \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// function return macro
|
||||
#if defined(NDEBUG)
|
||||
|
||||
#define H5_RETURN(expr) \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
done: \
|
||||
return ret_value;
|
||||
|
||||
#else // NDEBUG not defined
|
||||
|
||||
#define H5_RETURN(expr) \
|
||||
ret_value = expr; \
|
||||
goto done; \
|
||||
done: \
|
||||
if (__log__ ) { \
|
||||
char fmt[256]; \
|
||||
snprintf (fmt, sizeof(fmt), "return: %s", \
|
||||
h5_rfmts[h5_call_stack_get_type()]); \
|
||||
h5_debug (fmt, ret_value); \
|
||||
h5_call_stack_pop(); \
|
||||
} \
|
||||
return ret_value;
|
||||
|
||||
#endif
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define H5_API_LEAVE(expr) H5_LEAVE(expr)
|
||||
#define H5_API_RETURN(expr) H5_RETURN(expr);
|
||||
|
||||
|
||||
#define TRY( func ) \
|
||||
if ((int64_t)(ptrdiff_t)(func) <= (int64_t)H5_ERR) { \
|
||||
goto done; \
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,84 +10,16 @@
|
||||
#ifndef __H5CORE_H5_SYSCALL_H
|
||||
#define __H5CORE_H5_SYSCALL_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "h5core/h5_types.h"
|
||||
#include "h5core/h5_log.h"
|
||||
|
||||
#define MALLOC_WRAPPER_ENTER(type, fmt, ...) \
|
||||
__FUNC_ENTER(type, H5_DEBUG_MALLOC, fmt, __VA_ARGS__)
|
||||
#define MALLOC_WRAPPER_LEAVE(value) __FUNC_LEAVE(value)
|
||||
#define MALLOC_WRAPPER_RETURN(value) __FUNC_RETURN(value, H5_DEBUG_MALLOC)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
static inline h5_err_t
|
||||
h5_free (
|
||||
void* ptr
|
||||
) {
|
||||
MALLOC_WRAPPER_ENTER (h5_err_t, "ptr=%p", ptr);
|
||||
if (ptr) {
|
||||
free (ptr);
|
||||
}
|
||||
MALLOC_WRAPPER_RETURN (H5_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
static inline void_p
|
||||
h5_alloc (
|
||||
void* ptr,
|
||||
const size_t size
|
||||
) {
|
||||
MALLOC_WRAPPER_ENTER (void_p, "ptr=%p, size=%lu", ptr, size);
|
||||
if (size < 1) {
|
||||
ret_value = (void_p) h5_free (ptr);
|
||||
MALLOC_WRAPPER_LEAVE (NULL);
|
||||
}
|
||||
ptr = realloc (ptr, size);
|
||||
if (ptr == NULL) {
|
||||
MALLOC_WRAPPER_LEAVE (
|
||||
(void_p)h5_error (H5_ERR_NOMEM, "Out of memory. Tried to alloc %lld", (long long int)size));
|
||||
}
|
||||
MALLOC_WRAPPER_RETURN (ptr);
|
||||
}
|
||||
|
||||
static inline void_p
|
||||
h5_calloc (
|
||||
const size_t count,
|
||||
const size_t size
|
||||
) {
|
||||
MALLOC_WRAPPER_ENTER (void_p, "count=%zu , size=%zu", count, size);
|
||||
void* ptr = NULL;
|
||||
if (count * size < 1) {
|
||||
MALLOC_WRAPPER_LEAVE (ptr);
|
||||
}
|
||||
ptr = calloc (count, size);
|
||||
if (ptr == NULL) {
|
||||
MALLOC_WRAPPER_LEAVE (
|
||||
(void_p)h5_error (H5_ERR_NOMEM, "Out of memory. Tried to alloc %lld", (long long int)count* size));
|
||||
}
|
||||
MALLOC_WRAPPER_RETURN (ptr);
|
||||
}
|
||||
|
||||
|
||||
static inline char_p
|
||||
h5_strdup (
|
||||
const char* s1
|
||||
) {
|
||||
MALLOC_WRAPPER_ENTER (char_p, "s='%s'", s1);
|
||||
|
||||
char_p s2 = (char_p)h5_calloc (1, strlen (s1)+1 );
|
||||
if (s2 == NULL) {
|
||||
MALLOC_WRAPPER_LEAVE (
|
||||
(char_p)h5_error (H5_ERR_NOMEM, "Out of memory."));
|
||||
}
|
||||
MALLOC_WRAPPER_RETURN (strcpy (s2, s1));
|
||||
}
|
||||
h5_err_t h5_free (void* ptr);
|
||||
void_p h5_alloc (void* ptr, const size_t size);
|
||||
void_p h5_calloc (const size_t count, const size_t size);
|
||||
char_p h5_strdup (const char* s1);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user