wireshark.h: Remove wmem dependency.

Start smaller. Remove the return macros from wslog.h because
that pulls in a wmem dependency and the interface is not very
stable yet.
This commit is contained in:
João Valverde 2021-10-22 07:30:31 +01:00 committed by Wireshark GitLab Utility
parent 1acae21bcd
commit 8c9019a155
5 changed files with 51 additions and 37 deletions

View File

@ -44,7 +44,6 @@
#include <ws_symbol_export.h>
#include <ws_version.h>
#include <wsutil/wmem/wmem.h>
#include <wsutil/ws_assert.h>
#include <wsutil/wslog.h>

View File

@ -77,6 +77,7 @@ set(WSUTIL_PUBLIC_HEADERS
ws_mempbrk_int.h
ws_pipe.h
ws_roundup.h
ws_return.h
wsgcrypt.h
wsjson.h
wslog.h

View File

@ -21,6 +21,7 @@
#include <wsutil/wslog.h>
#include <wsutil/inet_addr.h>
#include <wsutil/pint.h>
#include <wsutil/ws_return.h>
/*
* If a user _does_ pass in a too-small buffer, this is probably

46
wsutil/ws_return.h Normal file
View File

@ -0,0 +1,46 @@
/*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __WS_RETURN_H__
#define __WS_RETURN_H__
#include <wsutil/wslog.h>
#include <wsutil/wmem/wmem.h>
#define ws_warn_zero_len() ws_warning("Zero length passed to %s", __func__)
#define ws_warn_null_ptr() ws_warning("Null pointer passed to %s", __func__)
#define ws_return_str_if_zero(scope, len) \
do { \
if (!(len)) { \
ws_warn_zero_len(); \
return wmem_strdup(scope, "(zero length)"); \
} \
} while (0)
#define ws_return_str_if_null(scope, ptr) \
do { \
if (!(ptr)) { \
ws_warn_null_ptr(); \
return wmem_strdup(scope, "(null pointer)"); \
} \
} while (0)
#define ws_return_ptr_if_null(ptr, val) \
do { \
if (!(ptr)) { \
ws_warn_null_ptr(); \
return (val); \
} \
} while (0)
#endif /* WS_RETURN_H_ */

View File

@ -11,16 +11,15 @@
#ifndef __WSLOG_H__
#define __WSLOG_H__
#include <glib.h>
#include <stdio.h>
#include <time.h>
#include <stdarg.h>
#include <glib.h>
#include <wireshark.h>
#include <ws_symbol_export.h>
#include <ws_attributes.h>
#include <ws_log_defs.h>
#include <wsutil/wmem/wmem.h>
#ifdef WS_LOG_DOMAIN
#define _LOG_DOMAIN WS_LOG_DOMAIN
#else
@ -297,38 +296,6 @@ void ws_logv_full(const char *domain, enum ws_log_level level,
#define ws_noisy(...) _LOG_DEBUG(LOG_LEVEL_NOISY, __VA_ARGS__)
#define ws_warn_zero_len() ws_warning("Zero length passed to %s", __func__)
#define ws_warn_null_ptr() ws_warning("Null pointer passed to %s", __func__)
#define ws_return_str_if_zero(scope, len) \
do { \
if (!(len)) { \
ws_warn_zero_len(); \
return wmem_strdup(scope, "(zero length)"); \
} \
} while (0)
#define ws_return_str_if_null(scope, ptr) \
do { \
if (!(ptr)) { \
ws_warn_null_ptr(); \
return wmem_strdup(scope, "(null pointer)"); \
} \
} while (0)
#define ws_return_ptr_if_null(ptr, val) \
do { \
if (!(ptr)) { \
ws_warn_null_ptr(); \
return (val); \
} \
} while (0)
/** This function is called to log a buffer (bytes array).
*
* Accepts an optional 'msg' argument to provide a description.