Commit e250f0dc by David Malcolm Committed by David Malcolm

PR jit/64018: Add description of error-handling to the JIT tutorial

gcc/jit/ChangeLog:
	PR jit/64018
	* docs/intro/tutorial02.rst: Spell out lifetime of generated code.
	Add description of error-handling, taken in part from...
	* docs/topics/contexts.rst (Error-handling): Expand, and move some
	content to tutorial02.rst.
	* docs/_build/texinfo/libgccjit.texi: Regenerate.

From-SVN: r218243
parent 9838117b
2014-12-01 David Malcolm <dmalcolm@redhat.com>
PR jit/64018
* docs/intro/tutorial02.rst: Spell out lifetime of generated code.
Add description of error-handling, taken in part from...
* docs/topics/contexts.rst (Error-handling): Expand, and move some
content to tutorial02.rst.
* docs/_build/texinfo/libgccjit.texi: Regenerate.
2014-12-01 David Malcolm <dmalcolm@redhat.com>
PR jit/64020
* docs/topics/types.rst (Standard types) Add new enum values to
the table of enum gcc_jit_types: GCC_JIT_TYPE_COMPLEX_FLOAT,
......
......@@ -218,6 +218,44 @@ then call it:
result: 25
Once we're done with the code, we can release the result:
.. code-block:: c
gcc_jit_result_release (result);
We can't call ``square`` anymore once we've released ``result``.
Error-handling
**************
Various kinds of errors are possible when using the API, such as
mismatched types in an assignment. You can only compile and get code
from a context if no errors occur.
Errors are printed on stderr; they typically contain the name of the API
entrypoint where the error occurred, and pertinent information on the
problem:
.. code-block:: console
./buggy-program: error: gcc_jit_block_add_assignment: mismatching types: assignment to i (type: int) from "hello world" (type: const char *)
The API is designed to cope with errors without crashing, so you can get
away with having a single error-handling check in your code:
.. code-block:: c
void *fn_ptr = gcc_jit_result_get_code (result, "square");
if (!fn_ptr)
{
fprintf (stderr, "NULL fn_ptr");
goto error;
}
For more information, see the :ref:`error-handling guide <error-handling>`
within the Topic eference.
Options
*******
......
......@@ -101,18 +101,30 @@ within a process may use a given "family tree" of such contexts at once,
and if you're using multiple threads you should provide your own locking
around entire such context partitions.
.. _error-handling:
Error-handling
--------------
You can only compile and get code from a context if no errors occur.
In general, if an error occurs when using an API entrypoint, it returns
NULL. You don't have to check everywhere for NULL results, since the
API gracefully handles a NULL being passed in for any argument.
Various kinds of errors are possible when using the API, such as
mismatched types in an assignment. You can only compile and get code from
a context if no errors occur.
Errors are printed on stderr and can be queried using
:c:func:`gcc_jit_context_get_first_error`.
They typically contain the name of the API entrypoint where the error
occurred, and pertinent information on the problem:
.. code-block:: console
./buggy-program: error: gcc_jit_block_add_assignment: mismatching types: assignment to i (type: int) from "hello world" (type: const char *)
In general, if an error occurs when using an API entrypoint, the
entrypoint returns NULL. You don't have to check everywhere for NULL
results, since the API handles a NULL being passed in for any
argument by issuing another error. This typically leads to a cascade of
followup error messages, but is safe (albeit verbose).
.. function:: const char *\
gcc_jit_context_get_first_error (gcc_jit_context *ctxt)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment