aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_common.h
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2020-07-21 12:30:37 +0200
committert3sserakt <t3ss@posteo.de>2020-07-21 12:30:37 +0200
commit5fa1c7dc809aebb55ef062cb3a2757c54eb6b7e7 (patch)
treec26167460724fea683ef51a88ffd93d1fa830412 /src/include/gnunet_common.h
parent17d84245fdfeeb1a6da4ffb97898903cb55f702c (diff)
parent7f4ddbcab8598e3d5e29c23ce883cdfa664408f1 (diff)
downloadgnunet-5fa1c7dc809aebb55ef062cb3a2757c54eb6b7e7.tar.gz
gnunet-5fa1c7dc809aebb55ef062cb3a2757c54eb6b7e7.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r--src/include/gnunet_common.h85
1 files changed, 42 insertions, 43 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 34f419a49..91d4a5bd4 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -345,7 +345,9 @@ struct GNUNET_AsyncScopeSave
345 * #GNUNET_NO to stop iteration with no error, 345 * #GNUNET_NO to stop iteration with no error,
346 * #GNUNET_SYSERR to abort iteration with error! 346 * #GNUNET_SYSERR to abort iteration with error!
347 */ 347 */
348typedef int (*GNUNET_FileNameCallback) (void *cls, const char *filename); 348typedef int
349(*GNUNET_FileNameCallback) (void *cls,
350 const char *filename);
349 351
350 352
351/** 353/**
@@ -353,7 +355,8 @@ typedef int (*GNUNET_FileNameCallback) (void *cls, const char *filename);
353 * 355 *
354 * @param cls Closure. 356 * @param cls Closure.
355 */ 357 */
356typedef void (*GNUNET_ContinuationCallback) (void *cls); 358typedef void
359(*GNUNET_ContinuationCallback) (void *cls);
357 360
358 361
359/** 362/**
@@ -368,10 +371,11 @@ typedef void (*GNUNET_ContinuationCallback) (void *cls);
368 * @param data_size 371 * @param data_size
369 * Size of @a data. 372 * Size of @a data.
370 */ 373 */
371typedef void (*GNUNET_ResultCallback) (void *cls, 374typedef void
372 int64_t result_code, 375(*GNUNET_ResultCallback) (void *cls,
373 const void *data, 376 int64_t result_code,
374 uint16_t data_size); 377 const void *data,
378 uint16_t data_size);
375 379
376 380
377/* ****************************** logging ***************************** */ 381/* ****************************** logging ***************************** */
@@ -453,11 +457,11 @@ __attribute__ ((format (printf, 2, 3)));
453 __extension__ ({ \ 457 __extension__ ({ \
454 int _gnunet_boolean_var_; \ 458 int _gnunet_boolean_var_; \
455 if (expr) \ 459 if (expr) \
456 _gnunet_boolean_var_ = 1; \ 460 _gnunet_boolean_var_ = 1; \
457 else \ 461 else \
458 _gnunet_boolean_var_ = 0; \ 462 _gnunet_boolean_var_ = 0; \
459 _gnunet_boolean_var_; \ 463 _gnunet_boolean_var_; \
460 }) 464 })
461#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1)) 465#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 1))
462#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0)) 466#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR (expr), 0))
463#else 467#else
@@ -495,12 +499,12 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
495 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 499 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
496 { \ 500 { \
497 if (GN_UNLIKELY (log_call_enabled == -1)) \ 501 if (GN_UNLIKELY (log_call_enabled == -1)) \
498 log_call_enabled = \ 502 log_call_enabled = \
499 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 503 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
500 (comp), \ 504 (comp), \
501 __FILE__, \ 505 __FILE__, \
502 __FUNCTION__, \ 506 __FUNCTION__, \
503 __LINE__); \ 507 __LINE__); \
504 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 508 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
505 { \ 509 { \
506 GNUNET_log_skip (-1, GNUNET_NO); \ 510 GNUNET_log_skip (-1, GNUNET_NO); \
@@ -508,7 +512,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
508 else \ 512 else \
509 { \ 513 { \
510 if (GN_UNLIKELY (log_call_enabled)) \ 514 if (GN_UNLIKELY (log_call_enabled)) \
511 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ 515 GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \
512 } \ 516 } \
513 } \ 517 } \
514 } while (0) 518 } while (0)
@@ -521,12 +525,12 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
521 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \ 525 ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) \
522 { \ 526 { \
523 if (GN_UNLIKELY (log_call_enabled == -1)) \ 527 if (GN_UNLIKELY (log_call_enabled == -1)) \
524 log_call_enabled = \ 528 log_call_enabled = \
525 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \ 529 GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), \
526 NULL, \ 530 NULL, \
527 __FILE__, \ 531 __FILE__, \
528 __FUNCTION__, \ 532 __FUNCTION__, \
529 __LINE__); \ 533 __LINE__); \
530 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \ 534 if (GN_UNLIKELY (GNUNET_get_log_skip () > 0)) \
531 { \ 535 { \
532 GNUNET_log_skip (-1, GNUNET_NO); \ 536 GNUNET_log_skip (-1, GNUNET_NO); \
@@ -534,7 +538,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
534 else \ 538 else \
535 { \ 539 { \
536 if (GN_UNLIKELY (log_call_enabled)) \ 540 if (GN_UNLIKELY (log_call_enabled)) \
537 GNUNET_log_nocheck ((kind), __VA_ARGS__); \ 541 GNUNET_log_nocheck ((kind), __VA_ARGS__); \
538 } \ 542 } \
539 } \ 543 } \
540 } while (0) 544 } while (0)
@@ -766,6 +770,12 @@ GNUNET_e2s2 (const struct GNUNET_CRYPTO_EcdhePublicKey *p);
766 770
767 771
768/** 772/**
773 * Forward declaration to make compiler happy depending on include order.
774 */
775struct GNUNET_PeerIdentity;
776
777
778/**
769 * @ingroup logging 779 * @ingroup logging
770 * Convert a peer identity to a string (for printing debug messages). 780 * Convert a peer identity to a string (for printing debug messages).
771 * This is one of the very few calls in the entire API that is 781 * This is one of the very few calls in the entire API that is
@@ -1271,6 +1281,7 @@ GNUNET_is_zero_ (const void *a,
1271#define GNUNET_malloc_large(size) \ 1281#define GNUNET_malloc_large(size) \
1272 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__) 1282 GNUNET_xmalloc_unchecked_ (size, __FILE__, __LINE__)
1273 1283
1284
1274/** 1285/**
1275 * @ingroup memory 1286 * @ingroup memory
1276 * Wrapper around realloc. Reallocates size bytes of memory. 1287 * Wrapper around realloc. Reallocates size bytes of memory.
@@ -1283,6 +1294,7 @@ GNUNET_is_zero_ (const void *a,
1283#define GNUNET_realloc(ptr, size) \ 1294#define GNUNET_realloc(ptr, size) \
1284 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__) 1295 GNUNET_xrealloc_ (ptr, size, __FILE__, __LINE__)
1285 1296
1297
1286/** 1298/**
1287 * @ingroup memory 1299 * @ingroup memory
1288 * Wrapper around free. Frees the memory referred to by ptr. 1300 * Wrapper around free. Frees the memory referred to by ptr.
@@ -1290,40 +1302,27 @@ GNUNET_is_zero_ (const void *a,
1290 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free_nz. 1302 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free_nz.
1291 * 1303 *
1292 * @param ptr location where to free the memory. ptr must have 1304 * @param ptr location where to free the memory. ptr must have
1293 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. 1305 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed.
1294 */ 1306 */
1295#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__) 1307#define GNUNET_free_nz(ptr) GNUNET_xfree_ (ptr, __FILE__, __LINE__)
1296 1308
1309
1297/** 1310/**
1298 * @ingroup memory 1311 * @ingroup memory
1299 * Wrapper around free. Frees the memory referred to by ptr and sets ptr to NULL. 1312 * Wrapper around free. Frees the memory referred to by ptr and sets ptr to NULL.
1300 * Note that it is generally better to free memory that was 1313 * Note that it is generally better to free memory that was
1301 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free. 1314 * allocated with #GNUNET_array_grow using #GNUNET_array_grow(mem, size, 0) instead of #GNUNET_free.
1302 * 1315 *
1316 * @a ptr will be set to NULL. Use #GNUNET_free_nz() if @a ptr is not an L-value.
1317 *
1303 * @param ptr location where to free the memory. ptr must have 1318 * @param ptr location where to free the memory. ptr must have
1304 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. 1319 * been returned by #GNUNET_strdup, #GNUNET_strndup, #GNUNET_malloc or #GNUNET_array_grow earlier. NULL is allowed.
1305 */ 1320 */
1306#define GNUNET_free(ptr) do { \ 1321#define GNUNET_free(ptr) do { \
1307 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \ 1322 GNUNET_xfree_ (ptr, __FILE__, __LINE__); \
1308 ptr = NULL; \ 1323 ptr = NULL; \
1309} while (0) 1324} while (0)
1310 1325
1311/**
1312 * @ingroup memory
1313 * Free the memory pointed to by ptr if ptr is not NULL.
1314 * Equivalent to `if (NULL != ptr) GNUNET_free(ptr)`.
1315 *
1316 * @param ptr the location in memory to free
1317 */
1318#define GNUNET_free_non_null(ptr) \
1319 do \
1320 { \
1321 void *__x__ = ptr; \
1322 if (NULL != __x__) \
1323 { \
1324 GNUNET_free (__x__); \
1325 } \
1326 } while (0)
1327 1326
1328/** 1327/**
1329 * @ingroup memory 1328 * @ingroup memory