Some function return cases fixed.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10748 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
83d60a1d36
commit
ea556b565d
3 changed files with 91 additions and 55 deletions
39
Lib/c/c.swg
39
Lib/c/c.swg
|
|
@ -30,12 +30,12 @@ typedef struct {
|
||||||
%typemap(ctype) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1_type"
|
%typemap(ctype) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1_type"
|
||||||
%typemap(ctype) short &, int &, long &, char &, float &, double & "$1_basetype *"
|
%typemap(ctype) short &, int &, long &, char &, float &, double & "$1_basetype *"
|
||||||
%typemap(ctype) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1_basetype *"
|
%typemap(ctype) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1_basetype *"
|
||||||
%typemap(ctype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype *"
|
%typemap(ctype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype const *"
|
||||||
%typemap(ctype) const short, const int, const long, const char, const float, const double "$1_type"
|
%typemap(ctype) const short, const int, const long, const char, const float, const double "$1_type"
|
||||||
%typemap(ctype) const unsigned short, const unsigned int, const unsigned long, const unsigned char "$1_type"
|
%typemap(ctype) const unsigned short, const unsigned int, const unsigned long, const unsigned char "$1_type"
|
||||||
%typemap(ctype) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$1_type"
|
%typemap(ctype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
|
||||||
%typemap(ctype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$1_basetype *"
|
%typemap(ctype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$1_basetype *"
|
||||||
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [ANY] "$1_basetype **"
|
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1_basetype **"
|
||||||
%typemap(ctype) SWIGTYPE "SwigObj *"
|
%typemap(ctype) SWIGTYPE "SwigObj *"
|
||||||
%typemap(ctype) SWIGTYPE * "SwigObj *"
|
%typemap(ctype) SWIGTYPE * "SwigObj *"
|
||||||
%typemap(ctype) SWIGTYPE & "SwigObj *"
|
%typemap(ctype) SWIGTYPE & "SwigObj *"
|
||||||
|
|
@ -44,25 +44,27 @@ typedef struct {
|
||||||
|
|
||||||
%fragment("stdbool_inc", "proxy_header") {#include <stdbool.h>}
|
%fragment("stdbool_inc", "proxy_header") {#include <stdbool.h>}
|
||||||
%typemap(ctype, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool *, bool * [ANY] "$1_type"
|
%typemap(ctype, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool *, bool * [ANY] "$1_type"
|
||||||
%typemap(ctype, fragment="stdbool_inc") bool &, const bool & "$1_basetype *"
|
%typemap(ctype, fragment="stdbool_inc") bool & "$1_basetype *"
|
||||||
|
%typemap(ctype, fragment="stdbool_inc") const bool & "$1_basetype const *"
|
||||||
|
|
||||||
%typemap(in) short, int, long, char, float, double, bool "$1 = ($1_type) $input;"
|
%typemap(in) short, int, long, char, float, double "$1 = ($1_type) $input;"
|
||||||
%typemap(in) void *, short *, int *, long *, char *, float *, double *, bool * "$1 = ($1_type) $input;"
|
%typemap(in) void *, short *, int *, long *, char *, float *, double * "$1 = ($1_type) $input;"
|
||||||
%typemap(in) void **, short **, int **, long **, char **, float **, double **, bool * "$1 = ($1_basetype **) $input;"
|
%typemap(in) void **, short **, int **, long **, char **, float **, double ** "$1 = ($1_basetype **) $input;"
|
||||||
%typemap(in) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$1 = ($1_type) $input;"
|
%typemap(in) unsigned short *, unsigned int *, unsigned long *, unsigned char * "$1 = ($1_type) $input;"
|
||||||
%typemap(in) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1 = ($1_type) $input;"
|
%typemap(in) unsigned short **, unsigned int **, unsigned long **, unsigned char ** "$1 = ($1_type) $input;"
|
||||||
%typemap(in) const void *, const short *, const int *, const long *, const char *, const float *, const double *, const bool * "$1 = ($1_basetype *) $input;"
|
%typemap(in) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) const unsigned short *, const unsigned int *, const unsigned long *, const unsigned char * "$1 = ($1_type) $input;"
|
%typemap(in) const unsigned short *, const unsigned int *, const unsigned long *, const unsigned char * "$1 = ($1_type) $input;"
|
||||||
%typemap(in) unsigned short, unsigned int, unsigned long, unsigned char "$1 = ($1_type) $input;"
|
%typemap(in) unsigned short, unsigned int, unsigned long, unsigned char "$1 = ($1_type) $input;"
|
||||||
%typemap(in) short &, int &, long &, char &, float &, double &, bool & "$1 = ($1_basetype *) $input;"
|
%typemap(in) short &, int &, long &, char &, float &, double &, bool & "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) const short &, const int &, const long &, const char &, const float &, const double &, const bool & "$1 = ($1_basetype *) $input;"
|
%typemap(in) const short &, const int &, const long &, const char &, const float &, const double & "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1 = ($1_basetype *) $input;"
|
%typemap(in) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$1 = ($1_basetype *) $input;"
|
%typemap(in) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$1 = ($1_basetype *) $input;"
|
%typemap(in) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$1 = ($1_basetype *) $input;"
|
||||||
%typemap(in) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY], bool * [ANY] "$1 = ($1_basetype *) $input;"
|
%typemap(in) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1 = ($1_basetype *) $input;"
|
||||||
|
|
||||||
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool *, bool * [ANY] "$1 = ($1_type) $input;"
|
%typemap(in, fragment="stdbool_inc") bool, bool *, bool **, const bool, const bool * "$1 = ($1_type) $input;"
|
||||||
%typemap(in, fragment="stdbool_inc") bool &, const bool & "$1 = ($1_basetype *) $input;"
|
%typemap(in, fragment="stdbool_inc") bool & "$1 = ($1_basetype *) $input;"
|
||||||
|
%typemap(in, fragment="stdbool_inc") const bool &, const bool * "$1 = ($1_basetype *) $input;"
|
||||||
|
|
||||||
%typemap(in) enum SWIGTYPE "$1 = ($1_type) $input;"
|
%typemap(in) enum SWIGTYPE "$1 = ($1_type) $input;"
|
||||||
|
|
||||||
|
|
@ -102,16 +104,17 @@ typedef struct {
|
||||||
%typemap(couttype) void *, short *, int *, long *, char *, float *, double* "$1_type"
|
%typemap(couttype) void *, short *, int *, long *, char *, float *, double* "$1_type"
|
||||||
%typemap(couttype) const short, const int, const long, const char, const float, const double "$1_basetype"
|
%typemap(couttype) const short, const int, const long, const char, const float, const double "$1_basetype"
|
||||||
%typemap(couttype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
|
%typemap(couttype) const void *, const short *, const int *, const long *, const char *, const float *, const double * "$1_type"
|
||||||
%typemap(couttype) short &, int &, long &, char &, float &, double &, bool & "$1_basetype *"
|
%typemap(couttype) short &, int &, long &, char &, float &, double & "$1_basetype *"
|
||||||
%typemap(couttype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype const *"
|
%typemap(couttype) const short &, const int &, const long &, const char &, const float &, const double & "$1_basetype const *"
|
||||||
%typemap(couttype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$1_basetype *"
|
%typemap(couttype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$1_basetype *"
|
||||||
%typemap(couttype) SWIGTYPE "SwigObj *"
|
%typemap(couttype) SWIGTYPE "SwigObj *"
|
||||||
%typemap(couttype) SWIGTYPE * "SwigObj *"
|
%typemap(couttype) SWIGTYPE * "SwigObj *"
|
||||||
%typemap(couttype) SWIGTYPE & "SwigObj *"
|
%typemap(couttype) SWIGTYPE & "SwigObj *"
|
||||||
%typemap(couttype) enum SWIGTYPE "$1_type"
|
%typemap(couttype) enum SWIGTYPE "$1_type"
|
||||||
|
|
||||||
%typemap(couttype, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$1_type"
|
%typemap(couttype, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$1_type"
|
||||||
%typemap(couttype, fragment="stdbool_inc") bool &, const bool & "$1_basetype *"
|
%typemap(couttype, fragment="stdbool_inc") bool & "$1_basetype*"
|
||||||
|
%typemap(couttype, fragment="stdbool_inc") const bool & "$1_basetype const *"
|
||||||
|
|
||||||
%typemap(out) short, int, long, char, float, double "$result = $1;"
|
%typemap(out) short, int, long, char, float, double "$result = $1;"
|
||||||
%typemap(out) void*, short*, int*, long*, char*, float*, double* "$result = $1;"
|
%typemap(out) void*, short*, int*, long*, char*, float*, double* "$result = $1;"
|
||||||
|
|
@ -123,7 +126,7 @@ typedef struct {
|
||||||
%typemap(out) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$result = $1;"
|
%typemap(out) unsigned short &, unsigned int &, unsigned long &, unsigned char & "$result = $1;"
|
||||||
%typemap(out) const short &, const int &, const long &, const char &, const float &, const double & "$result = $1;"
|
%typemap(out) const short &, const int &, const long &, const char &, const float &, const double & "$result = $1;"
|
||||||
%typemap(out) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$result = $1;"
|
%typemap(out) const unsigned short &, const unsigned int &, const unsigned long &, const unsigned char & "$result = $1;"
|
||||||
%typemap(out) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY], bool [ANY] "$result = $1;"
|
%typemap(out) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$result = $1;"
|
||||||
%typemap(out) void ""
|
%typemap(out) void ""
|
||||||
|
|
||||||
%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = $1;"
|
%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = $1;"
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ class string;
|
||||||
delete $1;
|
delete $1;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(out) string, const string & {
|
%typemap(out) string, const string &, string * {
|
||||||
const char *str = cppresult.c_str();
|
const char *str = cppresult->c_str();
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
$result = (char *) malloc(len + 1);
|
$result = (char *) malloc(len + 1);
|
||||||
memcpy($result, str, len);
|
memcpy($result, str, len);
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,7 @@ public:
|
||||||
* globalfunctionHandler()
|
* globalfunctionHandler()
|
||||||
* ------------------------------------------------------------------------ */
|
* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
virtual int globalfunctionHandler(Node *n ) {
|
virtual int globalfunctionHandler(Node *n) {
|
||||||
String *action = NewString("");
|
String *action = NewString("");
|
||||||
String *vis_hint = NewString("");
|
String *vis_hint = NewString("");
|
||||||
String *return_type_str = SwigType_str(Getattr(n, "type"), 0);
|
String *return_type_str = SwigType_str(Getattr(n, "type"), 0);
|
||||||
|
|
@ -390,8 +390,6 @@ ready:
|
||||||
Node *node = Swig_symbol_clookup(query, symtab);
|
Node *node = Swig_symbol_clookup(query, symtab);
|
||||||
if (node)
|
if (node)
|
||||||
newtype = NewStringf("enum %s", Getattr(node, "name"));
|
newtype = NewStringf("enum %s", Getattr(node, "name"));
|
||||||
else
|
|
||||||
newtype = Copy(enumtype);
|
|
||||||
|
|
||||||
return newtype;
|
return newtype;
|
||||||
}
|
}
|
||||||
|
|
@ -411,6 +409,7 @@ ready:
|
||||||
String *tm;
|
String *tm;
|
||||||
String *proto = NewString("");
|
String *proto = NewString("");
|
||||||
String *over_suffix = NewString("");
|
String *over_suffix = NewString("");
|
||||||
|
SwigType *return_var_type = empty_string;
|
||||||
int gencomma;
|
int gencomma;
|
||||||
bool is_void_return = (SwigType_type(type) == T_VOID);
|
bool is_void_return = (SwigType_type(type) == T_VOID);
|
||||||
|
|
||||||
|
|
@ -503,10 +502,6 @@ ready:
|
||||||
// add variable for holding result of original function
|
// add variable for holding result of original function
|
||||||
bool return_object = false;
|
bool return_object = false;
|
||||||
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
||||||
if (SwigType_isconst(type))
|
|
||||||
SwigType_del_qualifier(type);
|
|
||||||
SwigType *return_var_type;
|
|
||||||
|
|
||||||
SwigType *tdtype = SwigType_typedef_resolve(type);
|
SwigType *tdtype = SwigType_typedef_resolve(type);
|
||||||
if (tdtype)
|
if (tdtype)
|
||||||
type = tdtype;
|
type = tdtype;
|
||||||
|
|
@ -515,11 +510,29 @@ ready:
|
||||||
Wrapper_add_localv(wrapper, "cppresult", "int", "cppresult", NIL);
|
Wrapper_add_localv(wrapper, "cppresult", "int", "cppresult", NIL);
|
||||||
}
|
}
|
||||||
else if (SwigType_isbuiltin(SwigType_base(type))) {
|
else if (SwigType_isbuiltin(SwigType_base(type))) {
|
||||||
|
if (SwigType_isconst(type))
|
||||||
|
SwigType_del_qualifier(type);
|
||||||
|
|
||||||
// type is built-in (int, char, double, etc.)
|
// type is built-in (int, char, double, etc.)
|
||||||
if (SwigType_isreference(type) || SwigType_isarray(type))
|
if (SwigType_isreference(type)) {
|
||||||
return_var_type = SwigType_add_pointer(SwigType_base(type));
|
if (SwigType_isconst(SwigType_del_reference(type))) {
|
||||||
else
|
return_var_type = SwigType_base(type);
|
||||||
|
SwigType_add_qualifier(return_var_type, "const");
|
||||||
|
SwigType_add_pointer(return_var_type);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return_var_type = SwigType_base(type);
|
||||||
|
SwigType_add_pointer(return_var_type);
|
||||||
|
}
|
||||||
|
SwigType_add_reference(type);
|
||||||
|
}
|
||||||
|
else if (SwigType_isarray(type)) {
|
||||||
|
return_var_type = SwigType_base(type);
|
||||||
|
SwigType_add_pointer(return_var_type);
|
||||||
|
}
|
||||||
|
else {
|
||||||
return_var_type = type;
|
return_var_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
||||||
}
|
}
|
||||||
|
|
@ -527,10 +540,14 @@ ready:
|
||||||
// type is class
|
// type is class
|
||||||
if (SwigType_ispointer(type))
|
if (SwigType_ispointer(type))
|
||||||
return_var_type = type;
|
return_var_type = type;
|
||||||
else if (SwigType_isreference(type) || SwigType_isarray(type))
|
else if (SwigType_isreference(type) || SwigType_isarray(type)) {
|
||||||
return_var_type = SwigType_add_pointer(SwigType_base(type));
|
return_var_type = SwigType_base(type);
|
||||||
else
|
SwigType_add_pointer(return_var_type);
|
||||||
return_var_type = SwigType_add_pointer(type);
|
}
|
||||||
|
else {
|
||||||
|
return_var_type = type;
|
||||||
|
SwigType_add_pointer(return_var_type);
|
||||||
|
}
|
||||||
|
|
||||||
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
||||||
return_object = true;
|
return_object = true;
|
||||||
|
|
@ -644,23 +661,23 @@ ready:
|
||||||
if (Cmp(nodeType(n), "constructor") != 0)
|
if (Cmp(nodeType(n), "constructor") != 0)
|
||||||
Replace(action, "result =", "cppresult = $mod", DOH_REPLACE_FIRST);
|
Replace(action, "result =", "cppresult = $mod", DOH_REPLACE_FIRST);
|
||||||
|
|
||||||
// handle return-by-reference
|
// handle special cases of cpp return result
|
||||||
if (SwigType_isreference(type)) {
|
|
||||||
String *ref_cast = NewString("");
|
String *mod = NewString("$mod");
|
||||||
if (SwigType_isconst(SwigType_del_reference(type))) {
|
if (SwigType_isreference(type))
|
||||||
//Printf(ref_cast, "(%s*)", SwigType_str(SwigType_base(type), 0));
|
Replaceall(mod, "$mod", "");
|
||||||
Printf(ref_cast, "*");
|
|
||||||
}
|
|
||||||
Replaceall(action, "$mod", ref_cast);
|
|
||||||
Delete(ref_cast);
|
|
||||||
}
|
|
||||||
else if (SwigType_isenum(type))
|
else if (SwigType_isenum(type))
|
||||||
Replaceall(action, "$mod", "(int)");
|
Replaceall(mod, "$mod", "(int)");
|
||||||
else if (return_object && Getattr(n, "c:retval")) {
|
else if (return_object && Getattr(n, "c:retval"))
|
||||||
Replaceall(action, "$mod", "&");
|
Replaceall(mod, "$mod", "&");
|
||||||
|
else {
|
||||||
|
Delete(mod);
|
||||||
|
mod = empty_string;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Replaceall(action, "$mod", "");
|
Printf(stderr, "\n%s, %s, mod = %s\n", name, type, mod);
|
||||||
|
|
||||||
|
Replaceall(action, "$mod", mod);
|
||||||
|
|
||||||
// emit output typemap if needed
|
// emit output typemap if needed
|
||||||
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
||||||
|
|
@ -854,6 +871,15 @@ ready:
|
||||||
* --------------------------------------------------------------------- */
|
* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int staticmemberfunctionHandler(Node *n) {
|
virtual int staticmemberfunctionHandler(Node *n) {
|
||||||
|
SwigType *type = Getattr(n, "type");
|
||||||
|
SwigType *tdtype;
|
||||||
|
tdtype = SwigType_typedef_resolve(type);
|
||||||
|
if (tdtype)
|
||||||
|
type = tdtype;
|
||||||
|
if (type) {
|
||||||
|
if (!SwigType_ispointer(type) && !SwigType_isreference(type))
|
||||||
|
Setattr(n, "c:retval", "1");
|
||||||
|
}
|
||||||
return Language::staticmemberfunctionHandler(n);
|
return Language::staticmemberfunctionHandler(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -863,8 +889,14 @@ ready:
|
||||||
|
|
||||||
virtual int memberfunctionHandler(Node *n) {
|
virtual int memberfunctionHandler(Node *n) {
|
||||||
SwigType *type = Getattr(n, "type");
|
SwigType *type = Getattr(n, "type");
|
||||||
if (!SwigType_ispointer(type) && !SwigType_ispointer(SwigType_typedef_resolve(type)))
|
SwigType *tdtype;
|
||||||
|
tdtype = SwigType_typedef_resolve(type);
|
||||||
|
if (tdtype)
|
||||||
|
type = tdtype;
|
||||||
|
if (type) {
|
||||||
|
if (!SwigType_ispointer(type) && !SwigType_isreference(type))
|
||||||
Setattr(n, "c:retval", "1");
|
Setattr(n, "c:retval", "1");
|
||||||
|
}
|
||||||
return Language::memberfunctionHandler(n);
|
return Language::memberfunctionHandler(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -923,6 +955,7 @@ ready:
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------
|
/* ---------------------------------------------------------------------
|
||||||
* staticmembervariableHandler()
|
* staticmembervariableHandler()
|
||||||
|
* TODO: refactor
|
||||||
* --------------------------------------------------------------------- */
|
* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int staticmembervariableHandler(Node *n) {
|
virtual int staticmembervariableHandler(Node *n) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue