if (strcmp (name, BOOLEAN_PREFIX_EXTERNAL[i].name) == 0)
return BOOLEAN_PREFIX_EXTERNAL[i].prefix;
- fprintf (stderr, "Internal error: No prefix exists for '%s'\n", name);
- exit (1);
+ INTERNAL_ERROR ("No prefix exists for '%s'\n", name);
return "";
}
{
char *header;
- if (message->parsing_started ) {
- fprintf (stderr, "Error: notmuch_message_file_restrict_headers called after parsing has started\n");
- exit (1);
- }
+ if (message->parsing_started)
+ INTERNAL_ERROR ("notmuch_message_file_restrict_headers called after parsing has started");
while (1) {
header = va_arg (va_headers, char*);
! g_hash_table_lookup_extended (message->headers,
header_desired, NULL, NULL))
{
- fprintf (stderr,
- "Internal error: Attempt to get header \"%s\" which was not\n"
- "included in call to notmuch_message_file_restrict_headers\n",
- header_desired);
- exit (1);
+ INTERNAL_ERROR ("Attempt to get header \"%s\" which was not\n"
+ "included in call to notmuch_message_file_restrict_headers\n",
+ header_desired);
}
return NULL;
if (private_status >= (notmuch_private_status_t) NOTMUCH_STATUS_LAST_STATUS)
{
- fprintf (stderr, "Internal error: Failed to find document immediately after adding it.\n");
- exit (1);
+ INTERNAL_ERROR ("Failed to find document immediately after adding it.\n");
}
*status = (notmuch_status_t) private_status;
i.skip_to (_find_prefix ("id"));
if (i == message->doc.termlist_end ()) {
- fprintf (stderr, "Internal error: Message with document ID of %d has no message ID.\n",
- message->doc_id);
- exit (1);
+ INTERNAL_ERROR ("Message with document ID of %d has no message ID.\n",
+ message->doc_id);
}
message->message_id = talloc_strdup (message, (*i).c_str () + 1);
status = _notmuch_message_add_term (message, "tag", tag);
if (status) {
- fprintf (stderr, "Internal error: _notmuch_message_add_term return unexpected value: %d\n",
- status);
- exit (1);
+ INTERNAL_ERROR ("_notmuch_message_add_term return unexpected value: %d\n",
+ status);
}
_notmuch_message_sync (message);
status = _notmuch_message_remove_term (message, "tag", tag);
if (status) {
- fprintf (stderr, "Internal error: _notmuch_message_remove_term return unexpected value: %d\n",
- status);
- exit (1);
+ INTERNAL_ERROR ("_notmuch_message_remove_term return unexpected value: %d\n",
+ status);
}
_notmuch_message_sync (message);
#define COMPILE_TIME_ASSERT(pred) ((void)sizeof(char[1 - 2*!(pred)]))
+/* There's no point in continuing when we've detected that we've done
+ * something wrong internally (as opposed to the user passing in a
+ * bogus value).
+ *
+ * Note that __location__ comes from talloc.h.
+ */
+#define INTERNAL_ERROR(format, ...) \
+ do { \
+ fprintf(stderr, \
+ "Internal error: " format " (%s)\n", \
+ ##__VA_ARGS__, __location__); \
+ exit (1); \
+ } while (0)
+
/* Thanks to Andrew Tridgell's (SAMBA's) talloc for this definition of
* unlikely. The talloc source code comes to us via the GNU LGPL v. 3.
*/
#include <glib.h> /* g_strdup_printf */
+/* There's no point in continuing when we've detected that we've done
+ * something wrong internally (as opposed to the user passing in a
+ * bogus value).
+ *
+ * Note that __location__ comes from talloc.h.
+ */
+#define INTERNAL_ERROR(format, ...) \
+ do { \
+ fprintf(stderr, \
+ "Internal error: " format " (%s)\n", \
+ ##__VA_ARGS__, __location__); \
+ exit (1); \
+ } while (0)
+
#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
typedef int (*command_function_t) (int argc, char *argv[]);
ret = status;
goto DONE;
default:
- fprintf (stderr, "Internal error: add_message returned unexpected value: %d\n", status);
- ret = status;
+ INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
goto DONE;
}
if (state->processed_files % 1000 == 0)
if (message == NULL &&
status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
{
- fprintf (stderr, "Internal error: a results iterator contains a non-existent document ID.\n");
- exit (1);
+ INTERNAL_ERROR ("a results iterator contains a non-existent document ID.\n");
}
return message;
char *error = xmalloc (error_size);
regerror (rerr, preg, error, error_size);
- fprintf (stderr, "Internal error compiling regex %s: %s\n",
- regex, error);
- free (error);
- exit (1);
+ INTERNAL_ERROR ("compiling regex %s: %s\n",
+ regex, error);
}
}
return rerr;
for (i = 0; i < nmatch; i++) {
- if (pmatch[i].rm_so == -1) {
- fprintf (stderr, "Internal error matching regex against %s: Sub-match %d not found\n",
- string, i);
- exit (1);
- }
+ if (pmatch[i].rm_so == -1)
+ INTERNAL_ERROR ("matching regex against %s: Sub-match %d not found\n",
+ string, i);
}
return 0;