Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
['/usr/local/opt/openssl/include'] + \
['aerospike-client-c/modules/common/src/include']
extra_compile_args = [
'-Winline',
'-std=gnu99', '-g', '-Wall', '-fPIC', '-DDEBUG', '-O1',
'-fno-common', '-fno-strict-aliasing',
'-D_FILE_OFFSET_BITS=64', '-D_REENTRANT',
Expand Down
37 changes: 3 additions & 34 deletions src/include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,9 @@
#include <aerospike/as_error.h>

// Cannot use multi-line macro because it cannot return a value.
static inline as_status
as_error_set_or_prepend_helper(as_error *err, as_status code, const char *fmt,
const char *func, const char *file,
uint32_t line, ...)
{
if (!fmt) {
err->code = code;
goto RETURN_EARLY;
}

va_list ap;
va_start(ap, line);

char err_msg_to_prepend[AS_ERROR_MESSAGE_MAX_SIZE];
vsnprintf(err_msg_to_prepend, AS_ERROR_MESSAGE_MAX_SIZE, fmt, ap);

// Prepend our new error message to the existing one.
char orig_err_msg[AS_ERROR_MESSAGE_MAX_SIZE];
strncpy(orig_err_msg, err->message, AS_ERROR_MESSAGE_MAX_LEN);
// Handles edge case where max number of chars is copied (without null terminator)
orig_err_msg[AS_ERROR_MESSAGE_MAX_LEN] = '\0';

as_error_setall(err, code, err_msg_to_prepend, func, file, line);

if (strlen(orig_err_msg)) {
as_error_append(err, " -> ");
as_error_append(err, orig_err_msg);
}

va_end(ap);

RETURN_EARLY:
return code;
}
as_status as_error_set_or_prepend_helper(as_error *err, as_status code,
const char *fmt, const char *func,
const char *file, uint32_t line, ...);

#undef as_error_update

Expand Down
34 changes: 34 additions & 0 deletions src/main/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,40 @@
#include "exception_types.h"
#include "macros.h"

as_status as_error_set_or_prepend_helper(as_error *err, as_status code,
const char *fmt, const char *func,
const char *file, uint32_t line, ...)
{
if (!fmt) {
err->code = code;
goto RETURN_EARLY;
}

va_list ap;
va_start(ap, line);

char err_msg_to_prepend[AS_ERROR_MESSAGE_MAX_SIZE];
vsnprintf(err_msg_to_prepend, AS_ERROR_MESSAGE_MAX_SIZE, fmt, ap);

// Prepend our new error message to the existing one.
char orig_err_msg[AS_ERROR_MESSAGE_MAX_SIZE];
strncpy(orig_err_msg, err->message, AS_ERROR_MESSAGE_MAX_LEN);
// Handles edge case where max number of chars is copied (without null terminator)
orig_err_msg[AS_ERROR_MESSAGE_MAX_LEN] = '\0';

as_error_setall(err, code, err_msg_to_prepend, func, file, line);

if (strlen(orig_err_msg)) {
as_error_append(err, " -> ");
as_error_append(err, orig_err_msg);
}

va_end(ap);

RETURN_EARLY:
return code;
}

static PyObject *py_exc_module;

#define SUBMODULE_NAME "exception"
Expand Down
Loading