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.
This commit is contained in:
Olly Betts 2022-03-07 14:20:58 +13:00
commit d7625ee6b2
2 changed files with 13 additions and 9 deletions

View file

@ -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:

View file

@ -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;