summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2022-03-07 14:20:58 +1300
committerOlly Betts <olly@survex.com>2022-03-07 14:24:48 +1300
commitd7625ee6b23154a48546fe231d349bb52f5f9dd9 (patch)
treec0774b3d899b88f27f75598bb1bdc3ba22b4beb7
parent46bdb1bb29500e645e9426c07889af4a6224354e (diff)
downloadswig-d7625ee6b23154a48546fe231d349bb52f5f9dd9.tar.gz
Fix fatal error implemented by assert
Calling assert() on a condition that's always false is not an appropriate way to exit after emitting "Fatal error [...]" because if NDEBUG is defined the assert() becomes a no-op and the error stops actually being fatal.
-rw-r--r--Doc/Devel/tree.html4
-rw-r--r--Source/Swig/tree.c18
2 files changed, 13 insertions, 9 deletions
diff --git a/Doc/Devel/tree.html b/Doc/Devel/tree.html
index 5bb4b6a1e..2b9ac75dd 100644
--- a/Doc/Devel/tree.html
+++ b/Doc/Devel/tree.html
@@ -183,8 +183,8 @@ this function merely records that those attributes did not exist in the original
<b><tt>void Swig_require(const char *namespace, Node *n, ...)</tt></b>
<blockquote>
-This function is similar to <tt>Swig_save()</tt> except that adds additional attribute checking. There are different interpretations
-of the attribute names. A name of "attr" merely requests that the function check for the presence of an attribute. If the attribute is missing, SWIG will exit with a failed assertion. An attribute name of "?attr" specifies that the attribute "attr" is optional and
+This function is similar to <tt>Swig_save()</tt> except that it performs additional attribute checking. There are different interpretations
+of the attribute names. A name of "attr" merely requests that the function check for the presence of an attribute. If the attribute is missing, SWIG will exit with a fatal error. An attribute name of "?attr" specifies that the attribute "attr" is optional and
that its old value must be saved (if any). An attribute name of "*attr" specifies that the attribute is required and that
its value must be saved. The saving of attributes is performed in the same manner as with <tt>Swig_save()</tt>. Here is an example:
diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c
index e2162b7f1..5b0e9e1e9 100644
--- a/Source/Swig/tree.c
+++ b/Source/Swig/tree.c
@@ -261,12 +261,16 @@ int checkAttribute(Node *n, const_String_or_char_ptr name, const_String_or_char_
* ns - namespace for the view name for saving any attributes under
* n - node
* ... - list of attribute names of type char*
- * This method checks that the attribute names exist in the node n and asserts if
- * not. Assert will only occur unless the attribute is optional. An attribute is
- * optional if it is prefixed by ?, eg "?value". If the attribute name is prefixed
- * by * or ?, eg "*value" then a copy of the attribute is saved. The saved
- * attributes will be restored on a subsequent call to Swig_restore(). All the
- * saved attributes are saved in the view namespace (prefixed by ns).
+ *
+ * An attribute is optional if it is prefixed by ?, eg "?value". All
+ * non-optional attributes are checked for on node n and if any do not exist
+ * SWIG exits with a fatal error.
+ *
+ * If the attribute name is prefixed by * or ?, eg "*value" then a copy of the
+ * attribute is saved. The saved attributes will be restored on a subsequent
+ * call to Swig_restore(). All the saved attributes are saved in the view
+ * namespace (prefixed by ns).
+ *
* This function can be called more than once with different namespaces.
* ----------------------------------------------------------------------------- */
@@ -291,7 +295,7 @@ void Swig_require(const char *ns, Node *n, ...) {
obj = Getattr(n, name);
if (!opt && !obj) {
Swig_error(Getfile(n), Getline(n), "Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", name, nodeType(n));
- assert(obj);
+ Exit(EXIT_FAILURE);
}
if (!obj)
obj = DohNone;