Use global scratch space for temporary objects, better errors

This commit is contained in:
2024-02-14 21:44:46 -06:00
parent bc948d1a61
commit 8b57e0c441
4 changed files with 149 additions and 102 deletions

View File

@@ -117,15 +117,18 @@ const KiwiErr* new_error(const KiwiErr* base, const std::exception& ex) {
static const constexpr KiwiErr kKiwiErrUnhandledCxxException {
KiwiErrUnknown,
"An unhandled C++ exception occurred."};
"An unhandled C++ exception occurred."
};
static const constexpr KiwiErr kKiwiErrNullObjectArg0 {
KiwiErrNullObject,
"null object passed as argument #0 (self)"};
"null object passed as argument #0 (self)"
};
static const constexpr KiwiErr kKiwiErrNullObjectArg1 {
KiwiErrNullObject,
"null object passed as argument #1"};
"null object passed as argument #1"
};
template<typename F>
inline const KiwiErr* wrap_err(F&& f) {
@@ -134,42 +137,49 @@ inline const KiwiErr* wrap_err(F&& f) {
} catch (const UnsatisfiableConstraint& ex) {
static const constexpr KiwiErr err {
KiwiErrUnsatisfiableConstraint,
"The constraint cannot be satisfied."};
"The constraint cannot be satisfied."
};
return &err;
} catch (const UnknownConstraint& ex) {
static const constexpr KiwiErr err {
KiwiErrUnknownConstraint,
"The constraint has not been added to the solver."};
"The constraint has not been added to the solver."
};
return &err;
} catch (const DuplicateConstraint& ex) {
static const constexpr KiwiErr err {
KiwiErrDuplicateConstraint,
"The constraint has already been added to the solver."};
"The constraint has already been added to the solver."
};
return &err;
} catch (const UnknownEditVariable& ex) {
static const constexpr KiwiErr err {
KiwiErrUnknownEditVariable,
"The edit variable has not been added to the solver."};
"The edit variable has not been added to the solver."
};
return &err;
} catch (const DuplicateEditVariable& ex) {
static const constexpr KiwiErr err {
KiwiErrDuplicateEditVariable,
"The edit variable has already been added to the solver."};
"The edit variable has already been added to the solver."
};
return &err;
} catch (const BadRequiredStrength& ex) {
static const constexpr KiwiErr err {
KiwiErrBadRequiredStrength,
"A required strength cannot be used in this context."};
"A required strength cannot be used in this context."
};
return &err;
} catch (const InternalSolverError& ex) {
static const constexpr KiwiErr base {
KiwiErrInternalSolverError,
"An internal solver error occurred."};
"An internal solver error occurred."
};
return new_error(&base, ex);
} catch (std::bad_alloc&) {
static const constexpr KiwiErr err {KiwiErrAlloc, "A memory allocation failed."};

View File

@@ -1,10 +1,10 @@
#ifndef CKIWI_H_
#define CKIWI_H_
#include <stddef.h>
#ifndef KIWI_CKIWI_H_
#define KIWI_CKIWI_H_
#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif
#define KIWI_REF_ISNULL(ref) ((ref).impl_ == NULL)
@@ -98,4 +98,4 @@ char* kiwi_solver_dumps(const KiwiSolver* sp);
// Local Variables:
// mode: c++
// End:
#endif // CKIWI_H_
#endif // KIWI_CKIWI_H_