Fixed some issues with member variables handling
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11155 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4acb01b741
commit
5002c69cd6
9 changed files with 115 additions and 61 deletions
|
|
@ -1098,17 +1098,19 @@ r_clean:
|
|||
# ----------------------------------------------------------------
|
||||
|
||||
CLIBPREFIX = lib
|
||||
C_LDSHARED = @C_LDSHARED@
|
||||
CXX_LDSHARED = @CXX_LDSHARED@
|
||||
C_SO = @C_SO@
|
||||
|
||||
c: $(SRCS)
|
||||
$(SWIG) -c $(SWIGOPT) $(INTERFACE)
|
||||
$(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES)
|
||||
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(CLIBPREFIX)$(TARGET)$(SO)
|
||||
$(C_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO)
|
||||
|
||||
c_cpp: $(SRCS)
|
||||
$(SWIG) -c++ -c $(SWIGOPT) $(INTERFACE)
|
||||
$(CXX) -c $(CCSHARED) $(CXXFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
|
||||
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(CLIBPREFIX)$(TARGET)$(SO)
|
||||
$(CXX_LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(CLIBPREFIX)$(TARGET)$(C_SO)
|
||||
|
||||
c_compile: $(RUNME) $(PROXY)
|
||||
$(CC) $(RUNME) $(PROXY) -L. -l$(TARGET) -o $(RUNME:.c=)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@ memchk:
|
|||
env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~ runme
|
||||
rm -f *.o *.out *.so *.a *.dll *.dylib *.exe *_wrap* *_proxy* *~ runme
|
||||
|
||||
check: all
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@ memchk:
|
|||
env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~ runme
|
||||
rm -f *.o *.out *.so *.a *.dll *.dylib *.exe *_wrap* *_proxy* *~ runme
|
||||
|
||||
check: all
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@ memchk:
|
|||
env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.so *.out *.a *.exe *.dll *_wrap* *_proxy* *~ runme
|
||||
rm -f *.o *.so *.out *.a *.exe *.dll *.dylib *_wrap* *_proxy* *~ runme
|
||||
|
||||
check: all
|
||||
|
|
|
|||
|
|
@ -12,13 +12,12 @@ top_builddir = @top_builddir@/..
|
|||
|
||||
C_TEST_CASES =
|
||||
|
||||
CPP_TEST_CASES = \
|
||||
cast_operator \
|
||||
char_strings \
|
||||
exception_order \
|
||||
exception_partial_info \
|
||||
enums \
|
||||
enum_plus \
|
||||
CPP_TEST_CASES = cast_operator \
|
||||
char_strings \
|
||||
exception_order \
|
||||
exception_partial_info \
|
||||
enums \
|
||||
enum_plus
|
||||
|
||||
include $(srcdir)/../common.mk
|
||||
|
||||
|
|
|
|||
50
Lib/c/c.swg
50
Lib/c/c.swg
|
|
@ -15,6 +15,7 @@
|
|||
#include <setjmp.h>
|
||||
|
||||
#define SWIG_STR(x) #x
|
||||
#define SWIG_contract_assert(expr, msg) if(!(expr)) { printf("%s\n", msg); SWIG_exit(0); } else
|
||||
%}
|
||||
|
||||
// typemaps for function parameters
|
||||
|
|
@ -34,7 +35,7 @@
|
|||
%typemap(ctype) short *&, int *&, long *&, char *&, float *&, double *& "$1_basetype **"
|
||||
%typemap(ctype) const short *&, const int *&, const long *&, const char *&, const float *&, const double *& "$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] "$1_basetype **"
|
||||
%typemap(ctype) void * [ANY], short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$1_basetype *"
|
||||
%typemap(ctype) void [ANY][ANY], short [ANY][ANY], int [ANY][ANY], long [ANY][ANY], char [ANY][ANY], float [ANY][ANY], double [ANY][ANY] "$1_basetype **"
|
||||
%typemap(ctype) SWIGTYPE "SwigObj *"
|
||||
%typemap(ctype) SWIGTYPE * "SwigObj *"
|
||||
|
|
@ -96,10 +97,13 @@
|
|||
$1 = ($1_ltype) 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* unsupported yet
|
||||
%typemap(freearg) SWIGTYPE * [ANY], SWIGTYPE * [ANY][ANY], SWIGTYPE **, SWIGTYPE *** {
|
||||
if (arg2)
|
||||
free(arg2);
|
||||
if ($input)
|
||||
free($input);
|
||||
}
|
||||
*/
|
||||
|
||||
%typemap(in) SWIGTYPE * [ANY][ANY], SWIGTYPE *** {
|
||||
if ($input) {
|
||||
|
|
@ -143,9 +147,11 @@
|
|||
%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 **"
|
||||
%typemap(couttype) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [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 [ANY] "SwigObj **"
|
||||
%typemap(couttype) SWIGTYPE * [ANY], SWIGTYPE ** "SwigObj **"
|
||||
%typemap(couttype) SWIGTYPE * [ANY][ANY], SWIGTYPE *** "SwigObj ***"
|
||||
%typemap(couttype) enum SWIGTYPE "$1_type"
|
||||
|
|
@ -167,6 +173,7 @@
|
|||
%typemap(out) short *&, int *&, long *&, char *&, float *&, double *& "$result = $1;"
|
||||
%typemap(out) const short *&, const int *&, const long *&, const char *&, const float *&, const double *& "$result = $1;"
|
||||
%typemap(out) short [ANY], int [ANY], long [ANY], char [ANY], float [ANY], double [ANY] "$result = $1;"
|
||||
%typemap(out) short * [ANY], int * [ANY], long * [ANY], char * [ANY], float * [ANY], double * [ANY] "$result = $1;"
|
||||
%typemap(out) void ""
|
||||
|
||||
%typemap(out, fragment="stdbool_inc") bool, bool *, const bool, const bool * "$result = $1;"
|
||||
|
|
@ -175,31 +182,41 @@
|
|||
%typemap(out) enum SWIGTYPE "$result = ($1_type) $1;"
|
||||
|
||||
%typemap(out) SWIGTYPE {
|
||||
$result = SWIG_create_object(SWIG_STR($1_type));
|
||||
$result = SWIG_temporary;
|
||||
$result->obj = (void*) &$1;
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE *, SWIGTYPE & {
|
||||
$result = SWIG_create_object(SWIG_STR($1_basetype));
|
||||
$result = SWIG_temporary;
|
||||
$result->obj = (void*) $1;
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE * [ANY], SWIGTYPE ** {
|
||||
static SwigObj **_temp = 0;
|
||||
if ($1) {
|
||||
$result = (SwigObj**) malloc($1_dim0 * sizeof(SwigObj*));
|
||||
size_t i = 0;
|
||||
for ( ; i < $1_dim0; ++i)
|
||||
if (_temp) {
|
||||
for ( ; i < $1_dim0; ++i)
|
||||
SWIG_destroy_object(_temp[i]);
|
||||
free(_temp);
|
||||
}
|
||||
_temp = (SwigObj**) malloc($1_dim0 * sizeof(SwigObj*));
|
||||
for (i = 0 ; i < $1_dim0; ++i) {
|
||||
if ($1[i]) {
|
||||
$result[i] = SWIG_create_object(SWIG_STR($1_ltype));
|
||||
$result[i]->obj = (void*) $1[i];
|
||||
_temp[i] = SWIG_create_object(SWIG_STR($1_ltype));
|
||||
_temp[i]->obj = (void*) $1[i];
|
||||
}
|
||||
else
|
||||
$result[i] = (SwigObj*) 0;
|
||||
_temp[i] = (SwigObj*) 0;
|
||||
}
|
||||
$result = _temp;
|
||||
}
|
||||
else
|
||||
$result = (SwigObj**) 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 2+ dim arrays - not supported yet
|
||||
%typemap(out) SWIGTYPE * [ANY][ANY], SWIGTYPE *** {
|
||||
if ($1) {
|
||||
$result = (SwigObj***) malloc($1_dim0 * $1_dim1 * sizeof(SwigObj*));
|
||||
|
|
@ -217,7 +234,7 @@
|
|||
}
|
||||
else
|
||||
$result = (SwigObj***) 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
#ifdef SWIG_C_EXCEPT
|
||||
|
|
@ -228,6 +245,11 @@ typedef struct {
|
|||
} SwigObj;
|
||||
%}
|
||||
%include "cexcept.swg"
|
||||
#ifdef SWIG_CPPMODE
|
||||
%insert("runtime") %{
|
||||
SwigObj *SWIG_temporary = (SwigObj *) malloc(sizeof(SwigObj));
|
||||
%}
|
||||
#endif
|
||||
#else
|
||||
%insert("runtime") %{
|
||||
typedef struct {
|
||||
|
|
@ -247,6 +269,12 @@ SWIGEXPORTC int SWIG_exit(int code) {
|
|||
#endif
|
||||
%}
|
||||
|
||||
#ifdef SWIG_CPPMODE
|
||||
%insert("runtime") %{
|
||||
SwigObj *SWIG_temporary = (SwigObj *) malloc(sizeof(SwigObj));
|
||||
%}
|
||||
#endif
|
||||
|
||||
%insert("proxy_header") %{
|
||||
typedef struct {
|
||||
void *obj;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
// this is used instead of default SWIGEXPORT symbol
|
||||
|
||||
#ifndef SWIGEXPORTC
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__APPLE__)
|
||||
# define SWIGEXPORTC
|
||||
# else
|
||||
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef SWIGPROTECT
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__APPLE__)
|
||||
# define SWIGPROTECT(x)
|
||||
# else
|
||||
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
|
||||
|
|
|
|||
|
|
@ -78,14 +78,15 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (!CPlusPlus)
|
||||
if (!CPlusPlus)
|
||||
except_flag = false;
|
||||
|
||||
// add a symbol to the parser for conditional compilation
|
||||
Preprocessor_define("SWIGC 1", 0);
|
||||
Preprocessor_define("SWIG_C_RUNTME 1", 0);
|
||||
if (except_flag)
|
||||
Preprocessor_define("SWIG_C_EXCEPT 1", 0);
|
||||
if (CPlusPlus)
|
||||
Preprocessor_define("SWIG_CPPMODE 1", 0);
|
||||
|
||||
SWIG_library_directory("c");
|
||||
|
||||
|
|
@ -199,7 +200,7 @@ public:
|
|||
}
|
||||
|
||||
Swig_register_filebyname("header", f_header);
|
||||
Swig_register_filebyname("wrappers", f_wrappers);
|
||||
Swig_register_filebyname("wrapper", f_wrappers);
|
||||
Swig_register_filebyname("runtime", f_runtime);
|
||||
Swig_register_filebyname("init", f_init);
|
||||
|
||||
|
|
@ -425,7 +426,7 @@ ready:
|
|||
/* ----------------------------------------------------------------------
|
||||
* functionWrapper()
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
virtual int functionWrapper(Node *n) {
|
||||
String *name = Getattr(n, "sym:name");
|
||||
SwigType *type = Getattr(n, "type");
|
||||
|
|
@ -544,13 +545,13 @@ ready:
|
|||
Swig_warning(WARN_C_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No couttype typemap defined for %s\n", SwigType_str(type, 0));
|
||||
}
|
||||
|
||||
// add variable for holding result of original function
|
||||
// add variable for holding result of original function 'cppresult'
|
||||
bool return_object = false;
|
||||
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
||||
SwigType *tdtype = SwigType_typedef_resolve(type);
|
||||
if (tdtype)
|
||||
type = tdtype;
|
||||
|
||||
|
||||
if (SwigType_isenum(type)) {
|
||||
Wrapper_add_localv(wrapper, "cppresult", "int", "cppresult", NIL);
|
||||
}
|
||||
|
|
@ -575,12 +576,15 @@ ready:
|
|||
SwigType_add_reference(type);
|
||||
}
|
||||
else if (SwigType_isarray(type)) {
|
||||
|
||||
return_var_type = SwigType_base(type);
|
||||
SwigType *atype = Copy(type);
|
||||
do {
|
||||
SwigType_del_array(atype);
|
||||
SwigType_add_pointer(return_var_type);
|
||||
} while (SwigType_isarray(atype));
|
||||
if (SwigType_ispointer(atype))
|
||||
SwigType_add_pointer(return_var_type);
|
||||
Delete(atype);
|
||||
}
|
||||
else {
|
||||
|
|
@ -611,6 +615,7 @@ ready:
|
|||
SwigType_add_pointer(return_var_type);
|
||||
}
|
||||
else {
|
||||
SwigType_add_pointer(type);
|
||||
return_var_type = type;
|
||||
}
|
||||
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
||||
|
|
@ -687,7 +692,10 @@ ready:
|
|||
gencomma = 1;
|
||||
|
||||
// apply typemaps for input parameter
|
||||
if ((tm = Getattr(p, "tmap:in"))) {
|
||||
if (Cmp(nodeType(n), "destructor") == 0) {
|
||||
p = Getattr(p, "tmap:in:next");
|
||||
}
|
||||
else if ((tm = Getattr(p, "tmap:in"))) {
|
||||
if (dont_apply_tmap) {
|
||||
Printv(wrapper->code, lname, " = ", arg_name, ";\n", NIL);
|
||||
}
|
||||
|
|
@ -702,6 +710,7 @@ ready:
|
|||
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(type, 0));
|
||||
p = nextSibling(p);
|
||||
}
|
||||
|
||||
|
||||
Delete(arg_name);
|
||||
Delete(proxy_parm_type);
|
||||
|
|
@ -710,12 +719,14 @@ ready:
|
|||
|
||||
Printf(wrapper->def, ") {");
|
||||
|
||||
// emit variables for holding parameters
|
||||
emit_parameter_variables(parms, wrapper);
|
||||
|
||||
// emit variable for holding function return value
|
||||
emit_return_variable(n, return_type, wrapper);
|
||||
|
||||
if (Cmp(nodeType(n), "destructor") != 0) {
|
||||
// emit variables for holding parameters
|
||||
emit_parameter_variables(parms, wrapper);
|
||||
|
||||
// emit variable for holding function return value
|
||||
emit_return_variable(n, return_type, wrapper);
|
||||
}
|
||||
|
||||
// insert constraint checking
|
||||
for (p = parms; p; ) {
|
||||
if ((tm = Getattr(p, "tmap:check"))) {
|
||||
|
|
@ -1043,7 +1054,11 @@ ready:
|
|||
String *code = NewString("");
|
||||
|
||||
// create code for 'get' function
|
||||
Printv(code, "result = ", classname, "::", name, ";\n", NIL);
|
||||
Printv(code, "result = $mod", classname, "::", name, ";\n", NIL);
|
||||
if (!SwigType_isbuiltin(SwigType_base(type)) && !SwigType_ispointer(type))
|
||||
Replaceall(code, "$mod", "&");
|
||||
else
|
||||
Replaceall(code, "$mod", "");
|
||||
wrap_get_variable(n, classname, newclassname, name, code);
|
||||
|
||||
// create parameter for 'set' function
|
||||
|
|
@ -1066,7 +1081,11 @@ ready:
|
|||
}
|
||||
else
|
||||
code = NewString("");
|
||||
Printv(code, classname, "::", name, " = arg1;\n", NIL);
|
||||
Printv(code, classname, "::", name, " = $mod arg1;\nresult = arg1;\n", NIL);
|
||||
if (!SwigType_isbuiltin(SwigType_base(type)) && !SwigType_ispointer(type))
|
||||
Replaceall(code, "$mod", "*");
|
||||
else
|
||||
Replaceall(code, "$mod", "");
|
||||
wrap_set_variable(n, classname, newclassname, name, code);
|
||||
}
|
||||
|
||||
|
|
@ -1082,26 +1101,14 @@ ready:
|
|||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int membervariableHandler(Node *n) {
|
||||
SwigType *type = Copy(Getattr(n, "type"));
|
||||
SwigType *tdtype;
|
||||
tdtype = SwigType_typedef_resolve(type);
|
||||
if (tdtype)
|
||||
type = tdtype;
|
||||
|
||||
int array_count = 0;
|
||||
while (SwigType_isarray(type)) {
|
||||
SwigType_del_array(type);
|
||||
array_count++;
|
||||
SwigType *type = Getattr(n, "type");
|
||||
SwigType *btype = SwigType_base(type);
|
||||
if (SwigType_isarray(type) && !SwigType_isbuiltin(btype)) {
|
||||
// this hack applies to member objects array (not ptrs.)
|
||||
SwigType_add_pointer(btype);
|
||||
SwigType_add_array(btype, NewStringf("%s", SwigType_array_getdim(type, 0)));
|
||||
Setattr(n, "type", btype);
|
||||
}
|
||||
if (type) {
|
||||
if (!SwigType_ispointer(type) && !SwigType_isreference(type))
|
||||
Setattr(n, "c:retval", "1");
|
||||
}
|
||||
while (array_count) {
|
||||
SwigType_add_pointer(type);
|
||||
array_count--;
|
||||
}
|
||||
Delete(type);
|
||||
return Language::membervariableHandler(n);
|
||||
}
|
||||
|
||||
|
|
@ -1289,7 +1296,7 @@ ready:
|
|||
// create action code
|
||||
if (except_flag) {
|
||||
Printf(code, "SWIG_remove_registry_entry(carg1);\n");
|
||||
Printf(code, "SWIG_destroy_object(arg1);\n");
|
||||
Printf(code, "SWIG_destroy_object(carg1);");
|
||||
}
|
||||
else {
|
||||
Printv(code, "if (carg1->obj)\ndelete (", classname, " *) (carg1->obj);\n", NIL);
|
||||
|
|
|
|||
18
configure.in
18
configure.in
|
|
@ -1815,6 +1815,24 @@ fi
|
|||
|
||||
AC_SUBST(RBIN)
|
||||
|
||||
# C module on Mac OS X tweaks
|
||||
case $host in
|
||||
*-*-darwin*)
|
||||
C_LDSHARED="cc -dynamiclib"
|
||||
CXX_LDSHARED="g++ -dynamiclib"
|
||||
C_SO=".dylib"
|
||||
;;
|
||||
*)
|
||||
C_LDSHARED=$(LDSHARED)
|
||||
CXX_LDSHARED="$(CXXSHARED)"
|
||||
C_SO=$(SO)
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_SUBST(C_LDSHARED)
|
||||
AC_SUBST(CXX_LDSHARED)
|
||||
AC_SUBST(C_SO)
|
||||
|
||||
#----------------------------------------------------------------
|
||||
# Determine which languages to use for examples/test-suite
|
||||
#----------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue