From 9f8b97ae462dd6b1f71f438bf0d19015e97afef7 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 18 Mar 2023 18:11:23 +0100 Subject: [PATCH] Rename fields of m_exception_t: data->context n->num --- README.md | 4 ++-- m-try.h | 12 ++++++------ tests/test-mtry.c | 26 +++++++++++++------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 817a6f21..f041dbf8 100644 --- a/README.md +++ b/README.md @@ -7813,8 +7813,8 @@ This is the exception type. It is composed of the following fields: * error\_code: The error code. It is used to identify the error that are raised the exception. * line: The line number where the error was detected. * filename: The filename (CSTR) where the error was detected. -* n: Number of entries in 'data' table -* data: an array of M\_USE\_MAX\_EXCEPTION elements. +* num: Number of entries in 'context' table +* context: an array of M\_USE\_MAX\_CONTEXT elements. You can access the fields of the type directly. diff --git a/m-try.h b/m-try.h index 32a75a35..a5a61cc5 100644 --- a/m-try.h +++ b/m-try.h @@ -81,7 +81,7 @@ M_STATIC_ASSERT(M_RET_ARG1 (__VA_ARGS__) != 0, \ M_LIB_NOT_A_CONSTANT_NON_NULL_INTEGER, \ "The error code shall be a non null constant"); \ - M_STATIC_ASSERT(M_NARGS (__VA_ARGS__) <= 1+M_USE_MAX_EXCEPTION, \ + M_STATIC_ASSERT(M_NARGS (__VA_ARGS__) <= 1+M_USE_MAX_CONTEXT, \ M_LIB_TOO_MANY_ARGUMENTS, \ "There are too many arguments for an exception."); \ M_IF_NARGS_EQ1(__VA_ARGS__)(M_THROW_1, M_THROW_N)(__VA_ARGS__); \ @@ -89,10 +89,10 @@ /* - * Size of the extra data that are stored in an exception. + * Size of the context data that are stored in an exception. */ -#ifndef M_USE_MAX_EXCEPTION -#define M_USE_MAX_EXCEPTION 5 +#ifndef M_USE_MAX_CONTEXT +#define M_USE_MAX_CONTEXT 10 #endif /* @@ -121,9 +121,9 @@ template struct m_exception_s { unsigned error_code; // Error code unsigned short line; // Line number where the error was detected - unsigned short n; // Number of entries in 'error' table + unsigned short num; // Number of entries in 'context' table const char *filename; // filename where the error was detected - intptr_t data[M_USE_MAX_EXCEPTION]; // Specific data of the exception + intptr_t context[M_USE_MAX_CONTEXT]; // Specific context of the exception #ifdef __cplusplus m_exception_s *operator->() { return this; } #endif diff --git a/tests/test-mtry.c b/tests/test-mtry.c index e9667fbe..23f54269 100644 --- a/tests/test-mtry.c +++ b/tests/test-mtry.c @@ -31,8 +31,8 @@ static void test_throw(void) M_TRY(protect) { M_THROW(67, 56); } M_CATCH(protect, 67) { - assert(protect->n == 1); - M_THROW(M_ERROR_MEMORY, protect->data[0], 4, 6, 8); + assert(protect->num == 1); + M_THROW(M_ERROR_MEMORY, protect->context[0], 4, 6, 8); } } @@ -96,8 +96,8 @@ static void test1(void) assert(0); } M_CATCH(test2, M_ERROR_ACCESS) { assert(flow++ == 6); - assert(test2->n == 1); - assert(test2->data[0] == 12); + assert(test2->num == 1); + assert(test2->context[0] == 12); } } M_CATCH(test1, M_ERROR_MEMORY) { assert(0); @@ -129,9 +129,9 @@ static void test1(void) assert(0); } M_CATCH(test1, 42) { assert(flow++ == 6); - assert(test1->n == 2); - assert(test1->data[0] == 1); - assert(test1->data[1] == 3); + assert(test1->num == 2); + assert(test1->context[0] == 1); + assert(test1->context[1] == 3); } assert(flow ++ == 7); @@ -191,11 +191,11 @@ static void test1(void) } } M_CATCH(test1, M_ERROR_MEMORY) { assert(flow ++ == 4); - assert(test1->n == 4); - assert(test1->data[0] == 56); - assert(test1->data[1] == 4); - assert(test1->data[2] == 6); - assert(test1->data[3] == 8); + assert(test1->num == 4); + assert(test1->context[0] == 56); + assert(test1->context[1] == 4); + assert(test1->context[2] == 6); + assert(test1->context[3] == 8); } M_CATCH(test1, 42) { assert(0); } @@ -219,7 +219,7 @@ static void test1(void) assert(flow ++ == 3); #ifndef __cplusplus assert(test1->error_code == 23); - assert(test1->n == 0); + assert(test1->num == 0); #endif } assert(flow ++ == 4);