Further simplify error queue flags.
ERR_FLAGS_STRING is meaningless and we can use a bitfield for the mark bit. Change-Id: I6f677b55b11316147512171629196c651cb33ca9 Reviewed-on: https://boringssl-review.googlesource.com/21084 Commit-Queue: Steven Valdez <svaldez@google.com> Reviewed-by: Steven Valdez <svaldez@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
1c58471cc9
commit
a65c252f78
@ -129,15 +129,9 @@ extern const uint32_t kOpenSSLReasonValues[];
|
||||
extern const size_t kOpenSSLReasonValuesLen;
|
||||
extern const char kOpenSSLReasonStringData[];
|
||||
|
||||
// err_clear_data frees the optional |data| member of the given error.
|
||||
static void err_clear_data(struct err_error_st *error) {
|
||||
OPENSSL_free(error->data);
|
||||
error->data = NULL;
|
||||
}
|
||||
|
||||
// err_clear clears the given queued error.
|
||||
static void err_clear(struct err_error_st *error) {
|
||||
err_clear_data(error);
|
||||
OPENSSL_free(error->data);
|
||||
OPENSSL_memset(error, 0, sizeof(struct err_error_st));
|
||||
}
|
||||
|
||||
@ -224,7 +218,7 @@ static uint32_t get_error_values(int inc, int top, const char **file, int *line,
|
||||
} else {
|
||||
*data = error->data;
|
||||
if (flags != NULL) {
|
||||
*flags = error->flags & ERR_FLAG_PUBLIC_MASK;
|
||||
*flags = ERR_FLAG_STRING;
|
||||
}
|
||||
// If this error is being removed, take ownership of data from
|
||||
// the error. The semantics are such that the caller doesn't
|
||||
@ -237,7 +231,6 @@ static uint32_t get_error_values(int inc, int top, const char **file, int *line,
|
||||
state->to_free = error->data;
|
||||
}
|
||||
error->data = NULL;
|
||||
error->flags = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -594,9 +587,8 @@ static void err_set_error_data(char *data) {
|
||||
|
||||
error = &state->errors[state->top];
|
||||
|
||||
err_clear_data(error);
|
||||
OPENSSL_free(error->data);
|
||||
error->data = data;
|
||||
error->flags = ERR_FLAG_STRING;
|
||||
}
|
||||
|
||||
void ERR_put_error(int library, int unused, int reason, const char *file,
|
||||
@ -711,7 +703,7 @@ int ERR_set_mark(void) {
|
||||
if (state == NULL || state->bottom == state->top) {
|
||||
return 0;
|
||||
}
|
||||
state->errors[state->top].flags |= ERR_FLAG_MARK;
|
||||
state->errors[state->top].mark = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -725,8 +717,8 @@ int ERR_pop_to_mark(void) {
|
||||
while (state->bottom != state->top) {
|
||||
struct err_error_st *error = &state->errors[state->top];
|
||||
|
||||
if ((error->flags & ERR_FLAG_MARK) != 0) {
|
||||
error->flags &= ~ERR_FLAG_MARK;
|
||||
if (error->mark) {
|
||||
error->mark = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -176,6 +176,10 @@ OPENSSL_EXPORT uint32_t ERR_get_error(void);
|
||||
// number of the call that added the error are also returned.
|
||||
OPENSSL_EXPORT uint32_t ERR_get_error_line(const char **file, int *line);
|
||||
|
||||
// ERR_FLAG_STRING means that the |data| member is a NUL-terminated string that
|
||||
// can be printed. This is always set if |data| is non-NULL.
|
||||
#define ERR_FLAG_STRING 1
|
||||
|
||||
// ERR_get_error_line_data acts like |ERR_get_error_line|, but also returns the
|
||||
// error-specific data pointer and flags. The flags are a bitwise-OR of
|
||||
// |ERR_FLAG_*| values. The error-specific data is owned by the error queue
|
||||
@ -396,6 +400,10 @@ OPENSSL_EXPORT char *ERR_error_string(uint32_t packed_error, char *buf);
|
||||
// ERR_GET_FUNC returns zero. BoringSSL errors do not report a function code.
|
||||
#define ERR_GET_FUNC(packed_error) 0
|
||||
|
||||
// ERR_TXT_STRING is provided for compatibility with code that assumes that
|
||||
// it's using OpenSSL.
|
||||
#define ERR_TXT_STRING ERR_FLAG_STRING
|
||||
|
||||
|
||||
// Private functions.
|
||||
|
||||
@ -438,28 +446,10 @@ struct err_error_st {
|
||||
uint32_t packed;
|
||||
// line contains the line number where the error occurred.
|
||||
uint16_t line;
|
||||
// flags contains a bitwise-OR of ERR_FLAG_* values.
|
||||
uint8_t flags;
|
||||
// mark indicates a reversion point in the queue. See |ERR_pop_to_mark|.
|
||||
unsigned mark : 1;
|
||||
};
|
||||
|
||||
// ERR_FLAG_STRING means that the |data| member is a NUL-terminated string that
|
||||
// can be printed. This is always set if |data| is non-NULL.
|
||||
#define ERR_FLAG_STRING 1
|
||||
// ERR_TXT_STRING is provided for compatibility with code that assumes that
|
||||
// it's using OpenSSL.
|
||||
#define ERR_TXT_STRING ERR_FLAG_STRING
|
||||
|
||||
// ERR_FLAG_PUBLIC_MASK is applied to the flags field before it is returned
|
||||
// from functions like |ERR_get_error_line_data|.
|
||||
#define ERR_FLAG_PUBLIC_MASK 0xf
|
||||
|
||||
// The following flag values are internal and are masked when flags are
|
||||
// returned from functions like |ERR_get_error_line_data|.
|
||||
|
||||
// ERR_FLAG_MARK is used to indicate a reversion point in the queue. See
|
||||
// |ERR_pop_to_mark|.
|
||||
#define ERR_FLAG_MARK 16
|
||||
|
||||
// ERR_NUM_ERRORS is the limit of the number of errors in the queue.
|
||||
#define ERR_NUM_ERRORS 16
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user