From 63cd681d4e3cdb9d79b5eacd8aebf20d09500419 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sat, 6 Jul 2024 13:52:11 +0200 Subject: [PATCH 1/3] geanygendoc: Fix crash if trying to document an unknown type Fix crash if the tag to generate documentation for is of an unknown type. Also consolidate some code around this to validate parameters just to be more defensive in case it sill actually happens. Fixes #1362. --- geanygendoc/src/ggd-doc-type.c | 6 +++++- geanygendoc/src/ggd.c | 17 ++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/geanygendoc/src/ggd-doc-type.c b/geanygendoc/src/ggd-doc-type.c index f8f180eaf..edbd8122b 100644 --- a/geanygendoc/src/ggd-doc-type.c +++ b/geanygendoc/src/ggd-doc-type.c @@ -128,9 +128,12 @@ ggd_doc_type_get_setting (const GgdDocType *doctype, { GgdDocSetting *setting = NULL; GList *tmp; - gssize match_len = strlen (match); + gssize match_len; g_return_val_if_fail (doctype != NULL, NULL); + g_return_val_if_fail (match != NULL, NULL); + + match_len = (gssize) strlen (match); for (tmp = doctype->settings; tmp && ! setting; tmp = g_list_next (tmp)) { if (ggd_doc_setting_matches (tmp->data, match, match_len)) { @@ -177,6 +180,7 @@ ggd_doc_type_resolve_setting (const GgdDocType *doctype, gchar *child_match = NULL; g_return_val_if_fail (doctype != NULL, NULL); + g_return_val_if_fail (match != NULL, NULL); /*g_debug ("Resolving match \"%s\"...", child_match);*/ if (nth_child) (*nth_child) = 0; diff --git a/geanygendoc/src/ggd.c b/geanygendoc/src/ggd.c index bc55a300f..cecbacd3f 100644 --- a/geanygendoc/src/ggd.c +++ b/geanygendoc/src/ggd.c @@ -383,22 +383,25 @@ get_setting_from_tag (GgdDocType *doctype, const TMTag *tag, const TMTag **real_tag) { - GgdDocSetting *setting; + GgdDocSetting *setting = NULL; gchar *hierarchy; - gint nth_child; GPtrArray *tag_array = doc->tm_file->tags_array; GeanyFiletypeID geany_ft = FILETYPE_ID (doc->file_type); hierarchy = ggd_tag_resolve_type_hierarchy (tag_array, geany_ft, tag); /*g_debug ("type hierarchy for tag %s is: %s", tag->name, hierarchy);*/ - setting = ggd_doc_type_resolve_setting (doctype, hierarchy, &nth_child); *real_tag = tag; - if (setting) { - for (; nth_child > 0; nth_child--) { - *real_tag = ggd_tag_find_parent (tag_array, geany_ft, *real_tag); + if (hierarchy) { + gint nth_child; + + setting = ggd_doc_type_resolve_setting (doctype, hierarchy, &nth_child); + if (setting) { + for (; nth_child > 0; nth_child--) { + *real_tag = ggd_tag_find_parent (tag_array, geany_ft, *real_tag); + } } + g_free (hierarchy); } - g_free (hierarchy); return setting; } From 7a2f1dc667da9e488c12cd299d53d230302a1da7 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sat, 6 Jul 2024 13:54:37 +0200 Subject: [PATCH 2/3] geanygendoc: Sort tag types alphabetically No functional changes, it just helps updating the table. --- geanygendoc/src/ggd-tag-utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/geanygendoc/src/ggd-tag-utils.c b/geanygendoc/src/ggd-tag-utils.c index 1d1fff800..2cdaa1e72 100644 --- a/geanygendoc/src/ggd-tag-utils.c +++ b/geanygendoc/src/ggd-tag-utils.c @@ -252,10 +252,13 @@ static const struct { { tm_tag_class_t, "class" }, { tm_tag_enum_t, "enum" }, { tm_tag_enumerator_t, "enumval" }, + { tm_tag_externvar_t, "extern" }, { tm_tag_field_t, "field" }, { tm_tag_function_t, "function" }, { tm_tag_interface_t, "interface" }, { tm_tag_local_var_t, "local" }, + { tm_tag_macro_t, "define" }, + { tm_tag_macro_with_arg_t, "macro" }, { tm_tag_member_t, "member" }, { tm_tag_method_t, "method" }, { tm_tag_namespace_t, "namespace" }, @@ -264,10 +267,7 @@ static const struct { { tm_tag_struct_t, "struct" }, { tm_tag_typedef_t, "typedef" }, { tm_tag_union_t, "union" }, - { tm_tag_variable_t, "variable" }, - { tm_tag_externvar_t, "extern" }, - { tm_tag_macro_t, "define" }, - { tm_tag_macro_with_arg_t, "macro" } + { tm_tag_variable_t, "variable" } }; /** From 8043a678b69c3ad3dcb58e4826a2232e97072ebf Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sat, 6 Jul 2024 13:59:56 +0200 Subject: [PATCH 3/3] geanygendoc: Add support for types "include" and "other" They are both ignored by the default configuration, as include directives are not usually useful to document, and "other" is not normally emitted by the C language parser. --- geanygendoc/data/filetypes/c.conf | 6 ++++++ geanygendoc/docs/manual.rst | 4 ++++ geanygendoc/src/ggd-tag-utils.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/geanygendoc/data/filetypes/c.conf b/geanygendoc/data/filetypes/c.conf index 1159b15ae..231ff25b3 100644 --- a/geanygendoc/data/filetypes/c.conf +++ b/geanygendoc/data/filetypes/c.conf @@ -43,6 +43,9 @@ doctypes = { enumval.policy = FORWARD; # usually, locals are just not documented and get in the way local.policy = FORWARD; + # usually nothing useful to document + include.policy = PASS; + other.policy = PASS; function = { template = "/**\n * {symbol}:\n{for arg in argument_list} * @{arg}: {cursor}\n{end} * \n * {cursor}\n{if returns} * \n * Returns: \n{end}{if write_since}{if returns} * \n{end} * Since: \n{end} */\n"; @@ -77,6 +80,9 @@ doctypes = { doxygen = { # usually, locals are just not documented and get in the way local.policy = FORWARD; + # usually nothing useful to document + include.policy = PASS; + other.policy = PASS; function.template = "/**\n * {doxygen_prefix}brief {cursor}\n{for a in argument_list} * {doxygen_prefix}param {a} \n{end}{if returns} * {doxygen_prefix}returns \n{end}{if write_since} * {doxygen_prefix}since \n{end} * \n * \n */\n"; macro.template = "/**\n * {doxygen_prefix}brief {cursor}\n{for a in argument_list} * {doxygen_prefix}param {a} \n{end}{if returns} * {doxygen_prefix}returns \n{end}{if write_since} * {doxygen_prefix}since \n{end} * \n * \n */\n"; diff --git a/geanygendoc/docs/manual.rst b/geanygendoc/docs/manual.rst index 10f4f45e5..a5ddd963a 100644 --- a/geanygendoc/docs/manual.rst +++ b/geanygendoc/docs/manual.rst @@ -346,6 +346,8 @@ Known types A field (of a class for example). ``function`` A function. +``include`` + An include directive. ``interface`` An interface. ``local`` @@ -356,6 +358,8 @@ Known types A method. ``namespace`` A namespace. +``other`` + A non-specific type that highly depend on the language. ``package`` A package. ``prototype`` diff --git a/geanygendoc/src/ggd-tag-utils.c b/geanygendoc/src/ggd-tag-utils.c index 2cdaa1e72..fe44c14e6 100644 --- a/geanygendoc/src/ggd-tag-utils.c +++ b/geanygendoc/src/ggd-tag-utils.c @@ -256,12 +256,14 @@ static const struct { { tm_tag_field_t, "field" }, { tm_tag_function_t, "function" }, { tm_tag_interface_t, "interface" }, + { tm_tag_include_t, "include" }, { tm_tag_local_var_t, "local" }, { tm_tag_macro_t, "define" }, { tm_tag_macro_with_arg_t, "macro" }, { tm_tag_member_t, "member" }, { tm_tag_method_t, "method" }, { tm_tag_namespace_t, "namespace" }, + { tm_tag_other_t, "other" }, { tm_tag_package_t, "package" }, { tm_tag_prototype_t, "prototype" }, { tm_tag_struct_t, "struct" },