Skip to content

Commit 0c00daf

Browse files
committed
Merge branch 'autodoc-doxygen-fix'
* autodoc-doxygen-fix: Fix crash in Python backend when using empty docstrings
2 parents a0d4218 + e14532c commit 0c00daf

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Examples/test-suite/autodoc.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,12 @@ const int PROCESS_DEFAULT_VALUE = 17;
183183
typedef long int some_type;
184184
int process_complex_defval(int val = PROCESS_DEFAULT_VALUE, int factor = some_type(-1)) { return val*factor; }
185185
%}
186+
187+
// Test for empty docstring, which should be ignored.
188+
%feature("docstring") ""
189+
190+
%inline %{
191+
struct a_structure{
192+
char my_array[1];
193+
};
194+
%}

Examples/test-suite/python/autodoc_runme.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,5 @@ def check(got, expected, expected_builtin=None, skip=False):
279279
check(inspect.getdoc(process4), "process4(int _from=0, int _in=1, int var=2) -> int")
280280

281281
check(inspect.getdoc(process_complex_defval), "process_complex_defval(val=PROCESS_DEFAULT_VALUE, factor=some_type(-1)) -> int")
282+
283+
check(inspect.getdoc(a_structure.__init__), "__init__(a_structure self) -> a_structure", None, skip)

Source/Modules/python.cxx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,15 @@ class PYTHON:public Language {
14841484

14851485
String *build_combined_docstring(Node *n, autodoc_t ad_type, const String *indent = "", bool low_level = false) {
14861486
String *docstr = Getattr(n, "feature:docstring");
1487-
if (docstr && Len(docstr)) {
1488-
docstr = Copy(docstr);
1487+
if (docstr) {
1488+
// Simplify the code below by just ignoring empty docstrings.
1489+
if (!Len(docstr))
1490+
docstr = NULL;
1491+
else
1492+
docstr = Copy(docstr);
1493+
}
1494+
1495+
if (docstr) {
14891496
char *t = Char(docstr);
14901497
if (*t == '{') {
14911498
Delitem(docstr, 0);
@@ -1496,7 +1503,7 @@ class PYTHON:public Language {
14961503
if (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")) {
14971504
String *autodoc = make_autodoc(n, ad_type, low_level);
14981505
if (autodoc && Len(autodoc) > 0) {
1499-
if (docstr && Len(docstr)) {
1506+
if (docstr) {
15001507
Append(autodoc, "\n");
15011508
Append(autodoc, docstr);
15021509
}
@@ -1509,7 +1516,7 @@ class PYTHON:public Language {
15091516
Delete(autodoc);
15101517
}
15111518

1512-
if (!docstr || !Len(docstr)) {
1519+
if (!docstr) {
15131520
if (doxygen) {
15141521
docstr = Getattr(n, "python:docstring");
15151522
if (!docstr && doxygenTranslator->hasDocumentation(n)) {

0 commit comments

Comments
 (0)