[Python] Fix lack of generation of docstrings when -O is used.
Also, fix generation of docstrings containing a double quote character. Patch from Richard Boulton in bug#1700146. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9684 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2d962ac1f2
commit
898e5f7f3d
8 changed files with 66 additions and 2 deletions
|
|
@ -1,6 +1,11 @@
|
||||||
Version 1.3.32 (in progress)
|
Version 1.3.32 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
04/20/2007: olly
|
||||||
|
[Python] Fix lack of generation of docstrings when -O is used.
|
||||||
|
Also, fix generation of docstrings containing a double quote
|
||||||
|
character. Patch from Richard Boulton in bug#1700146.
|
||||||
|
|
||||||
04/17/2007: wsfulton
|
04/17/2007: wsfulton
|
||||||
[Java, C#] Support for adding in Java/C# code before and after the intermediary call,
|
[Java, C#] Support for adding in Java/C# code before and after the intermediary call,
|
||||||
specifically related to the marshalling of the proxy type to the intermediary type.
|
specifically related to the marshalling of the proxy type to the intermediary type.
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ callback
|
||||||
class
|
class
|
||||||
constants
|
constants
|
||||||
contract
|
contract
|
||||||
|
docstrings
|
||||||
enum
|
enum
|
||||||
exception
|
exception
|
||||||
exceptshadow
|
exceptshadow
|
||||||
|
|
|
||||||
23
Examples/python/docstrings/Makefile
Normal file
23
Examples/python/docstrings/Makefile
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIG = $(TOP)/../preinst-swig
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS = -lm
|
||||||
|
SWIGOPT = -O
|
||||||
|
|
||||||
|
all::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' \
|
||||||
|
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||||
|
|
||||||
|
static::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' \
|
||||||
|
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||||
|
|
||||||
|
clean::
|
||||||
|
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||||
|
rm -f $(TARGET).py
|
||||||
|
|
||||||
|
check: all
|
||||||
4
Examples/python/docstrings/example.cxx
Normal file
4
Examples/python/docstrings/example.cxx
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#include "example.h"
|
||||||
|
|
||||||
|
void Foo::bar() {}
|
||||||
|
|
||||||
4
Examples/python/docstrings/example.h
Normal file
4
Examples/python/docstrings/example.h
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
void bar();
|
||||||
|
};
|
||||||
14
Examples/python/docstrings/example.i
Normal file
14
Examples/python/docstrings/example.i
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* %feature("docstring") has to come before the declaration of the method to
|
||||||
|
* SWIG. */
|
||||||
|
%feature("docstring") Foo::bar "No comment"
|
||||||
|
|
||||||
|
/* Let's just grab the original header file here */
|
||||||
|
%include "example.h"
|
||||||
|
|
||||||
6
Examples/python/docstrings/runme.py
Normal file
6
Examples/python/docstrings/runme.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# file: runme.py
|
||||||
|
|
||||||
|
import example
|
||||||
|
|
||||||
|
print "example.Foo.bar.__doc__ =", repr(example.Foo.bar.__doc__), "(Should be 'No comment')"
|
||||||
|
|
||||||
|
|
@ -1419,19 +1419,26 @@ public:
|
||||||
Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function);
|
Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n && Getattr(n, "feature:callback")) {
|
if (!n) {
|
||||||
|
Append(methods, "NULL");
|
||||||
|
} else if (Getattr(n, "feature:callback")) {
|
||||||
if (have_docstring(n)) {
|
if (have_docstring(n)) {
|
||||||
String *ds = docstring(n, AUTODOC_FUNC, "", false);
|
String *ds = docstring(n, AUTODOC_FUNC, "", false);
|
||||||
Replaceall(ds, "\n", "\\n");
|
Replaceall(ds, "\n", "\\n");
|
||||||
|
Replaceall(ds, "\"", "\\\"");
|
||||||
Printf(methods, "(char *)\"%s\\nswig_ptr: %s\"", ds, Getattr(n, "feature:callback:name"));
|
Printf(methods, "(char *)\"%s\\nswig_ptr: %s\"", ds, Getattr(n, "feature:callback:name"));
|
||||||
} else {
|
} else {
|
||||||
Printf(methods, "(char *)\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
|
Printf(methods, "(char *)\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
|
||||||
}
|
}
|
||||||
|
} else if (have_docstring(n)) {
|
||||||
|
String *ds = docstring(n, AUTODOC_FUNC, "", false);
|
||||||
|
Replaceall(ds, "\n", "\\n");
|
||||||
|
Replaceall(ds, "\"", "\\\"");
|
||||||
|
Printf(methods, "(char *)\"%s\"", ds);
|
||||||
} else {
|
} else {
|
||||||
Append(methods, "NULL");
|
Append(methods, "NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Append(methods, "},\n");
|
Append(methods, "},\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue