aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinnokentii <innokentii@yandex-team.com>2023-03-06 12:39:20 +0300
committerinnokentii <innokentii@yandex-team.com>2023-03-06 12:39:20 +0300
commit91a970e57eca134bea57b1522398bee21f7c63d9 (patch)
tree4ce0ad8b8d5f9be829c9e4baec2d0274d6b2cc1f
parent3c7bd95dcf90c78f62e5b6a2d53a49d88ad815cf (diff)
downloadydb-91a970e57eca134bea57b1522398bee21f7c63d9.tar.gz
Add pr #73 to libfyaml: add document destroy hook
add pr #73 to libfyaml
-rw-r--r--contrib/libs/libfyaml/include/libfyaml.h70
-rw-r--r--contrib/libs/libfyaml/src/lib/fy-doc.c37
-rw-r--r--contrib/libs/libfyaml/src/lib/fy-doc.h3
3 files changed, 110 insertions, 0 deletions
diff --git a/contrib/libs/libfyaml/include/libfyaml.h b/contrib/libs/libfyaml/include/libfyaml.h
index 28abdd668f..bb19d89463 100644
--- a/contrib/libs/libfyaml/include/libfyaml.h
+++ b/contrib/libs/libfyaml/include/libfyaml.h
@@ -4796,6 +4796,76 @@ fy_document_unregister_meta(struct fy_document *fyd)
FY_EXPORT;
/**
+ * fy_document_get_userdata() - Get the userdata pointer of a document
+ *
+ * Return the userdata pointer of a document.
+ *
+ * @fyn: The document to get userdata from
+ *
+ * Returns:
+ * The stored userdata pointer
+ */
+void *
+fy_document_get_userdata(struct fy_document *fyd)
+ FY_EXPORT;
+
+/**
+ * fy_document_set_userdata() - Set the userdata pointer of a document
+ *
+ * Set the userdata pointer of a document. If @userdata is NULL
+ * then clear the userdata.
+ *
+ * @fyd: The document to set userdata
+ * @userdata: The userdata pointer
+ *
+ * Returns:
+ * 0 on success, -1 on error
+ */
+int
+fy_document_set_userdata(struct fy_document *fyd, void *userdata)
+ FY_EXPORT;
+
+/**
+ * typedef fy_document_on_destroy_fn - Userdata clear method
+ *
+ * This is the callback called just before document is destroyed.
+ *
+ * @fyd: The document which will be destroyed
+ * @userdata: The userdata pointer of a document
+ *
+ */
+typedef void (*fy_document_on_destroy_fn)(struct fy_document *fyd, void *userdata);
+
+/**
+ * fy_document_register_on_destroy() - Register an on_destroy hook
+ *
+ * Register an on_destroy hook, to be called when
+ * the document is freed via a final call to fy_document_destroy().
+ *
+ * @fyd: The document which the hook is registered to
+ * @on_destroy_fn: The on_destroy hook method
+ *
+ * Returns:
+ * 0 on success, -1 if another hook is already registered.
+ */
+int
+fy_document_register_on_destroy(struct fy_document *fyd,
+ fy_document_on_destroy_fn on_destroy_fn)
+ FY_EXPORT;
+
+/**
+ * fy_document_unregister_on_destroy() - Unregister an on_destroy hook
+ *
+ * Unregister the currently active on_destroy hook.
+ *
+ * @fyd: The document to unregister it's on_destroy hook.
+ */
+void
+fy_document_unregister_on_destroy(struct fy_document *fyd)
+ FY_EXPORT;
+
+
+/**
* fy_node_set_marker() - Set a marker of a node
*
* Sets the marker of the given node, while returning
diff --git a/contrib/libs/libfyaml/src/lib/fy-doc.c b/contrib/libs/libfyaml/src/lib/fy-doc.c
index eb76ac4ff6..2daec904ce 100644
--- a/contrib/libs/libfyaml/src/lib/fy-doc.c
+++ b/contrib/libs/libfyaml/src/lib/fy-doc.c
@@ -386,6 +386,9 @@ void fy_parse_document_destroy(struct fy_parser *fyp, struct fy_document *fyd)
fy_diag_unref(fyd->diag);
+ if (fyd->on_destroy_fn)
+ fyd->on_destroy_fn(fyd, fyd->userdata);
+
free(fyd);
}
@@ -6306,6 +6309,40 @@ void fy_document_unregister_meta(struct fy_document *fyd)
fyd->meta_user = NULL;
}
+int fy_document_set_userdata(struct fy_document *fyd, void *userdata)
+{
+ if (!fyd || !userdata)
+ return -1;
+
+ fyd->userdata = userdata;
+
+ return 0;
+}
+
+void* fy_document_get_userdata(struct fy_document *fyd)
+{
+ return fyd->userdata;
+}
+
+int fy_document_register_on_destroy(struct fy_document *fyd,
+ fy_document_on_destroy_fn on_destroy_fn)
+{
+ if (!fyd || !on_destroy_fn)
+ return -1;
+
+ fyd->on_destroy_fn = on_destroy_fn;
+
+ return 0;
+}
+
+void fy_document_unregister_on_destroy(struct fy_document *fyd)
+{
+ if (!fyd)
+ return;
+
+ fyd->on_destroy_fn = NULL;
+}
+
bool fy_node_set_marker(struct fy_node *fyn, unsigned int marker)
{
unsigned int prev_marks;
diff --git a/contrib/libs/libfyaml/src/lib/fy-doc.h b/contrib/libs/libfyaml/src/lib/fy-doc.h
index d8535c1a1e..d83d59026d 100644
--- a/contrib/libs/libfyaml/src/lib/fy-doc.h
+++ b/contrib/libs/libfyaml/src/lib/fy-doc.h
@@ -122,6 +122,9 @@ struct fy_document {
fy_node_meta_clear_fn meta_clear_fn;
void *meta_user;
+ fy_document_on_destroy_fn on_destroy_fn;
+ void *userdata;
+
struct fy_path_expr_document_data *pxdd;
};
/* only the list declaration/methods */