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:
parent
46bdb1bb29
commit
d7625ee6b2
2 changed files with 13 additions and 9 deletions
|
|
@ -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>
|
<b><tt>void Swig_require(const char *namespace, Node *n, ...)</tt></b>
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
This function is similar to <tt>Swig_save()</tt> except that adds additional attribute checking. There are different interpretations
|
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 failed assertion. An attribute name of "?attr" specifies that the attribute "attr" is optional and
|
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
|
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:
|
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:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
* ns - namespace for the view name for saving any attributes under
|
||||||
* n - node
|
* n - node
|
||||||
* ... - list of attribute names of type char*
|
* ... - 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
|
* An attribute is optional if it is prefixed by ?, eg "?value". All
|
||||||
* optional if it is prefixed by ?, eg "?value". If the attribute name is prefixed
|
* non-optional attributes are checked for on node n and if any do not exist
|
||||||
* by * or ?, eg "*value" then a copy of the attribute is saved. The saved
|
* SWIG exits with a fatal error.
|
||||||
* attributes will be restored on a subsequent call to Swig_restore(). All the
|
*
|
||||||
* saved attributes are saved in the view namespace (prefixed by ns).
|
* 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.
|
* 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);
|
obj = Getattr(n, name);
|
||||||
if (!opt && !obj) {
|
if (!opt && !obj) {
|
||||||
Swig_error(Getfile(n), Getline(n), "Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", name, nodeType(n));
|
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)
|
if (!obj)
|
||||||
obj = DohNone;
|
obj = DohNone;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue