yajl: Add yajl_reset_stack() to recover from parsing failure
libbons project currently bundles yajl because it needs to support recovering from yajl parsing failures by resetting the byte stack. See [https://jira.mongodb.org/browse/CDRIVER-597].
Followin patch adds yajl_reset_stack() public function which could satisfy libbson need:
From d42168311963a6827b0c9d547d8efdf0e7fbdcae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Fri, 24 Apr 2015 14:51:24 +0200
Subject: [PATCH] Add yajl_reset_stack()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
yajl_reset_stack() resets parser stack and initilize it to
yajl_state_start. This is needed by libbson library to recover from
parsing failure without need to destroy the handle completely.
See <https://jira.mongodb.org/browse/CDRIVER-597>.
Signed-off-by: Petr Písař <ppisar@redhat.com>
diff --git a/src/api/yajl_parse.h b/src/api/yajl_parse.h
index 1c25a60..8ba903a 100644
--- a/src/api/yajl_parse.h
+++ b/src/api/yajl_parse.h
@@ -168,6 +168,9 @@ extern "C" {
/** free a parser handle */
YAJL_API void yajl_free(yajl_handle handle);
+ /** Flush parser stack to initial state. All other settings are preserved. */
+ YAJL_API void yajl_reset_stack(yajl_handle handle);
+
/** Parse some json!
* \param hand - a handle to the json parser allocated with yajl_alloc
* \param jsonText - a pointer to the UTF8 json text to be parsed
diff --git a/src/yajl.c b/src/yajl.c
index d477893..1cb7c51 100644
--- a/src/yajl.c
+++ b/src/yajl.c
@@ -114,6 +114,13 @@ yajl_free(yajl_handle handle)
YA_FREE(&(handle->alloc), handle);
}
+void
+yajl_reset_stack(yajl_handle handle)
+{
+ handle->stateStack.used = 0;
+ yajl_bs_push(handle->stateStack, yajl_state_start);
+}
+
yajl_status
yajl_parse(yajl_handle hand, const unsigned char * jsonText,
size_t jsonTextLen)
--
2.1.0
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 24 (7 by maintainers)
@lloyd Are there any news to merge the patch in the master branch and roll a new release ? Without this release, it is impossible to integrate some libraries in distributions.
Is there a problem with maintenance of yajl ? It seems that there are some developers ( @lamont-granquist, @ppisar ) that would be happy to maintain it.