Merge branch 'autodoc-doxygen-fix'

* autodoc-doxygen-fix:
  Fix crash in Python backend when using empty docstrings
This commit is contained in:
William S Fulton 2020-01-31 18:57:47 +00:00
commit 0c00daf3a1
3 changed files with 22 additions and 4 deletions

View file

@ -183,3 +183,12 @@ const int PROCESS_DEFAULT_VALUE = 17;
typedef long int some_type;
int process_complex_defval(int val = PROCESS_DEFAULT_VALUE, int factor = some_type(-1)) { return val*factor; }
%}
// Test for empty docstring, which should be ignored.
%feature("docstring") ""
%inline %{
struct a_structure{
char my_array[1];
};
%}

View file

@ -279,3 +279,5 @@ check(inspect.getdoc(process3), "process3(int _from, int _in, int var) -> int")
check(inspect.getdoc(process4), "process4(int _from=0, int _in=1, int var=2) -> int")
check(inspect.getdoc(process_complex_defval), "process_complex_defval(val=PROCESS_DEFAULT_VALUE, factor=some_type(-1)) -> int")
check(inspect.getdoc(a_structure.__init__), "__init__(a_structure self) -> a_structure", None, skip)

View file

@ -1484,8 +1484,15 @@ public:
String *build_combined_docstring(Node *n, autodoc_t ad_type, const String *indent = "", bool low_level = false) {
String *docstr = Getattr(n, "feature:docstring");
if (docstr && Len(docstr)) {
docstr = Copy(docstr);
if (docstr) {
// Simplify the code below by just ignoring empty docstrings.
if (!Len(docstr))
docstr = NULL;
else
docstr = Copy(docstr);
}
if (docstr) {
char *t = Char(docstr);
if (*t == '{') {
Delitem(docstr, 0);
@ -1496,7 +1503,7 @@ public:
if (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")) {
String *autodoc = make_autodoc(n, ad_type, low_level);
if (autodoc && Len(autodoc) > 0) {
if (docstr && Len(docstr)) {
if (docstr) {
Append(autodoc, "\n");
Append(autodoc, docstr);
}
@ -1509,7 +1516,7 @@ public:
Delete(autodoc);
}
if (!docstr || !Len(docstr)) {
if (!docstr) {
if (doxygen) {
docstr = Getattr(n, "python:docstring");
if (!docstr && doxygenTranslator->hasDocumentation(n)) {