[beast: 1/14] SFI: bcore.hh: provide diagnostics and basic macro utilities in the Bse namespace
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 1/14] SFI: bcore.hh: provide diagnostics and basic macro utilities in the Bse namespace
- Date: Thu, 23 Mar 2017 17:13:26 +0000 (UTC)
commit 93b9959beb80ca90e4a3c87b62ffcd2e7c911532
Author: Tim Janik <timj gnu org>
Date: Tue Mar 14 00:42:42 2017 +0100
SFI: bcore.hh: provide diagnostics and basic macro utilities in the Bse namespace
Signed-off-by: Tim Janik <timj gnu org>
sfi/Makefile.am | 6 +-
sfi/bcore.cc | 72 +++++++++++++++++++++++
sfi/bcore.hh | 150 ++++++++++++++++++++++++++++++++++++++++++++++++
sfi/glib-extra.cc | 3 +-
sfi/glib-extra.hh | 24 +++-----
sfi/sfi.hh | 11 +---
sfi/sficomport.cc | 6 +-
sfi/sficomwire.cc | 18 +++---
sfi/sfimemory.cc | 2 +-
sfi/sfiserial.cc | 4 +-
sfi/sfistore.cc | 2 +-
sfi/sfitypes.hh | 2 +-
sfi/sfiwrapper.cc | 36 ------------
sfi/sfiwrapper.hh | 62 ++++++-------------
sfi/tests/Makefile.am | 2 +-
sfi/tests/misctests.cc | 2 +
sfi/tests/ring.cc | 2 +
17 files changed, 279 insertions(+), 125 deletions(-)
---
diff --git a/sfi/Makefile.am b/sfi/Makefile.am
index a26aea9..b51d2c7 100644
--- a/sfi/Makefile.am
+++ b/sfi/Makefile.am
@@ -6,6 +6,7 @@ DEFS += @DEFINE__FILE_DIR__@ -DG_LOG_DOMAIN=\"SFI\" -DG_DISABLE_CONST_RET
AM_CPPFLAGS += -I$(top_srcdir)
sfi_public_headers = $(strip \
+ bcore.hh \
sfistore.hh sficomwire.hh sfifilecrawler.hh \
glib-extra.hh sfiwrapper.hh \
sfivmarshal.hh sfiglue.hh sfigluecodec.hh sfiglueproxy.hh \
@@ -17,6 +18,7 @@ sfi_public_headers = $(strip \
gbsearcharray.hh \
)
sfi_all_sources = $(strip \
+ bcore.cc \
sfistore.cc sficomwire.cc sfifilecrawler.cc \
glib-extra.cc sfiwrapper.cc sfiprimitives.cc \
sfivmarshal.cc sfiglue.cc sfigluecodec.cc sfiglueproxy.cc \
@@ -42,7 +44,7 @@ noinst_LTLIBRARIES = libsfi-@MAJOR@.la
libsfi_@MAJOR@includedir = $(bseincludedir)/sfi
libsfi_@MAJOR@include_HEADERS = $(sfi_public_headers)
libsfi_@MAJOR@_la_SOURCES = $(sfi_all_sources)
-libsfi_@MAJOR@_la_CXXFLAGS = $(AM_CXXFLAGS) $(LIBBSE_CFLAGS) -DRAPICORN_CONVENIENCE
+libsfi_@MAJOR@_la_CXXFLAGS = $(AM_CXXFLAGS) $(LIBBSE_CFLAGS) -DBSE_CONVENIENCE
libsfi_@MAJOR@_la_LIBADD = $(LIBBSE_LIBS)
#
@@ -52,7 +54,7 @@ libsfi_@MAJOR@_la_LIBADD = $(LIBBSE_LIBS)
bin_PROGRAMS = sfidl
sfidl_SOURCES = sfidl.cc
-sfidl_CXXFLAGS = $(AM_CXXFLAGS) $(LIBBSE_CFLAGS) -DRAPICORN_CONVENIENCE
+sfidl_CXXFLAGS = $(AM_CXXFLAGS) $(LIBBSE_CFLAGS) -DBSE_CONVENIENCE
sfidl_LDADD = $(LIBBSE_LIBS)
# included files
EXTRA_DIST += sfidl-generator.cc sfidl-namespace.cc sfidl-options.cc sfidl-parser.cc sfidl-factory.cc
diff --git a/sfi/bcore.cc b/sfi/bcore.cc
new file mode 100644
index 0000000..031921b
--- /dev/null
+++ b/sfi/bcore.cc
@@ -0,0 +1,72 @@
+// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
+#include "bcore.hh"
+#include <unistd.h> // _exit
+
+namespace Bse {
+using namespace Rapicorn;
+
+
+namespace Internal {
+
+bool debug_any_enabled = true; // initialized by debug_key_enabled()
+
+bool
+debug_key_enabled (const char *conditional)
+{
+ // cache $BSE_DEBUG and setup debug_any_enabled;
+ static const char *const debug_flags = [] () {
+ const char *f = getenv ("BSE_DEBUG");
+ std::string flags = !f ? "" : ":" + std::string (f) + ":";
+ char *result = new char [flags.size() + 1];
+ strcpy (result, flags.data());
+ debug_any_enabled = result && result[0];
+ return result;
+ } ();
+ // find conditional in colon-separated $BSE_DEBUG
+ if (conditional && debug_flags)
+ {
+ const char *const flag = strstr (debug_flags, conditional);
+ const int l = strlen (conditional);
+ if (flag && flag > debug_flags && flag[-1] == ':' && l)
+ {
+ if (flag[l] == ':' || // also allow =1 =yes =true =on
+ (flag[l] == '=' && (strchr ("123456789yYtT", flag[l + 1]) ||
+ strncasecmp (flag + l, "=on", 3) == 0)))
+ return true;
+ }
+ }
+ return false;
+}
+
+void RAPICORN_NORETURN
+force_abort ()
+{
+ // ensure the program halts on error conditions
+ abort();
+ _exit (-1);
+}
+
+void
+diagnostic (char kind, const std::string &message)
+{
+ const char buf[2] = { kind, 0 };
+ String prefix;
+ switch (kind) {
+ case 'W': prefix = "WARNING: "; break;
+ case 'I': prefix = "INFO: "; break;
+ case 'D': prefix = "DEBUG: "; break;
+ case ' ': prefix = ""; break;
+ case 'F':
+ prefix = program_argv0() + ": FATAL: ";
+ break;
+ default:
+ prefix = program_argv0() + ": " + buf + ": ";
+ break;
+ }
+ const char *const newline = !message.empty() && message.data()[message.size() - 1] == '\n' ? "" : "\n";
+ printerr ("%s%s%s", prefix, message, newline);
+}
+
+} // Internal
+
+} // Bse
diff --git a/sfi/bcore.hh b/sfi/bcore.hh
new file mode 100644
index 0000000..1024f50
--- /dev/null
+++ b/sfi/bcore.hh
@@ -0,0 +1,150 @@
+// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
+#ifndef __BSE_BCORE_HH__
+#define __BSE_BCORE_HH__
+
+#ifdef BSE_CONVENIENCE
+#define RAPICORN_CONVENIENCE BSE_CONVENIENCE
+#endif
+#include <rapicorn-core.hh>
+#ifdef RAPICORN_CONVENIENCE
+#undef fatal // avoid easy clashes
+#endif
+#include <sfi/glib-extra.hh>
+
+namespace Bse {
+using namespace Rapicorn;
+using Rapicorn::uint8;
+using Rapicorn::uint16;
+using Rapicorn::uint32;
+using Rapicorn::uint64;
+using Rapicorn::int8;
+using Rapicorn::int16;
+using Rapicorn::int32;
+using Rapicorn::int64;
+using Rapicorn::unichar;
+using Rapicorn::String;
+using Rapicorn::string_format;
+using Rapicorn::printout;
+using Rapicorn::printerr;
+namespace Path = Rapicorn::Path;
+
+
+// == Utility Macros ==
+#define BSE_ISLIKELY(expr) RAPICORN_ISLIKELY(expr) ///< Compiler hint that @a expr is likely to
be true.
+#define BSE_UNLIKELY(expr) RAPICORN_UNLIKELY(expr) ///< Compiler hint that @a expr is unlikely
to be true.
+#define BSE_LIKELY BSE_ISLIKELY ///< Compiler hint that @a expr is likely to
be true.
+#define BSE_ABS(a) ((a) < 0 ? -(a) : (a)) ///< Yield the absolute value of @a a.
+#define BSE_MIN(a,b) ((a) <= (b) ? (a) : (b)) ///< Yield the smaller value of @a a and @a
b.
+#define BSE_MAX(a,b) ((a) >= (b) ? (a) : (b)) ///< Yield the greater value of @a a and @a
b.
+#define BSE_CLAMP(v,mi,ma) ((v) < (mi) ? (mi) : ((v) > (ma) ? (ma) : (v))) ///< Yield @a v clamped to [
@a mi .. @a ma ].
+#define BSE_ARRAY_SIZE(array) (sizeof (array) / sizeof ((array)[0])) ///< Yield the number of C
@a array elements.
+#define BSE_ALIGN(size, base) ((base) * (((size) + (base) - 1) / (base))) ///< Round up @a size to
multiples of @a base.
+#define BSE_CPP_STRINGIFY(s) RAPICORN_CPP_STRINGIFY(s) ///< Turn @a s into a C string literal.
+#define BSE__HERE__ RAPICORN__HERE__ ///< Shorthand for a string literal containing
__FILE__ ":" __LINE__
+#define BSE_PURE RAPICORN_PURE ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_MALLOC RAPICORN_MALLOC ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_SENTINEL RAPICORN_SENTINEL ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_NORETURN RAPICORN_NORETURN ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_CONST RAPICORN_CONST ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_UNUSED RAPICORN_UNUSED ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_USED RAPICORN_USED ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_NO_INSTRUMENT RAPICORN_NO_INSTRUMENT ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_DEPRECATED RAPICORN_DEPRECATED ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_ALWAYS_INLINE RAPICORN_ALWAYS_INLINE ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_NOINLINE RAPICORN_NOINLINE ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_CONSTRUCTOR RAPICORN_CONSTRUCTOR ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html">GCC Attribute</a>.
+#define BSE_MAY_ALIAS RAPICORN_MAY_ALIAS ///< A <a
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html">GCC Attribute</a>.
+#define BSE_CLASS_NON_COPYABLE(ClassName) RAPICORN_CLASS_NON_COPYABLE (ClassName) ///< Delete copy ctor and
assignment operator.
+#define BSE_DECLARE_VLA(Type, var, count) RAPICORN_DECLARE_VLA (Type, var, count) ///< Declare a variable
length array (clang++ uses std::vector<>).
+
+// == Path Name Macros ==
+#ifdef _WIN32 // includes _WIN64
+#undef BSE_UNIX_PATHS ///< Undefined on _WIN32 and _WIN64,
defined on Unix.
+#define BSE_DOS_PATHS 1 ///< Undefined on Unix-like systems,
defined on _WIN32 and _WIN64.
+#else // !_WIN32
+#define BSE_UNIX_PATHS 1 ///< Undefined on _WIN32 and _WIN64,
defined on Unix.
+#undef BSE_DOS_PATHS ///< Undefined on Unix-like systems,
defined on _WIN32 and _WIN64.
+#endif // !_WIN32
+#define BSE_DIR_SEPARATOR RAPICORN_DIR_SEPARATOR ///< A '/' on Unix-like systems, a
'\\' on _WIN32.
+#define BSE_DIR_SEPARATOR_S RAPICORN_DIR_SEPARATOR_S ///< A "/" on Unix-like systems, a
"\\" on _WIN32.
+#define BSE_SEARCHPATH_SEPARATOR RAPICORN_SEARCHPATH_SEPARATOR ///< A ':' on Unix-like systems, a
';' on _WIN32.
+#define BSE_SEARCHPATH_SEPARATOR_S RAPICORN_SEARCHPATH_SEPARATOR_S ///< A ":" on Unix-like systems, a
";" on _WIN32.
+#define BSE_IS_ABSPATH(p) RAPICORN_IS_ABSPATH (p) ///< Checks root directory path
component, plus drive letter on _WIN32.
+
+// == Diagnostics ==
+template<class ...Args> void fatal (const char *format, const Args &...args)
RAPICORN_NORETURN;
+template<class ...Args> void warning (const char *format, const Args &...args);
+template<class ...Args> void warn (const char *format, const Args &...args);
+template<class ...Args> void info (const char *format, const Args &...args);
+template<class ...Args> inline void dump (const char *conditional, const char *format, const
Args &...args) RAPICORN_ALWAYS_INLINE;
+template<class ...Args> inline void debug (const char *conditional, const char *format, const
Args &...args) RAPICORN_ALWAYS_INLINE;
+inline bool debug_enabled (const char *conditional) RAPICORN_ALWAYS_INLINE
BSE_PURE;
+
+// == Legacy ==
+inline bool BSE_DEPRECATED bse_debug_enabled (const char *k) { return debug_enabled (k); }
+
+// == Internal Implementation Details ==
+namespace Internal {
+extern bool debug_any_enabled; //< Indicates if $BSE_DEBUG enables some debug
settings.
+bool debug_key_enabled (const char *conditional) BSE_PURE;
+void diagnostic (char kind, const std::string &message);
+void force_abort () RAPICORN_NORETURN;
+} // Internal
+
+/// Issue a printf-like message if @a conditional is enabled by $BSE_DEBUG.
+template<class ...Args> inline void RAPICORN_ALWAYS_INLINE
+dump (const char *conditional, const char *format, const Args &...args)
+{
+ if (BSE_UNLIKELY (Internal::debug_any_enabled) && Internal::debug_key_enabled (conditional))
+ Internal::diagnostic (' ', string_format (format, args...));
+}
+
+/// Issue a printf-like debugging message if @a conditional is enabled by $BSE_DEBUG.
+template<class ...Args> inline void RAPICORN_ALWAYS_INLINE
+debug (const char *conditional, const char *format, const Args &...args)
+{
+ if (BSE_UNLIKELY (Internal::debug_any_enabled) && Internal::debug_key_enabled (conditional))
+ Internal::diagnostic ('D', string_format (format, args...));
+}
+
+/// Check if @a conditional is enabled by $BSE_DEBUG.
+inline bool RAPICORN_ALWAYS_INLINE BSE_PURE
+debug_enabled (const char *conditional)
+{
+ if (BSE_UNLIKELY (Internal::debug_any_enabled))
+ return Internal::debug_key_enabled (conditional);
+ return false;
+}
+
+/// Issue a printf-like message and abort the program, this function will not return.
+template<class ...Args> void RAPICORN_NORETURN
+fatal (const char *format, const Args &...args)
+{
+ Internal::diagnostic ('F', string_format (format, args...));
+ Internal::force_abort();
+}
+
+/// Issue a printf-like warning message.
+template<class ...Args> void RAPICORN_NORETURN
+warn (const char *format, const Args &...args)
+{
+ Internal::diagnostic ('W', string_format (format, args...));
+}
+
+/// Issue a printf-like warning message.
+template<class ...Args> void RAPICORN_NORETURN
+warning (const char *format, const Args &...args)
+{
+ Internal::diagnostic ('W', string_format (format, args...));
+}
+
+/// Issue an informative printf-like message.
+template<class ...Args> void RAPICORN_NORETURN
+info (const char *format, const Args &...args)
+{
+ Internal::diagnostic ('I', string_format (format, args...));
+}
+
+} // Bse
+
+#endif // __BSE_BCORE_HH__
diff --git a/sfi/glib-extra.cc b/sfi/glib-extra.cc
index 72e1bc0..8f4d6be 100644
--- a/sfi/glib-extra.cc
+++ b/sfi/glib-extra.cc
@@ -1,7 +1,6 @@
// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
+#include "bcore.hh"
#include <string.h>
-#include "glib-extra.hh"
-
void
g_object_disconnect_any (gpointer object,
diff --git a/sfi/glib-extra.hh b/sfi/glib-extra.hh
index 5f5112f..3193e89 100644
--- a/sfi/glib-extra.hh
+++ b/sfi/glib-extra.hh
@@ -4,11 +4,9 @@
#include <glib.h>
#include <glib-object.h>
-#include <rapicorn-core.hh> // for Rapicorn::string_format
+#include <string>
-using Rapicorn::printout;
-using Rapicorn::printerr;
-using Rapicorn::string_format;
+typedef int64_t int64; ///< A 64-bit unsigned integer, use PRI*64 in format strings.
#if (GLIB_SIZEOF_LONG > 4)
#define G_HASH_LONG(l) ((l) + ((l) >> 32))
@@ -168,11 +166,11 @@ g_bit_matrix_change (GBitMatrix *matrix,
guint y,
gboolean bit_set)
{
- guint32 cons, index, shift;
- RAPICORN_ASSERT_RETURN (matrix && x < matrix->width && y < matrix->height);
- cons = y * matrix->width + x;
- index = cons >> 5; /* / 32 */
- shift = cons & 0x1f; /* % 32 */
+ if (!(matrix && x < matrix->width && y < matrix->height))
+ return;
+ const guint32 cons = y * matrix->width + x;
+ const guint32 index = cons >> 5; /* / 32 */
+ const guint32 shift = cons & 0x1f; /* % 32 */
if (bit_set)
matrix->bits[index] |= 1 << shift;
else
@@ -330,10 +328,6 @@ constexpr GConnectFlags operator~ (GConnectFlags s1) { return
// these definitions need to move into bse/utils or similar
namespace Bse {
-// import helpers from Rapicorn
-using Rapicorn::String;
-namespace Path = Rapicorn::Path;
-
// == INSTALLPATH ==
// See also configure.ac, this function is here because beast and all libs include this file.
enum InstallpathType {
@@ -359,8 +353,8 @@ enum InstallpathType {
INSTALLPATH_PYBEASTDIR,
};
/// Provide installation directories and searchpaths for various types of data.
-String installpath (InstallpathType installpath_type);
-void installpath_override (const String &topdir);
+std::string installpath (InstallpathType installpath_type);
+void installpath_override (const std::string &topdir);
/// Provide a string containing the BSE library version number.
std::string version ();
diff --git a/sfi/sfi.hh b/sfi/sfi.hh
index 1985ace..2b942ec 100644
--- a/sfi/sfi.hh
+++ b/sfi/sfi.hh
@@ -4,19 +4,11 @@
// == Rapicorn Imports ==
-#include <rapicorn-core.hh> // We move to Rapicorn core for low level stuff
-using Rapicorn::printerr;
-using Rapicorn::printout;
-using Rapicorn::string_format;
-using Rapicorn::Any;
-typedef std::string String;
+#include <sfi/sfiwrapper.hh> // Introduces bcore.hh and Rapicorn
namespace Sfi {
using namespace Rapicorn;
} // Sfi
-namespace Bse {
-using namespace Rapicorn;
-} // Bse
/* no bin-compat: #include <sfi/sficomwire.hh> */
#include <sfi/sficomport.hh>
@@ -38,7 +30,6 @@ using namespace Rapicorn;
#include <sfi/sfivalues.hh>
#include <sfi/sfivisitors.hh>
#include <sfi/sfivmarshal.hh>
-#include <sfi/sfiwrapper.hh>
#endif /* __SFI_H__ */
diff --git a/sfi/sficomport.cc b/sfi/sficomport.cc
index 520f8e8..3eb809d 100644
--- a/sfi/sficomport.cc
+++ b/sfi/sficomport.cc
@@ -453,13 +453,13 @@ com_port_read_pending (SfiComPort *port)
port->rbuffer.header[2] != ((SFI_COM_PORT_MAGIC >> 8) & 0xff) ||
port->rbuffer.header[3] != (SFI_COM_PORT_MAGIC & 0xff))
{
- printerr ("ComPort:%s: received data with invalid magic", port->ident);
+ Bse::printerr ("ComPort:%s: received data with invalid magic", port->ident);
return FALSE;
}
/* check length */
if (port->rbuffer.dlen < 1 || port->rbuffer.dlen > 10 * 1024 * 1024)
{
- printerr ("ComPort:%s: received data with excessive length", port->ident);
+ Bse::printerr ("ComPort:%s: received data with excessive length", port->ident);
return FALSE;
}
}
@@ -497,7 +497,7 @@ com_port_scanner_msg (GScanner *scanner,
gboolean error)
{
SfiComPort *port = (SfiComPort*) scanner->user_data;
- printerr ("ComPort:%s: while processing data: %s", port->ident, message);
+ Bse::printerr ("ComPort:%s: while processing data: %s", port->ident, message);
}
static void
diff --git a/sfi/sficomwire.cc b/sfi/sficomwire.cc
index 4bae125..1925f53 100644
--- a/sfi/sficomwire.cc
+++ b/sfi/sficomwire.cc
@@ -235,14 +235,14 @@ wire_receive (SfiComWire *wire)
p = get_uint32 (p, &type);
if (magic != BSE_MAGIC_BSEm)
{
- printerr ("%s: message with invalid magic: 0x%08x\n", wire->ident, magic);
+ Bse::printerr ("%s: message with invalid magic: 0x%08x\n", wire->ident, magic);
wire->remote_input_broke = TRUE;
wire->ibp = wire->ibuffer;
}
else if (mlength <= mheader_length || mlength >= max_mlength)
{
- printerr ("%s: message (type=%u) with invalid length: %u < %u < %u\n",
- wire->ident, type, mheader_length, mlength, max_mlength);
+ Bse::printerr ("%s: message (type=%u) with invalid length: %u < %u < %u\n",
+ wire->ident, type, mheader_length, mlength, max_mlength);
wire->remote_input_broke = TRUE;
wire->ibp = wire->ibuffer;
}
@@ -271,7 +271,7 @@ wire_receive (SfiComWire *wire)
wire->iresults = g_list_prepend (wire->iresults, msg);
else
{
- printerr ("%s: ignoring spurious result (request=%u): %s\n", wire->ident, msg->request,
msg->message);
+ Bse::printerr ("%s: ignoring spurious result (request=%u): %s\n", wire->ident,
msg->request, msg->message);
free_msg (msg);
}
}
@@ -283,8 +283,8 @@ wire_receive (SfiComWire *wire)
case SFI_COM_MSG_RESERVED2:
case SFI_COM_MSG_RESERVED3:
case SFI_COM_MSG_RESERVED4:
- printerr ("%s: ignoring message with unknown type: %u\n",
- wire->ident, type);
+ Bse::printerr ("%s: ignoring message with unknown type: %u\n",
+ wire->ident, type);
p += 4; /* request */
p += strl;
n = wire->ibp - p;
@@ -292,7 +292,7 @@ wire_receive (SfiComWire *wire)
wire->ibp = wire->ibuffer + n;
break;
default:
- printerr ("%s: message with invalid type: %u\n",
+ Bse::printerr ("%s: message with invalid type: %u\n",
wire->ident, type);
wire->remote_input_broke = TRUE;
wire->ibp = wire->ibuffer;
@@ -466,7 +466,7 @@ sfi_com_wire_receive_request (SfiComWire *wire,
if (msg->request == 0)
{
/* 0-requests are low-level messages, currently unhandled */
- printerr ("%s: ignoring message with request_id=0\n", wire->ident);
+ Bse::printerr ("%s: ignoring message with request_id=0\n", wire->ident);
free_msg (msg);
return sfi_com_wire_receive_request (wire, request_p);
}
@@ -531,7 +531,7 @@ wire_default_dispatch (gpointer data,
const gchar *request_msg,
SfiComWire *wire)
{
- printerr ("%s: unhandled request (id=%u): %s\n", wire->ident, request, request_msg);
+ Bse::printerr ("%s: unhandled request (id=%u): %s\n", wire->ident, request, request_msg);
sfi_com_wire_discard_request (wire, request);
return TRUE;
}
diff --git a/sfi/sfimemory.cc b/sfi/sfimemory.cc
index 4d1da77..e0542bb 100644
--- a/sfi/sfimemory.cc
+++ b/sfi/sfimemory.cc
@@ -110,7 +110,7 @@ sfi_free_memblock (gsize block_size,
cmem -= DBG8_SIZE;
debug_size = (gsize*) cmem;
if (block_size != *debug_size)
- printerr ("%s: in memory block at (%p): block_size=%zd != *debug_size=%zd\n", G_STRLOC, mem, block_size,
*debug_size);
+ Bse::printerr ("%s: in memory block at (%p): block_size=%zd != *debug_size=%zd\n", G_STRLOC, mem,
block_size, *debug_size);
low_free (block_size + DBG8_SIZE, cmem);
}
void
diff --git a/sfi/sfiserial.cc b/sfi/sfiserial.cc
index 7499c7d..efa74fb 100644
--- a/sfi/sfiserial.cc
+++ b/sfi/sfiserial.cc
@@ -89,7 +89,7 @@ string_to_cescape (const String &str) // FIXME: move
{
uint8 d = *it;
if (d < 32 || d > 126 || d == '?')
- buffer += string_format ("\\%03o", d);
+ buffer += Bse::string_format ("\\%03o", d);
else if (d == '\\')
buffer += "\\\\";
else if (d == '"')
@@ -959,6 +959,6 @@ sfi_value_store_stderr (const GValue *value)
{
GString *gstring = g_string_new ("");
sfi_value_store_typed (value, gstring);
- printerr ("((GValue*)%p)=%s\n", value, gstring->str);
+ Bse::printerr ("((GValue*)%p)=%s\n", value, gstring->str);
g_string_free (gstring, TRUE);
}
diff --git a/sfi/sfistore.cc b/sfi/sfistore.cc
index c749d79..17a5653 100644
--- a/sfi/sfistore.cc
+++ b/sfi/sfistore.cc
@@ -329,7 +329,7 @@ sfi_wstore_flush_fd (SfiWStore *wstore,
while (foff < 0 && errno == EINTR);
if (foff < 0 && errno)
return -errno;
- std::string str = string_format ("0x%08x 0x%08x", guint32 (bblock->offset - binary_offset), guint32
(bblock->length));
+ std::string str = Bse::string_format ("0x%08x 0x%08x", guint32 (bblock->offset - binary_offset),
guint32 (bblock->length));
do
l = write (fd, str.data(), str.size());
while (l < 0 && errno == EINTR);
diff --git a/sfi/sfitypes.hh b/sfi/sfitypes.hh
index 923cf30..3a4171a 100644
--- a/sfi/sfitypes.hh
+++ b/sfi/sfitypes.hh
@@ -2,7 +2,7 @@
#ifndef __SFI_TYPES_H__
#define __SFI_TYPES_H__
-#include <sfi/glib-extra.hh>
+#include <sfi/bcore.hh>
#include <sfi/sfiwrapper.hh>
/* --- Sfi typedefs --- */
diff --git a/sfi/sfiwrapper.cc b/sfi/sfiwrapper.cc
index 0b529fe..f43533f 100644
--- a/sfi/sfiwrapper.cc
+++ b/sfi/sfiwrapper.cc
@@ -5,42 +5,6 @@
#include <rapicorn-test.hh>
#include <errno.h>
-namespace Bse {
-
-/// Caching flag to inhibit useless bse_debug() calls.
-bool volatile _cached_bse_debug = true;
-
-/// Issue a debugging message, configurable via #$BSE_DEBUG.
-void
-bse_debug (const char *key, const char *file_path, const int line, const String &message)
-{
- envkey_debug_message ("BSE_DEBUG", key, file_path, line, message, &_cached_bse_debug);
-}
-
-#ifdef DOXYGEN
-/** Check if debugging is enabled for @a key.
- * This function checks if #$BSE_DEBUG contains @a key or "all" and returns true
- * if debugging is enabled for the given key. The @a key argument may be NULL in which
- * case the function checks if general debugging is enabled.
- */
-bool bse_debug_enabled (const char *key);
-#endif // DOXYGEN
-
-bool
-_bse_debug_enabled (const char *key)
-{
- return envkey_debug_check ("BSE_DEBUG", key, &_cached_bse_debug);
-}
-
-/// Check if the feature toggle @a key is enabled in #$BSE_FLIPPER.
-bool
-bse_flipper_check (const char *key)
-{
- return envkey_flipper_check ("BSE_FLIPPER", key);
-}
-
-} // Bse
-
/* --- initialization --- */
void
sfi_init (int *argcp, char **argv, const Bse::StringVector &args)
diff --git a/sfi/sfiwrapper.hh b/sfi/sfiwrapper.hh
index 8947a1d..d325dfb 100644
--- a/sfi/sfiwrapper.hh
+++ b/sfi/sfiwrapper.hh
@@ -1,43 +1,27 @@
// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
#ifndef __SFI_WRAPPER_H__
#define __SFI_WRAPPER_H__
-#include <stdbool.h>
-#include <sfi/glib-extra.hh>
-#include <rapicorn-core.hh>
-namespace Bse {
-using namespace Rapicorn;
-
-// == Likelyness Hinting ==
-#define BSE_ISLIKELY(expr) RAPICORN_ISLIKELY(expr) ///< Compiler hint that @a expr is likely to be true.
-#define BSE_UNLIKELY(expr) RAPICORN_UNLIKELY(expr) ///< Compiler hint that @a expr is unlikely to be
true.
-#define BSE_LIKELY BSE_ISLIKELY ///< Compiler hint that @a expr is likely to be true.
-
-// == Debugging ==
-/// Issue a general purpose debugging message, configurable via #$BSE_DEBUG.
-#define BSE_DEBUG(...) do { if (BSE_UNLIKELY (Bse::_cached_bse_debug)) Bse::bse_debug (NULL,
RAPICORN_PRETTY_FILE, __LINE__, Rapicorn::string_format (__VA_ARGS__)); } while (0)
-/// Issue a debugging message if debugging for @a key is enabled via #$BSE_DEBUG.
-#define BSE_KEY_DEBUG(key,...) do { if (BSE_UNLIKELY (Bse::_cached_bse_debug)) Bse::bse_debug (key,
RAPICORN_PRETTY_FILE, __LINE__, Rapicorn::string_format (__VA_ARGS__)); } while (0)
-extern bool volatile _cached_bse_debug;
-void bse_debug (const char*, const char*, int, const String&);
-bool _bse_debug_enabled (const char *key);
-inline bool bse_debug_enabled (const char *key = NULL) { return BSE_UNLIKELY (_cached_bse_debug) &&
_bse_debug_enabled (key); }
-bool bse_flipper_check (const char *key);
-
-} // Bse
-
-// sfiwrapper.h is a thin C language wrapper around C++ features
-
-/* --- short integer types --- */
-using Rapicorn::uint8;
-using Rapicorn::uint16;
-using Rapicorn::uint32;
-using Rapicorn::uint64;
-using Rapicorn::int8;
-using Rapicorn::int16;
-using Rapicorn::int32;
-using Rapicorn::int64;
-using Rapicorn::unichar;
+#include <sfi/bcore.hh>
+
+#ifdef BSE_CONVENIENCE
+using Bse::uint8;
+using Bse::uint16;
+using Bse::uint32;
+using Bse::uint64;
+using Bse::int8;
+using Bse::int16;
+using Bse::int32;
+using Bse::int64;
+using Bse::unichar;
+#endif // BSE_CONVENIENCE
+
+/* --- macros --- */
+#define sfi_error(...) Bse::fatal (__VA_ARGS__)
+#define sfi_warning(...) Bse::warning (__VA_ARGS__)
+#define sfi_info(...) Bse::info (__VA_ARGS__)
+#define sfi_diag(...) Bse::warning (__VA_ARGS__)
+#define BSE_KEY_DEBUG(...) Bse::debug (__VA_ARGS__)
/* --- initialization --- */
typedef struct
@@ -48,12 +32,6 @@ typedef struct
} SfiInitValue;
void sfi_init (int *argcp, char **argv, const Bse::StringVector &args = Bse::StringVector());
-/* --- messaging --- */
-#define sfi_error(...) RAPICORN_CRITICAL (__VA_ARGS__)
-#define sfi_warning(...) RAPICORN_CRITICAL (__VA_ARGS__)
-#define sfi_info(...) BSE_DEBUG (__VA_ARGS__)
-#define sfi_diag(...) BSE_DEBUG (__VA_ARGS__)
-
/* --- url handling --- */
void sfi_url_show (const char *url);
diff --git a/sfi/tests/Makefile.am b/sfi/tests/Makefile.am
index 4fc4d4f..2715f36 100644
--- a/sfi/tests/Makefile.am
+++ b/sfi/tests/Makefile.am
@@ -3,7 +3,7 @@ include $(top_srcdir)/Makefile.decl
AM_CPPFLAGS += -I$(top_srcdir) -I$(top_builddir) -I.
DEFS += @DEFINE__FILE_DIR__@ -DG_LOG_DOMAIN='"$(basename $(@F))"' -DPARANOID #
-DG_DISABLE_CONST_RETURNS
-AM_CXXFLAGS += $(SFI_CPPFLAGS) $(RAPICORN_CFLAGS) -DRAPICORN_CONVENIENCE
+AM_CXXFLAGS += $(SFI_CPPFLAGS) $(RAPICORN_CFLAGS) -DBSE_CONVENIENCE
noinst_PROGRAMS = $(ALLTESTS)
progs_ldadd = $(top_builddir)/sfi/libsfi-@MAJOR@.la $(LIBBSE_LIBS)
diff --git a/sfi/tests/misctests.cc b/sfi/tests/misctests.cc
index 248d426..ac28386 100644
--- a/sfi/tests/misctests.cc
+++ b/sfi/tests/misctests.cc
@@ -8,6 +8,8 @@
#include <signal.h> /* G_BREAKPOINT() */
#include <math.h>
+using namespace Bse;
+
/* provide IDL type initializers */
#define sfidl_pspec_Real(group, name, nick, blurb, dflt, min, max, step, hints) \
sfi_pspec_real (name, nick, blurb, dflt, min, max, step, hints)
diff --git a/sfi/tests/ring.cc b/sfi/tests/ring.cc
index c3f9523..494aa4d 100644
--- a/sfi/tests/ring.cc
+++ b/sfi/tests/ring.cc
@@ -3,6 +3,8 @@
#include <sfi/sfitests.hh>
#include <sfi/sfi.hh>
+using namespace Bse;
+
static void
print_ring_ints (SfiRing *ring)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]