implement the 'allowexcept' feature for global variables

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8580 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-01-28 02:41:48 +00:00
commit 1bb180523b
3 changed files with 37 additions and 8 deletions

View file

@ -773,7 +773,8 @@ CHICKEN::variableWrapper(Node *n) {
Replaceall(tm,"$source","value"); Replaceall(tm,"$source","value");
Replaceall(tm,"$target",name); Replaceall(tm,"$target",name);
Replaceall(tm,"$input","value"); Replaceall(tm,"$input","value");
Printv(f->code, tm, "\n",NIL); /* Printv(f->code, tm, "\n",NIL); */
emit_action_code(n, f, tm);
} }
else { else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number,
@ -797,7 +798,8 @@ CHICKEN::variableWrapper(Node *n) {
Replaceall(tm,"$varname",varname); Replaceall(tm,"$varname",varname);
Replaceall(tm,"$target","resultobj"); Replaceall(tm,"$target","resultobj");
Replaceall(tm,"$result","resultobj"); Replaceall(tm,"$result","resultobj");
Printf(f->code, "%s\n", tm); /* Printf(f->code, "%s\n", tm); */
emit_action_code(n, f, tm);
} }
else { else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
@ -983,7 +985,8 @@ CHICKEN::constantWrapper(Node *n)
Replaceall(tm,"$varname",source); Replaceall(tm,"$varname",source);
Replaceall(tm,"$target","resultobj"); Replaceall(tm,"$target","resultobj");
Replaceall(tm,"$result","resultobj"); Replaceall(tm,"$result","resultobj");
Printf(f->code, "%s\n", tm); /* Printf(f->code, "%s\n", tm); */
emit_action_code(n, f, tm);
} }
else { else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,

View file

@ -1498,7 +1498,7 @@ MODULA3 ():
Swig_save ("functionWrapper", n, "wrap:action", NIL); Swig_save ("functionWrapper", n, "wrap:action", NIL);
// below based on Swig_VargetToFunction() // below based on Swig_VargetToFunction()
SwigType *ty = Swig_wrapped_var_type (Getattr (n, "type")); SwigType *ty = Swig_wrapped_var_type (Getattr (n, "type"), use_naturalvar_mode(n));
Setattr (n, "wrap:action", Setattr (n, "wrap:action",
NewStringf ("result = (%s) %s;\n", SwigType_lstr (ty, 0), NewStringf ("result = (%s) %s;\n", SwigType_lstr (ty, 0),
Getattr (n, "value"))); Getattr (n, "value")));

View file

@ -72,6 +72,7 @@ static int fastunpack = 0;
static int modernargs = 0; static int modernargs = 0;
static int aliasobj0 = 0; static int aliasobj0 = 0;
static int castmode = 0; static int castmode = 0;
static int outputtuple = 0;
/* flags for the make_autodoc function */ /* flags for the make_autodoc function */
enum autodoc_t { enum autodoc_t {
@ -113,6 +114,7 @@ static const char *usage2 = (char *)"\
-noh - Don't generate the output header file\n\ -noh - Don't generate the output header file\n\
-nomodern - Don't use modern python features which are not back compatible \n\ -nomodern - Don't use modern python features which are not back compatible \n\
-nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n\ -nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n\
-nooutputtuple - Use a PyList for appending output values (default) \n\
-noproxy - Don't generate proxy classes \n\ -noproxy - Don't generate proxy classes \n\
-noproxydel - Don't generate the redundant __del__ method \n\ -noproxydel - Don't generate the redundant __del__ method \n\
-noproxyimport - Don't insert proxy import statements derived from the %import directive \n\ -noproxyimport - Don't insert proxy import statements derived from the %import directive \n\
@ -120,6 +122,7 @@ static const char *usage2 = (char *)"\
-nosafecstrings - Avoid extra strings copies when possible (default)\n\ -nosafecstrings - Avoid extra strings copies when possible (default)\n\
-nothreads - Disable thread support for all the interface\n\ -nothreads - Disable thread support for all the interface\n\
-old_repr - Use shorter and old version of __repr__ in proxy classes\n\ -old_repr - Use shorter and old version of __repr__ in proxy classes\n\
-outputtuple - Use a PyTuple for outputs instead of a PyList (use carfuly with legacy interfaces) \n\
-proxydel - Generate a __del__ method even when now is redundant (default) \n\ -proxydel - Generate a __del__ method even when now is redundant (default) \n\
-safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\ -safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\
-threads - Add thread support for all the interface\n\ -threads - Add thread support for all the interface\n\
@ -275,6 +278,12 @@ public:
} else if (strcmp(argv[i],"-nocppcast") == 0) { } else if (strcmp(argv[i],"-nocppcast") == 0) {
cppcast = 0; cppcast = 0;
Swig_mark_arg(i); Swig_mark_arg(i);
} else if (strcmp(argv[i],"-outputtuple") == 0) {
outputtuple = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nooutputtuple") == 0) {
outputtuple = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i],"-nortti") == 0) { } else if (strcmp(argv[i],"-nortti") == 0) {
/* Turn on no-RTTI mode */ /* Turn on no-RTTI mode */
Preprocessor_define((DOH *) "SWIG_NORTTI", 0); Preprocessor_define((DOH *) "SWIG_NORTTI", 0);
@ -427,6 +436,12 @@ public:
if (Getattr(options, "nocastmode")) { if (Getattr(options, "nocastmode")) {
castmode = 0; castmode = 0;
} }
if (Getattr(options, "outputtuple")) {
outputtuple = 1;
}
if (Getattr(options, "nooutputtuple")) {
outputtuple = 0;
}
mod_docstring = Getattr(options, "docstring"); mod_docstring = Getattr(options, "docstring");
package = Getattr(options, "package"); package = Getattr(options, "package");
} }
@ -505,6 +520,10 @@ public:
Printf(f_runtime,"#define SWIG_PYTHON_DIRECTOR_NO_VTABLE\n"); Printf(f_runtime,"#define SWIG_PYTHON_DIRECTOR_NO_VTABLE\n");
} }
if (outputtuple) {
Printf(f_runtime,"#define SWIG_PYTHON_OUTPUT_TUPLE\n");
}
if (castmode) { if (castmode) {
Printf(f_runtime,"#define SWIG_CASTRANK_MODE\n"); Printf(f_runtime,"#define SWIG_CASTRANK_MODE\n");
Printf(f_runtime,"#define SWIG_PYTHON_CAST_MODE\n"); Printf(f_runtime,"#define SWIG_PYTHON_CAST_MODE\n");
@ -2092,7 +2111,7 @@ public:
if (Getattr(n,"tmap:varin:implicitconv")) { if (Getattr(n,"tmap:varin:implicitconv")) {
Replaceall(tm,"$implicitconv", get_implicitconv_flag(n)); Replaceall(tm,"$implicitconv", get_implicitconv_flag(n));
} }
Printf(setf->code,"%s\n",tm); emit_action_code(n, setf, tm);
Delete(tm); Delete(tm);
} else { } else {
Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number,
@ -2120,18 +2139,25 @@ public:
/* Create a function for getting the value of a variable */ /* Create a function for getting the value of a variable */
Printf(getf->def,"SWIGINTERN PyObject *%s(void) {", getnamef); Printf(getf->def,"SWIGINTERN PyObject *%s(void) {", getnamef);
Wrapper_add_local(getf,"pyobj", "PyObject *pyobj = 0"); Wrapper_add_local(getf,"pyobj", "PyObject *pyobj = 0");
int addfail = 0;
if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) {
Replaceall(tm,"$source",name); Replaceall(tm,"$source",name);
Replaceall(tm,"$target","pyobj"); Replaceall(tm,"$target","pyobj");
Replaceall(tm,"$result","pyobj"); Replaceall(tm,"$result","pyobj");
Printf(getf->code,"%s\n", tm); addfail = emit_action_code(n, getf, tm);
Delete(tm); Delete(tm);
} else { } else {
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number,
"Unable to read variable of type %s\n", SwigType_str(t,0)); "Unable to read variable of type %s\n", SwigType_str(t,0));
} }
Printf(getf->code," return pyobj;\n}\n"); Append(getf->code," return pyobj;\n");
if (addfail) {
Append(getf->code,"fail:\n");
Append(getf->code," return NULL;\n");
}
Append(getf->code,"}\n");
Wrapper_print(getf,f_wrappers); Wrapper_print(getf,f_wrappers);
/* Now add this to the variable linking mechanism */ /* Now add this to the variable linking mechanism */