diff options
author | David Malcolm <dmalcolm@redhat.com> | 2015-01-08 21:52:35 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2015-01-08 21:52:35 +0000 |
commit | 303e1d56c6214940a633c2b8ea7da2d81c15bd4d (patch) | |
tree | 66af508dfe03e5522c875f84f66abfeeeabbcd9a /gcc/jit/jit-recording.c | |
parent | 204a913bda3c3228723ea13e41c9dd831c362b33 (diff) | |
download | gcc-303e1d56c6214940a633c2b8ea7da2d81c15bd4d.zip gcc-303e1d56c6214940a633c2b8ea7da2d81c15bd4d.tar.gz gcc-303e1d56c6214940a633c2b8ea7da2d81c15bd4d.tar.bz2 |
jit: New API entrypoint: gcc_jit_context_get_last_error
gcc/jit/ChangeLog:
* docs/topics/contexts.rst (Error-handling): Document new
entrypoint gcc_jit_context_get_last_error.
* docs/_build/texinfo/libgccjit.texi: Regenerate.
* jit-recording.c (gcc::jit::recording::context::context):
Initialize new fields "m_last_error_str" and
"m_owns_last_error_str".
(gcc::jit::recording::context::~context): Clean up
m_last_error_str, if needed.
(gcc::jit::recording::context::add_error_va): Update
m_last_error_str and m_owns_last_error_str, freeing the old
value if appropriate.
(gcc::jit::recording::context::get_last_error): New function.
* jit-recording.h (gcc::jit::recording::context::get_last_error):
New function.
(gcc::jit::recording::context): New fields m_last_error_str and
m_owns_last_error_str.
* libgccjit.c (gcc_jit_context_get_last_error): New function.
* libgccjit.h (gcc_jit_context_get_last_error): New declaration.
* libgccjit.map (gcc_jit_context_get_last_error): New function.
gcc/testsuite/ChangeLog:
* jit.dg/test-error-block-in-wrong-function.c (verify_code):
Verify the result of gcc_jit_context_get_last_error.
* jit.dg/test-error-null-passed-to-api.c (verify_code): Likewise.
From-SVN: r219363
Diffstat (limited to 'gcc/jit/jit-recording.c')
-rw-r--r-- | gcc/jit/jit-recording.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c index a872063..a9ff300 100644 --- a/gcc/jit/jit-recording.c +++ b/gcc/jit/jit-recording.c @@ -175,6 +175,8 @@ recording::context::context (context *parent_ctxt) m_error_count (0), m_first_error_str (NULL), m_owns_first_error_str (false), + m_last_error_str (NULL), + m_owns_last_error_str (false), m_mementos (), m_compound_types (), m_functions (), @@ -230,6 +232,10 @@ recording::context::~context () if (m_owns_first_error_str) free (m_first_error_str); + + if (m_owns_last_error_str) + if (m_last_error_str != m_first_error_str) + free (m_last_error_str); } /* Add the given mememto to the list of those tracked by this @@ -984,9 +990,12 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap) m_first_error_str = const_cast <char *> (errmsg); m_owns_first_error_str = has_ownership; } - else - if (has_ownership) - free (malloced_msg); + + if (m_owns_last_error_str) + if (m_last_error_str != m_first_error_str) + free (m_last_error_str); + m_last_error_str = const_cast <char *> (errmsg); + m_owns_last_error_str = has_ownership; m_error_count++; } @@ -1003,6 +1012,18 @@ recording::context::get_first_error () const return m_first_error_str; } +/* Get the message for the last error that occurred on this context, or + NULL if no errors have occurred on it. + + Implements the post-error-checking part of + gcc_jit_context_get_last_error. */ + +const char * +recording::context::get_last_error () const +{ + return m_last_error_str; +} + /* Lazily generate and record a recording::type representing an opaque struct named "FILE". |