Modified the WrapperFunction class. Fixed various bugs
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@555 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
ddbe3d7361
commit
64e2755215
18 changed files with 524 additions and 492 deletions
|
|
@ -346,22 +346,22 @@ GUILE::close (void)
|
|||
|
||||
void
|
||||
GUILE::get_pointer (char *iname, int parm, DataType *t,
|
||||
WrapperFunction &f, DOHString_or_char *proc_name,
|
||||
Wrapper *f, DOHString_or_char *proc_name,
|
||||
int num_scheme_parm)
|
||||
{
|
||||
/* Pointers are smobs */
|
||||
Printf(f.code, " if (SWIG_Guile_GetPtr_Str(s_%d,(void **) &_arg%d", parm, parm);
|
||||
Printf(f->code, " if (SWIG_Guile_GetPtr_Str(s_%d,(void **) &_arg%d", parm, parm);
|
||||
if (t->type == T_VOID)
|
||||
Printf(f.code, ", (char *) 0)) {\n");
|
||||
Printf(f->code, ", (char *) 0)) {\n");
|
||||
else
|
||||
Printv(f.code, ", \"", t->print_mangle(), "\")) {\n", 0);
|
||||
Printv(f->code, ", \"", t->print_mangle(), "\")) {\n", 0);
|
||||
/* Raise exception */
|
||||
Printv(f.code,
|
||||
Printv(f->code,
|
||||
tab8,
|
||||
"scm_wrong_type_arg(\"",proc_name, "\", ",
|
||||
0);
|
||||
Printf(f.code,"%d, s_%d);\n", num_scheme_parm, parm);
|
||||
Printv(f.code, tab4, "}\n", 0);
|
||||
Printf(f->code,"%d, s_%d);\n", num_scheme_parm, parm);
|
||||
Printv(f->code, tab4, "}\n", 0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
@ -405,10 +405,11 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
DOHString *proc_name = 0;
|
||||
char source[256], target[256], argnum[256], arg[256];
|
||||
char *tm;
|
||||
WrapperFunction f;
|
||||
Wrapper *f;
|
||||
DOHString *cleanup;
|
||||
DOHString *outarg;
|
||||
|
||||
f = NewWrapper();
|
||||
outarg = NewString("");
|
||||
cleanup = NewString("");
|
||||
|
||||
|
|
@ -422,7 +423,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// Now write the wrapper function itself....this is pretty ugly
|
||||
|
||||
Printv(f.def, "static SCM\n", wname," (", 0);
|
||||
Printv(f->def, "static SCM\n", wname," (", 0);
|
||||
|
||||
int i = 0;
|
||||
int first_arg = 1;
|
||||
|
|
@ -431,17 +432,17 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
continue;
|
||||
if ((p->t->type != T_VOID) || (p->t->is_pointer)) {
|
||||
if (!first_arg)
|
||||
Printf(f.def,", ");
|
||||
Printf(f.def,"SCM s_%d", i);
|
||||
Printf(f->def,", ");
|
||||
Printf(f->def,"SCM s_%d", i);
|
||||
first_arg = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Printf(f.def, ")\n{\n");
|
||||
Printf(f->def, ")\n{\n");
|
||||
|
||||
// Define the scheme name in C
|
||||
|
||||
Printv(f.def, "#define SCHEME_NAME \"", proc_name, "\"\n", 0);
|
||||
Printv(f->def, "#define SCHEME_NAME \"", proc_name, "\"\n", 0);
|
||||
|
||||
// Declare return variable and arguments
|
||||
|
||||
|
|
@ -449,7 +450,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
int numargs = 0;
|
||||
int numopt = 0;
|
||||
|
||||
f.add_local ((char*)"SCM", (char*)"gswig_result");
|
||||
Wrapper_add_local (f,(char*)"SCM", (char*)"gswig_result", 0);
|
||||
|
||||
// Now write code to extract the parameters (this is super ugly)
|
||||
|
||||
|
|
@ -467,13 +468,13 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
// Handle parameter types.
|
||||
|
||||
if (p.ignore)
|
||||
Printv(f.code, "/* ", p.name, " ignored... */\n", 0);
|
||||
Printv(f->code, "/* ", p.name, " ignored... */\n", 0);
|
||||
else {
|
||||
++numargs;
|
||||
if ((tm = typemap_lookup ((char*)"in", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
Printv(f.code,tm,"\n",0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
p.t, p.name, source, target, f))) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
else if (p.t->is_pointer)
|
||||
get_pointer (iname, i, p.t, f, proc_name, numargs);
|
||||
|
|
@ -486,15 +487,15 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
// Check if there are any constraints.
|
||||
|
||||
if ((tm = typemap_lookup ((char*)"check", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
Printv(f.code,tm,"\n",0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
p.t, p.name, source, target, f))) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
|
||||
// Pass output arguments back to the caller.
|
||||
|
||||
if ((tm = typemap_lookup ((char*)"argout", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
p.t, p.name, source, target, f))) {
|
||||
Printv(outarg,tm,"\n",0);
|
||||
mreplace (outarg, argnum, arg, proc_name);
|
||||
}
|
||||
|
|
@ -502,30 +503,30 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
// Free up any memory allocated for the arguments.
|
||||
|
||||
if ((tm = typemap_lookup ((char*)"freearg", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
p.t, p.name, source, target, f))) {
|
||||
Printv(cleanup, tm, "\n", 0);
|
||||
mreplace (cleanup, argnum, arg, proc_name);
|
||||
}
|
||||
}
|
||||
|
||||
// Now write code to make the function call
|
||||
Printv(f.code, tab4, "gh_defer_ints();\n", 0);
|
||||
Printv(f->code, tab4, "gh_defer_ints();\n", 0);
|
||||
emit_func_call (name, d, l, f);
|
||||
Printv(f.code, tab4, "gh_allow_ints();\n", 0);
|
||||
Printv(f->code, tab4, "gh_allow_ints();\n", 0);
|
||||
|
||||
// Now have return value, figure out what to do with it.
|
||||
|
||||
if (d->type == T_VOID)
|
||||
Printv(f.code, tab4, "gswig_result = GH_UNSPECIFIED;\n", 0);
|
||||
Printv(f->code, tab4, "gswig_result = GH_UNSPECIFIED;\n", 0);
|
||||
else if ((tm = typemap_lookup ((char*)"out", typemap_lang,
|
||||
d, name, (char*)"_result", (char*)"gswig_result", &f))) {
|
||||
Printv(f.code,tm,"\n",0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
d, name, (char*)"_result", (char*)"gswig_result", f))) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
else if (d->is_pointer) {
|
||||
/* MK: I would like to use SWIG_Guile_MakePtr here to save one type
|
||||
look-up. */
|
||||
Printv(f.code, tab4,
|
||||
Printv(f->code, tab4,
|
||||
"gswig_result = SWIG_Guile_MakePtr_Str (",
|
||||
"_result, ",
|
||||
"\"", d->print_mangle(), "\", ",
|
||||
|
|
@ -538,39 +539,39 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
}
|
||||
|
||||
// Dump the argument output code
|
||||
Printv(f.code,outarg,0);
|
||||
Printv(f->code,outarg,0);
|
||||
|
||||
// Dump the argument cleanup code
|
||||
Printv(f.code,cleanup,0);
|
||||
Printv(f->code,cleanup,0);
|
||||
|
||||
// Look for any remaining cleanup
|
||||
|
||||
if (NewObject) {
|
||||
if ((tm = typemap_lookup ((char*)"newfree", typemap_lang,
|
||||
d, iname, (char*)"_result", (char*)"", &f))) {
|
||||
Printv(f.code,tm,"\n",0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
d, iname, (char*)"_result", (char*)"", f))) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
}
|
||||
|
||||
// Free any memory allocated by the function being wrapped..
|
||||
|
||||
if ((tm = typemap_lookup ((char*)"ret", typemap_lang,
|
||||
d, name, (char*)"_result", (char*)"", &f))) {
|
||||
Printv(f.code,tm,"\n",0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
d, name, (char*)"_result", (char*)"", f))) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
|
||||
// Wrap things up (in a manner of speaking)
|
||||
|
||||
Printv(f.code, tab4, "return gswig_result;\n", 0);
|
||||
Printv(f->code, tab4, "return gswig_result;\n", 0);
|
||||
|
||||
// Undefine the scheme name
|
||||
|
||||
Printf(f.code, "#undef SCHEME_NAME\n");
|
||||
Printf(f.code, "}\n");
|
||||
Printf(f->code, "#undef SCHEME_NAME\n");
|
||||
Printf(f->code, "}\n");
|
||||
|
||||
f.print (f_wrappers);
|
||||
Wrapper_print (f, f_wrappers);
|
||||
|
||||
if (numargs > 10) {
|
||||
// Guile would complain: too many args
|
||||
|
|
@ -587,6 +588,7 @@ GUILE::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
Delete(proc_name);
|
||||
Delete(outarg);
|
||||
Delete(cleanup);
|
||||
DelWrapper(f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ private:
|
|||
GUILE_LSTYLE_HOBBIT // use (hobbit4d link)
|
||||
} linkage;
|
||||
void get_pointer(char *iname, int parm, DataType *t,
|
||||
WrapperFunction &f, DOHString_or_char *proc_name,
|
||||
Wrapper *f, DOHString_or_char *proc_name,
|
||||
int num_scheme_parm);
|
||||
void usage_var(char *, DataType *, DOHString *usage);
|
||||
void usage_func(char *, DataType *, ParmList *, DOHString *usage);
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
javaParameterSignature = NewString("");
|
||||
|
||||
// A new wrapper function object
|
||||
WrapperFunction f;
|
||||
Wrapper *f = NewWrapper();
|
||||
|
||||
if(!classdef_emitted) emit_classdef();
|
||||
|
||||
|
|
@ -560,7 +560,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
}
|
||||
|
||||
if(t->type != T_VOID || t->is_pointer) {
|
||||
f.add_local(jnirettype, (char*)"_jresult", (char*)"0");
|
||||
Wrapper_add_local(f,jnirettype, (char*)"_jresult", (char*)"0");
|
||||
}
|
||||
|
||||
Printf(f_java, " %s ", method_modifiers);
|
||||
|
|
@ -577,8 +577,8 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
Delete(member_name);
|
||||
}
|
||||
|
||||
if(!jnic) Printf(f.def,"extern \"C\"\n");
|
||||
Printv(f.def, "JNIEXPORT ", jnirettype, " JNICALL ", wname, "(JNIEnv *jenv, jclass jcls", 0);
|
||||
if(!jnic) Printf(f->def,"extern \"C\"\n");
|
||||
Printv(f->def, "JNIEXPORT ", jnirettype, " JNICALL ", wname, "(JNIEnv *jenv, jclass jcls", 0);
|
||||
|
||||
// Emit all of the local variables for holding arguments.
|
||||
int pcount = emit_args(t,l,f);
|
||||
|
|
@ -621,24 +621,24 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
gencomma = 1;
|
||||
|
||||
// Add to Jni function header
|
||||
Printv(f.def, ", ", jnitype, " ", source, 0);
|
||||
Printv(f->def, ", ", jnitype, " ", source, 0);
|
||||
|
||||
// Get typemap for this argument
|
||||
tm = typemap_lookup((char*)"in",typemap_lang,p->t,p->name,source,target,&f);
|
||||
tm = typemap_lookup((char*)"in",typemap_lang,p->t,p->name,source,target,f);
|
||||
if (tm) {
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Replace(f.code,"$arg",source, DOH_REPLACE_ANY);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
Replace(f->code,"$arg",source, DOH_REPLACE_ANY);
|
||||
} else {
|
||||
if(!p->t->is_pointer)
|
||||
Printv(f.code, tab4, target, " = ", p->t->print_cast(), source, ";\n", 0);
|
||||
Printv(f->code, tab4, target, " = ", p->t->print_cast(), source, ";\n", 0);
|
||||
else if((p->t->type == T_VOID && p->t->is_pointer == 1) ||
|
||||
(p->t->type == T_USER && p->t->is_pointer == 1)) {
|
||||
p->t->is_pointer++;
|
||||
Printv(f.code, tab4, target, " = *", p->t->print_cast(), "&", source, ";\n", 0);
|
||||
Printv(f->code, tab4, target, " = *", p->t->print_cast(), "&", source, ";\n", 0);
|
||||
p->t->is_pointer--;
|
||||
} else {
|
||||
if(p->t->type == T_CHAR && p->t->is_pointer == 1) {
|
||||
Printv(f.code, tab4, target, " = (", source, ") ? (char *)", JNICALL((char*)"GetStringUTFChars"), source, ", 0) : NULL;\n", 0);
|
||||
Printv(f->code, tab4, target, " = (", source, ") ? (char *)", JNICALL((char*)"GetStringUTFChars"), source, ", 0) : NULL;\n", 0);
|
||||
} else {
|
||||
char *scalarType = SwigTcToJniScalarType(p->t);
|
||||
char *cptrtype = p->t->print_type();
|
||||
|
|
@ -654,20 +654,20 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
DOHString *basic_jniptrtype = NewStringf("%s*",basic_jnitype);
|
||||
DOHString *source_length = NewStringf("%s%s)", JNICALL((char*)"GetArrayLength"), source);
|
||||
|
||||
target_copy = Swig_copy_string(f.new_local(Char(basic_jniptrtype), target, NULL));
|
||||
target_length = Swig_copy_string(f.new_local((char*)"jsize", target, Char(source_length)));
|
||||
if(local_i == NULL) local_i = Swig_copy_string(f.new_local((char*)"int", (char*)"i", NULL));
|
||||
target_copy = Swig_copy_string(Wrapper_new_local(f,Char(basic_jniptrtype), target, NULL));
|
||||
target_length = Swig_copy_string(Wrapper_new_local(f,(char*)"jsize", target, Char(source_length)));
|
||||
if(local_i == NULL) local_i = Swig_copy_string(Wrapper_new_local(f,(char*)"int", (char*)"i", NULL));
|
||||
|
||||
DOHString *scalarFunc = NewStringf("Get%sArrayElements",scalarType);
|
||||
|
||||
Printv(f.code, tab4, target_copy, " = ", JNICALL(scalarFunc), source, ", 0);\n", 0);
|
||||
Printv(f.code, tab4, target, " = ", p->t->print_cast(), " malloc(", target_length, " * sizeof(", ctype, "));\n", 0);
|
||||
Printv(f.code, tab4, "for(i=0; i<", target_length, "; i++)\n", 0);
|
||||
Printv(f->code, tab4, target_copy, " = ", JNICALL(scalarFunc), source, ", 0);\n", 0);
|
||||
Printv(f->code, tab4, target, " = ", p->t->print_cast(), " malloc(", target_length, " * sizeof(", ctype, "));\n", 0);
|
||||
Printv(f->code, tab4, "for(i=0; i<", target_length, "; i++)\n", 0);
|
||||
if(p->t->is_pointer > 1) {
|
||||
Printv(f.code, tab8, target, "[i] = *", p->t->print_cast(), "&", target_copy, "[i];\n", 0);
|
||||
Printv(f->code, tab8, target, "[i] = *", p->t->print_cast(), "&", target_copy, "[i];\n", 0);
|
||||
} else {
|
||||
p->t->is_pointer--;
|
||||
Printv(f.code, tab8, target, "[i] = ", p->t->print_cast(), target_copy, "[i];\n", 0);
|
||||
Printv(f->code, tab8, target, "[i] = ", p->t->print_cast(), target_copy, "[i];\n", 0);
|
||||
p->t->is_pointer++;
|
||||
}
|
||||
Delete(scalarFunc);
|
||||
|
|
@ -680,8 +680,8 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
// Check to see if there was any sort of a constaint typemap
|
||||
if ((tm = typemap_lookup((char*)"check",typemap_lang,p->t,p->name,source,target))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Replace(f.code,"$arg",source, DOH_REPLACE_ANY);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
Replace(f->code,"$arg",source, DOH_REPLACE_ANY);
|
||||
}
|
||||
|
||||
// Check if there was any cleanup code (save it for later)
|
||||
|
|
@ -738,7 +738,7 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
Printf(body,")");
|
||||
Printf(f_shadow, "%s;\n }\n\n",body);
|
||||
}
|
||||
Printf(f.def,") {");
|
||||
Printf(f->def,") {");
|
||||
|
||||
// Now write code to make the function call
|
||||
|
||||
|
|
@ -749,27 +749,27 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
|
||||
if((t->type != T_VOID || t->is_pointer) && !native_func) {
|
||||
if ((tm = typemap_lookup((char*)"out",typemap_lang,t,iname,(char*)"_result",(char*)"_jresult"))) {
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
} else {
|
||||
if(t->is_pointer == 0 && t->type == T_USER) { /* return by value */
|
||||
t->is_pointer=2;
|
||||
Printv(f.code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
|
||||
Printv(f->code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
|
||||
t->is_pointer=0;
|
||||
} else if(t->is_pointer == 0 && t->type != T_USER) {
|
||||
Printv(f.code, tab4, "_jresult = (", jnirettype, ") _result;\n", 0);
|
||||
Printv(f->code, tab4, "_jresult = (", jnirettype, ") _result;\n", 0);
|
||||
} else if((t->type == T_VOID && t->is_pointer == 1) ||
|
||||
(t->type == T_USER && t->is_pointer == 1)) {
|
||||
t->is_pointer++;
|
||||
Printv(f.code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
|
||||
Printv(f->code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
|
||||
t->is_pointer--;
|
||||
} else {
|
||||
if(t->type == T_CHAR && t->is_pointer == 1) {
|
||||
Printv(f.code, tab4, "if(_result != NULL)\n", 0);
|
||||
Printv(f.code, tab8, "_jresult = (jstring)", JNICALL((char*)"NewStringUTF"), "_result);\n", 0);
|
||||
Printv(f->code, tab4, "if(_result != NULL)\n", 0);
|
||||
Printv(f->code, tab8, "_jresult = (jstring)", JNICALL((char*)"NewStringUTF"), "_result);\n", 0);
|
||||
} else {
|
||||
Printf(stderr,"%s : Line %d. Warning: no return typemap for datatype %s\n", input_file,line_number,t->print_type());
|
||||
t->is_pointer++;
|
||||
Printv(f.code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
|
||||
Printv(f->code, tab4, "*", t->print_cast(), "&_jresult = _result;\n", 0);
|
||||
t->is_pointer--;
|
||||
}
|
||||
}
|
||||
|
|
@ -777,37 +777,37 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
}
|
||||
|
||||
// Dump argument output code;
|
||||
Printv(f.code, outarg, 0);
|
||||
Printv(f->code, outarg, 0);
|
||||
|
||||
// Dump the argument cleanup code
|
||||
Printv(f.code,cleanup, 0);
|
||||
Printv(f->code,cleanup, 0);
|
||||
|
||||
// Look for any remaining cleanup
|
||||
|
||||
if (NewObject) {
|
||||
if ((tm = typemap_lookup((char*)"newfree",typemap_lang,t,iname,(char*)"_result",(char*)""))) {
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
}
|
||||
|
||||
if((t->type != T_VOID || t->is_pointer) && !native_func) {
|
||||
if ((tm = typemap_lookup((char*)"ret",typemap_lang,t,iname,(char*)"_result",(char*)"_jresult", NULL))) {
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap things up (in a manner of speaking)
|
||||
if(t->type != T_VOID || t->is_pointer)
|
||||
Printv(f.code, tab4, "return _jresult;\n", 0);
|
||||
Printf(f.code, "}\n");
|
||||
Printv(f->code, tab4, "return _jresult;\n", 0);
|
||||
Printf(f->code, "}\n");
|
||||
|
||||
// Substitute the cleanup code (some exception handlers like to have this)
|
||||
Replace(f.code,"$cleanup",cleanup, DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY);
|
||||
|
||||
// Emit the function
|
||||
|
||||
if(!native_func)
|
||||
f.print(f_wrappers);
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
|
||||
// If registerNatives is active, store the table entry for this method
|
||||
|
|
@ -819,6 +819,12 @@ void JAVA::create_function(char *name, char *iname, DataType *t, ParmList *l)
|
|||
0);
|
||||
|
||||
}
|
||||
|
||||
Delete(cleanup);
|
||||
Delete(outarg);
|
||||
Delete(body);
|
||||
Delete(javaParameterSignature);
|
||||
DelWrapper(f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -246,10 +246,10 @@ MZSCHEME::close (void)
|
|||
|
||||
void
|
||||
MZSCHEME::get_pointer (DOHString_or_char *name, int parm, DataType *t,
|
||||
WrapperFunction &f)
|
||||
Wrapper *f)
|
||||
{
|
||||
Printf(f.code," if (!swig_get_c_pointer(argv[%d],\"%s\", (void **) &_arg%d))\n", parm, t->print_mangle(), parm);
|
||||
Printf(f.code," scheme_wrong_type(\"%s\", \"%s\", %d, argc, argv);\n", name, t->print_mangle(), parm);
|
||||
Printf(f->code," if (!swig_get_c_pointer(argv[%d],\"%s\", (void **) &_arg%d))\n", parm, t->print_mangle(), parm);
|
||||
Printf(f->code," scheme_wrong_type(\"%s\", \"%s\", %d, argc, argv);\n", name, t->print_mangle(), parm);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
@ -292,7 +292,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
Parm *p;
|
||||
char source[256], target[256], argnum[256], arg[256];
|
||||
char *tm;
|
||||
WrapperFunction f;
|
||||
Wrapper *f;
|
||||
DOHString *cleanup = 0;
|
||||
DOHString *proc_name = 0;
|
||||
int need_len = 0;
|
||||
|
|
@ -300,7 +300,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
DOHString *outarg = 0;
|
||||
int argout_set = 0;
|
||||
|
||||
|
||||
f = NewWrapper();
|
||||
outarg = NewString("");
|
||||
cleanup = NewString("");
|
||||
|
||||
|
|
@ -312,7 +312,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
Replace(proc_name,"_","-",DOH_REPLACE_ANY);
|
||||
|
||||
// writing the function wrapper function
|
||||
Printv(f.def,
|
||||
Printv(f->def,
|
||||
"static Scheme_Object *", wname, " (",
|
||||
"int argc, Scheme_Object **argv",
|
||||
")\n{",
|
||||
|
|
@ -328,9 +328,9 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
int numopt = 0;
|
||||
|
||||
// adds local variables : type name
|
||||
f.add_local ((char*)"char *", (char*)"_tempc");
|
||||
f.add_local ((char*)"int", (char*)"_len");
|
||||
f.add_local ((char*)"Scheme_Object *", (char*)"swig_result");
|
||||
Wrapper_add_local (f,(char*)"char *", (char*)"_tempc",0);
|
||||
Wrapper_add_local (f,(char*)"int", (char*)"_len",0);
|
||||
Wrapper_add_local (f,(char*)"Scheme_Object *", (char*)"swig_result",0);
|
||||
|
||||
// Now write code to extract the parameters (this is super ugly)
|
||||
|
||||
|
|
@ -348,13 +348,13 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
// Handle parameter types.
|
||||
|
||||
if (p.ignore)
|
||||
Printv(f.code, "/* ", p.name, " ignored... */\n", 0);
|
||||
Printv(f->code, "/* ", p.name, " ignored... */\n", 0);
|
||||
else {
|
||||
++numargs;
|
||||
if ((tm = typemap_lookup ((char*)"in", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
Printv(f.code, tm, "\n", 0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
p.t, p.name, source, target, f))) {
|
||||
Printv(f->code, tm, "\n", 0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
// no typemap found
|
||||
// assume it's a Scheme_Object containing the C pointer
|
||||
|
|
@ -368,16 +368,16 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
// Check if there are any constraints.
|
||||
|
||||
if ((tm = typemap_lookup ((char*)"check", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
p.t, p.name, source, target, f))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printv(f.code,tm,"\n", 0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
Printv(f->code,tm,"\n", 0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
|
||||
// Pass output arguments back to the caller.
|
||||
|
||||
if ((tm = typemap_lookup ((char*)"argout", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
p.t, p.name, source, target, f))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printv(outarg, tm, "\n", 0);
|
||||
mreplace (outarg, argnum, arg, proc_name);
|
||||
|
|
@ -386,7 +386,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// Free up any memory allocated for the arguments.
|
||||
if ((tm = typemap_lookup ((char*)"freearg", typemap_lang,
|
||||
p.t, p.name, source, target, &f))) {
|
||||
p.t, p.name, source, target, f))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printv(cleanup, tm, "\n", 0);
|
||||
mreplace (cleanup, argnum, arg, proc_name);
|
||||
|
|
@ -401,18 +401,18 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
if (d->type == T_VOID) {
|
||||
if(!argout_set)
|
||||
Printv(f.code, tab4, "swig_result = scheme_void;\n", 0);
|
||||
Printv(f->code, tab4, "swig_result = scheme_void;\n", 0);
|
||||
}
|
||||
|
||||
else if ((tm = typemap_lookup ((char*)"out", typemap_lang,
|
||||
d, name, (char*)"_result", (char*)"swig_result", &f))) {
|
||||
Printv(f.code, tm, "\n", 0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
d, name, (char*)"_result", (char*)"swig_result", f))) {
|
||||
Printv(f->code, tm, "\n", 0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
// no typemap found and not void then create a Scheme_Object holding
|
||||
// the C pointer and return it
|
||||
else if (d->is_pointer) {
|
||||
Printv(f.code,
|
||||
Printv(f->code,
|
||||
tab4,
|
||||
"swig_result = swig_make_c_pointer(",
|
||||
"_result, \"",
|
||||
|
|
@ -425,50 +425,50 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
}
|
||||
|
||||
// Dump the argument output code
|
||||
Printv(f.code, outarg,0);
|
||||
Printv(f->code, outarg,0);
|
||||
|
||||
// Dump the argument cleanup code
|
||||
Printv(f.code, cleanup, 0);
|
||||
Printv(f->code, cleanup, 0);
|
||||
|
||||
// Look for any remaining cleanup
|
||||
|
||||
if (NewObject) {
|
||||
if ((tm = typemap_lookup ((char*)"newfree", typemap_lang,
|
||||
d, iname, (char*)"_result", (char*)"", &f))) {
|
||||
Printv(f.code,tm,"\n",0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
d, iname, (char*)"_result", (char*)"", f))) {
|
||||
Printv(f->code,tm,"\n",0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
}
|
||||
|
||||
// Free any memory allocated by the function being wrapped..
|
||||
|
||||
if ((tm = typemap_lookup ((char*)"ret", typemap_lang,
|
||||
d, name, (char*)"_result", (char*)"", &f))) {
|
||||
d, name, (char*)"_result", (char*)"", f))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printv(f.code,tm,"\n",0);
|
||||
mreplace (f.code, argnum, arg, proc_name);
|
||||
Printv(f->code,tm,"\n",0);
|
||||
mreplace (f->code, argnum, arg, proc_name);
|
||||
}
|
||||
|
||||
// returning multiple values
|
||||
if(argout_set) {
|
||||
if(d->type == T_VOID) {
|
||||
f.add_local((char*)"int", (char*)"_lenv", (char*)"0");
|
||||
f.add_local((char*)"Scheme_Object *", (char*)"_values[MAXVALUES]");
|
||||
Printv(f.code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0);
|
||||
Wrapper_add_local(f,(char*)"int", (char*)"_lenv", (char*)"0");
|
||||
Wrapper_add_local(f,(char*)"Scheme_Object *", (char*)"_values[MAXVALUES]",0);
|
||||
Printv(f->code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0);
|
||||
}
|
||||
else {
|
||||
f.add_local((char*)"int", (char*)"_lenv", (char*)"1");
|
||||
f.add_local((char*)"Scheme_Object *",(char*) "_values[MAXVALUES]");
|
||||
Printv(f.code, tab4, "_values[0] = swig_result;\n", 0);
|
||||
Printv(f.code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0);
|
||||
Wrapper_add_local(f,(char*)"int", (char*)"_lenv", (char*)"1");
|
||||
Wrapper_add_local(f,(char*)"Scheme_Object *",(char*) "_values[MAXVALUES]",0);
|
||||
Printv(f->code, tab4, "_values[0] = swig_result;\n", 0);
|
||||
Printv(f->code, tab4, "swig_result = scheme_values(_lenv, _values);\n", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Wrap things up (in a manner of speaking)
|
||||
|
||||
Printv(f.code, tab4, "return swig_result;\n", "}\n", 0);
|
||||
Printv(f->code, tab4, "return swig_result;\n", "}\n", 0);
|
||||
|
||||
f.print (f_wrappers);
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
// Now register the function
|
||||
/* Printv(init_func_def,
|
||||
|
|
@ -485,6 +485,7 @@ MZSCHEME::create_function (char *name, char *iname, DataType *d, ParmList *l)
|
|||
Delete(proc_name);
|
||||
Delete(outarg);
|
||||
Delete(cleanup);
|
||||
DelWrapper(f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
class MZSCHEME : public Language
|
||||
{
|
||||
private:
|
||||
void get_pointer(DOHString_or_char *name, int parm, DataType *t, WrapperFunction &f);
|
||||
void get_pointer(DOHString_or_char *name, int parm, DataType *t, Wrapper *f);
|
||||
void usage_var(char *, DataType *, DOHString *usage);
|
||||
void usage_func(char *, DataType *, ParmList *, DOHString *usage);
|
||||
void usage_returns(char *, DataType *, ParmList *, DOHString *usage);
|
||||
|
|
|
|||
|
|
@ -743,13 +743,14 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
int pcount,i,j;
|
||||
char *wname;
|
||||
char *usage = 0;
|
||||
WrapperFunction f;
|
||||
Wrapper *f;
|
||||
char source[256],target[256],temp[256], argnum[32];
|
||||
char *tm;
|
||||
DOHString *cleanup, *outarg;
|
||||
int numopt = 0;
|
||||
int need_save, num_saved = 0; // Number of saved arguments.
|
||||
|
||||
f = NewWrapper();
|
||||
cleanup = NewString("");
|
||||
outarg = NewString("");
|
||||
|
||||
|
|
@ -759,19 +760,19 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// Now write the wrapper function itself....this is pretty ugly
|
||||
|
||||
Printv(f.def, "XS(", wname, ") {\n", 0);
|
||||
Printv(f.code, tab4, "cv = cv;\n", 0);
|
||||
Printv(f->def, "XS(", wname, ") {\n", 0);
|
||||
Printv(f->code, tab4, "cv = cv;\n", 0);
|
||||
|
||||
pcount = emit_args(d, l, f);
|
||||
numopt = l->numopt();
|
||||
|
||||
f.add_local((char*)"int",(char*)"argvi = 0");
|
||||
Wrapper_add_local(f,(char*)"int",(char*)"argvi = 0",0);
|
||||
|
||||
// Check the number of arguments
|
||||
|
||||
usage = usage_func(iname,d,l);
|
||||
Printf(f.code," if ((items < %d) || (items > %d)) \n", pcount-numopt, l->numarg());
|
||||
Printf(f.code," croak(\"Usage: %s\");\n", usage);
|
||||
Printf(f->code," if ((items < %d) || (items > %d)) \n", pcount-numopt, l->numarg());
|
||||
Printf(f->code," croak(\"Usage: %s\");\n", usage);
|
||||
|
||||
// Write code to extract parameters.
|
||||
// This section should be able to extract virtually any kind
|
||||
|
|
@ -793,13 +794,13 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
// If there are optional arguments, check for this
|
||||
|
||||
if (j>= (pcount-numopt))
|
||||
Printf(f.code," if (items > %d) {\n", j);
|
||||
Printf(f->code," if (items > %d) {\n", j);
|
||||
|
||||
// See if there is a type-map
|
||||
if ((tm = typemap_lookup((char*)"in",(char*)"perl5",p->t,p->name,source,target,&f))) {
|
||||
Printf(f.code,"%s\n",tm);
|
||||
Replace(f.code,"$argnum",argnum,DOH_REPLACE_ANY);
|
||||
Replace(f.code,"$arg",source,DOH_REPLACE_ANY);
|
||||
if ((tm = typemap_lookup((char*)"in",(char*)"perl5",p->t,p->name,source,target,f))) {
|
||||
Printf(f->code,"%s\n",tm);
|
||||
Replace(f->code,"$argnum",argnum,DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$arg",source,DOH_REPLACE_ANY);
|
||||
} else {
|
||||
|
||||
if (!p->t->is_pointer) {
|
||||
|
|
@ -822,19 +823,19 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
case T_USHORT:
|
||||
case T_ULONG:
|
||||
case T_UCHAR:
|
||||
Printf(f.code," _arg%d = %sSvIV(ST(%d));\n", i, p->t->print_cast(),j);
|
||||
Printf(f->code," _arg%d = %sSvIV(ST(%d));\n", i, p->t->print_cast(),j);
|
||||
break;
|
||||
case T_CHAR :
|
||||
|
||||
|
||||
Printf(f.code," _arg%d = (char) *SvPV(ST(%d),PL_na);\n", i, j);
|
||||
Printf(f->code," _arg%d = (char) *SvPV(ST(%d),PL_na);\n", i, j);
|
||||
break;
|
||||
|
||||
// Doubles
|
||||
|
||||
case T_DOUBLE :
|
||||
case T_FLOAT :
|
||||
Printf(f.code," _arg%d = %s SvNV(ST(%d));\n", i, p->t->print_cast(), j);
|
||||
Printf(f->code," _arg%d = %s SvNV(ST(%d));\n", i, p->t->print_cast(), j);
|
||||
break;
|
||||
|
||||
// Void.. Do nothing.
|
||||
|
|
@ -859,15 +860,15 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
// since that is usually a string.
|
||||
|
||||
if ((p->t->type == T_CHAR) && (p->t->is_pointer == 1)) {
|
||||
Printf(f.code," if (! SvOK((SV*) ST(%d))) { _arg%d = 0; }\n", j, i);
|
||||
Printf(f.code," else { _arg%d = (char *) SvPV(ST(%d),PL_na); }\n", i,j);
|
||||
Printf(f->code," if (! SvOK((SV*) ST(%d))) { _arg%d = 0; }\n", j, i);
|
||||
Printf(f->code," else { _arg%d = (char *) SvPV(ST(%d),PL_na); }\n", i,j);
|
||||
} else {
|
||||
|
||||
// Have a generic pointer type here. Read it in as a swig
|
||||
// typed pointer.
|
||||
|
||||
sprintf(temp,"argument %d", i+1);
|
||||
get_pointer(iname,temp,source,target, p->t, f.code, (char*)"XSRETURN(1)");
|
||||
get_pointer(iname,temp,source,target, p->t, f->code, (char*)"XSRETURN(1)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -875,7 +876,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
sprintf(temp,"_saved[%d]",num_saved);
|
||||
if (j>= (pcount-numopt))
|
||||
Printf(f.code," } \n");
|
||||
Printf(f->code," } \n");
|
||||
j++;
|
||||
} else {
|
||||
temp[0] = 0;
|
||||
|
|
@ -883,8 +884,8 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// Check if there is any constraint code
|
||||
if ((tm = typemap_lookup((char*)"check",(char*)"perl5",p->t,p->name,source,target))) {
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Replace(f.code,"$argnum",argnum, DOH_REPLACE_ANY);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
Replace(f->code,"$argnum",argnum, DOH_REPLACE_ANY);
|
||||
}
|
||||
need_save = 0;
|
||||
|
||||
|
|
@ -905,7 +906,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
// If we needed a saved variable, we need to emit to emit some code for that
|
||||
// This only applies if the argument actually existed (not ignore)
|
||||
if ((need_save) && (!p->ignore)) {
|
||||
Printv(f.code, tab4, temp, " = ", source, ";\n", 0);
|
||||
Printv(f->code, tab4, temp, " = ", source, ";\n", 0);
|
||||
num_saved++;
|
||||
}
|
||||
p = l->get_next();
|
||||
|
|
@ -916,7 +917,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
if (num_saved) {
|
||||
sprintf(temp,"_saved[%d]",num_saved);
|
||||
f.add_local((char*)"SV *",temp);
|
||||
Wrapper_add_local(f,(char*)"SV *",temp,0);
|
||||
}
|
||||
|
||||
// Now write code to make the function call
|
||||
|
|
@ -926,26 +927,26 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
// See if there was a typemap
|
||||
if ((tm = typemap_lookup((char*)"out",(char*)"perl5",d,iname,(char*)"_result",(char*)"ST(argvi)"))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f.code, "%s\n", tm);
|
||||
Printf(f->code, "%s\n", tm);
|
||||
} else if ((d->type != T_VOID) || (d->is_pointer)) {
|
||||
if (!d->is_pointer) {
|
||||
|
||||
// Function returns a "value"
|
||||
Printf(f.code," ST(argvi) = sv_newmortal();\n");
|
||||
Printf(f->code," ST(argvi) = sv_newmortal();\n");
|
||||
switch(d->type) {
|
||||
case T_INT: case T_BOOL: case T_SINT: case T_UINT:
|
||||
case T_SHORT: case T_SSHORT: case T_USHORT:
|
||||
case T_LONG : case T_SLONG : case T_ULONG:
|
||||
case T_SCHAR: case T_UCHAR :
|
||||
Printf(f.code," sv_setiv(ST(argvi++),(IV) _result);\n");
|
||||
Printf(f->code," sv_setiv(ST(argvi++),(IV) _result);\n");
|
||||
break;
|
||||
case T_DOUBLE :
|
||||
case T_FLOAT :
|
||||
Printf(f.code," sv_setnv(ST(argvi++), (double) _result);\n");
|
||||
Printf(f->code," sv_setnv(ST(argvi++), (double) _result);\n");
|
||||
break;
|
||||
case T_CHAR :
|
||||
f.add_local((char*)"char", (char*)"_ctemp[2]");
|
||||
Printv(f.code,
|
||||
Wrapper_add_local(f,(char*)"char", (char*)"_ctemp[2]",0);
|
||||
Printv(f->code,
|
||||
tab4, "_ctemp[0] = _result;\n",
|
||||
tab4, "_ctemp[1] = 0;\n",
|
||||
tab4, "sv_setpv((SV*)ST(argvi++),_ctemp);\n",
|
||||
|
|
@ -956,7 +957,7 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
case T_USER:
|
||||
d->is_pointer++;
|
||||
Printv(f.code,
|
||||
Printv(f->code,
|
||||
tab4, "sv_setref_pv(ST(argvi++),\"",(hidden ? realpackage : ""), (hidden ? "::" : ""), d->print_mangle(),
|
||||
"\", (void *) _result);\n", 0);
|
||||
d->is_pointer--;
|
||||
|
|
@ -969,15 +970,15 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
} else {
|
||||
|
||||
// Is a pointer return type
|
||||
Printf(f.code," ST(argvi) = sv_newmortal();\n");
|
||||
Printf(f->code," ST(argvi) = sv_newmortal();\n");
|
||||
if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
|
||||
|
||||
// Return a character string
|
||||
Printf(f.code," sv_setpv((SV*)ST(argvi++),(char *) _result);\n");
|
||||
Printf(f->code," sv_setpv((SV*)ST(argvi++),(char *) _result);\n");
|
||||
|
||||
} else {
|
||||
// Is an ordinary pointer type.
|
||||
Printv(f.code, tab4, "sv_setref_pv(ST(argvi++),\"", (hidden ? realpackage : ""), (hidden ? "::" : ""), d->print_mangle(),
|
||||
Printv(f->code, tab4, "sv_setref_pv(ST(argvi++),\"", (hidden ? realpackage : ""), (hidden ? "::" : ""), d->print_mangle(),
|
||||
"\", (void *) _result);\n", 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -985,38 +986,38 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// If there were any output args, take care of them.
|
||||
|
||||
Printv(f.code,outarg,0);
|
||||
Printv(f->code,outarg,0);
|
||||
|
||||
// If there was any cleanup, do that.
|
||||
|
||||
Printv(f.code,cleanup,0);
|
||||
Printv(f->code,cleanup,0);
|
||||
|
||||
if (NewObject) {
|
||||
if ((tm = typemap_lookup((char*)"newfree",(char*)"perl5",d,iname,(char*)"_result",(char*)""))) {
|
||||
Printf(f.code,"%s\n",tm);
|
||||
Printf(f->code,"%s\n",tm);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tm = typemap_lookup((char*)"ret",(char*)"perl5",d,iname,(char*)"_result",(char*)""))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
|
||||
// Wrap things up (in a manner of speaking)
|
||||
|
||||
Printf(f.code," XSRETURN(argvi);\n}\n");
|
||||
Printf(f->code," XSRETURN(argvi);\n}\n");
|
||||
|
||||
// Add the dXSARGS last
|
||||
|
||||
f.add_local((char*)"dXSARGS",(char*)"");
|
||||
Wrapper_add_local(f,(char*)"dXSARGS",(char*)"",0);
|
||||
|
||||
// Substitute the cleanup code
|
||||
Replace(f.code,"$cleanup",cleanup,DOH_REPLACE_ANY);
|
||||
Replace(f.code,"$name",iname,DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$name",iname,DOH_REPLACE_ANY);
|
||||
|
||||
// Dump this function out
|
||||
|
||||
f.print(f_wrappers);
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
// Now register the function
|
||||
|
||||
|
|
@ -1133,6 +1134,9 @@ void PERL5::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
}
|
||||
Delete(func);
|
||||
}
|
||||
Delete(cleanup);
|
||||
Delete(outarg);
|
||||
DelWrapper(f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
@ -1145,11 +1149,14 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
{
|
||||
char set_name[256];
|
||||
char val_name[256];
|
||||
WrapperFunction getf, setf;
|
||||
Wrapper *getf, *setf;
|
||||
char *tm;
|
||||
sprintf(set_name,"_wrap_set_%s",iname);
|
||||
sprintf(val_name,"_wrap_val_%s",iname);
|
||||
|
||||
getf = NewWrapper();
|
||||
setf = NewWrapper();
|
||||
|
||||
// Create a new scalar that we will attach magic to
|
||||
|
||||
Printv(vinit, tab4, "sv = perl_get_sv(\"", package, "::", iname, "\",TRUE | 0x2);\n", 0);
|
||||
|
|
@ -1157,17 +1164,17 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
// Create a Perl function for setting the variable value
|
||||
|
||||
if (!(Status & STAT_READONLY)) {
|
||||
Printf(setf.def,"SWIGCLASS_STATIC int %s(SV* sv, MAGIC *mg) {\n", set_name);
|
||||
Printv(setf.code,
|
||||
Printf(setf->def,"SWIGCLASS_STATIC int %s(SV* sv, MAGIC *mg) {\n", set_name);
|
||||
Printv(setf->code,
|
||||
tab4, "MAGIC_PPERL\n",
|
||||
tab4, "mg = mg;\n",
|
||||
0);
|
||||
|
||||
/* Check for a few typemaps */
|
||||
if ((tm = typemap_lookup((char*)"varin",(char*)"perl5",t,(char*)"",(char*)"sv",name))) {
|
||||
Printf(setf.code,"%s\n", tm);
|
||||
Printf(setf->code,"%s\n", tm);
|
||||
} else if ((tm = typemap_lookup((char*)"in",(char*)"perl5",t,(char*)"",(char*)"sv",name))) {
|
||||
Printf(setf.code,"%s\n", tm);
|
||||
Printf(setf->code,"%s\n", tm);
|
||||
} else {
|
||||
if (!t->is_pointer) {
|
||||
|
||||
|
|
@ -1178,14 +1185,14 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
case T_SHORT : case T_SSHORT : case T_USHORT:
|
||||
case T_LONG : case T_SLONG : case T_ULONG:
|
||||
case T_UCHAR: case T_SCHAR:
|
||||
Printv(setf.code,tab4, name, " = ", t->print_cast(), " SvIV(sv);\n", 0);
|
||||
Printv(setf->code,tab4, name, " = ", t->print_cast(), " SvIV(sv);\n", 0);
|
||||
break;
|
||||
case T_DOUBLE :
|
||||
case T_FLOAT :
|
||||
Printv(setf.code, tab4, name, " = ", t->print_cast(), " SvNV(sv);\n", 0);
|
||||
Printv(setf->code, tab4, name, " = ", t->print_cast(), " SvNV(sv);\n", 0);
|
||||
break;
|
||||
case T_CHAR :
|
||||
Printv(setf.code, tab4, name, " = (char) *SvPV(sv,PL_na);\n", 0);
|
||||
Printv(setf->code, tab4, name, " = (char) *SvPV(sv,PL_na);\n", 0);
|
||||
break;
|
||||
|
||||
case T_USER:
|
||||
|
|
@ -1194,9 +1201,9 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
// Get as a pointer value
|
||||
|
||||
t->is_pointer++;
|
||||
setf.add_local((char*)"void",(char*)"*_temp");
|
||||
get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf.code, (char*)"return(1)");
|
||||
Printv(setf.code, tab4, name, " = *(", t->print_cast(), " _temp);\n", 0);
|
||||
Wrapper_add_local(setf,(char*)"void",(char*)"*_temp",0);
|
||||
get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf->code, (char*)"return(1)");
|
||||
Printv(setf->code, tab4, name, " = *(", t->print_cast(), " _temp);\n", 0);
|
||||
t->is_pointer--;
|
||||
break;
|
||||
|
||||
|
|
@ -1207,39 +1214,39 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
} else {
|
||||
// Have some sort of pointer type here, Process it differently
|
||||
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
|
||||
setf.add_local((char*)"char",(char*)"*_a");
|
||||
Printf(setf.code," _a = (char *) SvPV(sv,PL_na);\n");
|
||||
Wrapper_add_local(setf,(char*)"char",(char*)"*_a",0);
|
||||
Printf(setf->code," _a = (char *) SvPV(sv,PL_na);\n");
|
||||
|
||||
if (CPlusPlus)
|
||||
Printv(setf.code,
|
||||
Printv(setf->code,
|
||||
tab4, "if (", name, ") delete [] ", name, ";\n",
|
||||
tab4, name, " = new char[strlen(_a)+1];\n",
|
||||
0);
|
||||
else
|
||||
Printv(setf.code,
|
||||
Printv(setf->code,
|
||||
tab4, "if (", name, ") free(", name, ");\n",
|
||||
tab4, name, " = (char *) malloc(strlen(_a)+1);\n",
|
||||
0);
|
||||
Printv(setf.code,"strcpy(", name, ",_a);\n", 0);
|
||||
Printv(setf->code,"strcpy(", name, ",_a);\n", 0);
|
||||
} else {
|
||||
// Set the value of a pointer
|
||||
|
||||
setf.add_local((char*)"void",(char*)"*_temp");
|
||||
get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf.code, (char*)"return(1)");
|
||||
Printv(setf.code,tab4, name, " = ", t->print_cast(), " _temp;\n", 0);
|
||||
Wrapper_add_local(setf,(char*)"void",(char*)"*_temp",0);
|
||||
get_pointer(iname,(char*)"value",(char*)"sv",(char*)"_temp", t, setf->code, (char*)"return(1)");
|
||||
Printv(setf->code,tab4, name, " = ", t->print_cast(), " _temp;\n", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Printf(setf.code," return 1;\n}\n");
|
||||
Replace(setf.code,"$name",iname, DOH_REPLACE_ANY);
|
||||
setf.print(magic);
|
||||
Printf(setf->code," return 1;\n}\n");
|
||||
Replace(setf->code,"$name",iname, DOH_REPLACE_ANY);
|
||||
Wrapper_print(setf,magic);
|
||||
|
||||
}
|
||||
|
||||
// Now write a function to evaluate the variable
|
||||
|
||||
Printf(getf.def,"SWIGCLASS_STATIC int %s(SV *sv, MAGIC *mg) {\n", val_name);
|
||||
Printv(getf.code,
|
||||
Printf(getf->def,"SWIGCLASS_STATIC int %s(SV *sv, MAGIC *mg) {\n", val_name);
|
||||
Printv(getf->code,
|
||||
tab4, "MAGIC_PPERL\n",
|
||||
tab4, "mg = mg;\n",
|
||||
0);
|
||||
|
|
@ -1247,9 +1254,9 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
// Check for a typemap
|
||||
|
||||
if ((tm = typemap_lookup((char*)"varout",(char*)"perl5",t,(char*)"",name, (char*)"sv"))) {
|
||||
Printf(getf.code,"%s\n", tm);
|
||||
Printf(getf->code,"%s\n", tm);
|
||||
} else if ((tm = typemap_lookup((char*)"out",(char*)"perl5",t,(char*)"",name,(char*)"sv"))) {
|
||||
Printf(getf.code,"%s\n", tm);
|
||||
Printf(getf->code,"%s\n", tm);
|
||||
} else {
|
||||
if (!t->is_pointer) {
|
||||
switch(t->type) {
|
||||
|
|
@ -1257,17 +1264,17 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
case T_SHORT : case T_SSHORT: case T_USHORT:
|
||||
case T_LONG : case T_SLONG : case T_ULONG:
|
||||
case T_UCHAR: case T_SCHAR:
|
||||
Printv(getf.code,tab4, "sv_setiv(sv, (IV) ", name, ");\n", 0);
|
||||
Printv(getf->code,tab4, "sv_setiv(sv, (IV) ", name, ");\n", 0);
|
||||
Printv(vinit, tab4, "sv_setiv(sv,(IV)", name, ");\n",0);
|
||||
break;
|
||||
case T_DOUBLE :
|
||||
case T_FLOAT :
|
||||
Printv(getf.code, tab4,"sv_setnv(sv, (double) ", name, ");\n", 0);
|
||||
Printv(getf->code, tab4,"sv_setnv(sv, (double) ", name, ");\n", 0);
|
||||
Printv(vinit, tab4, "sv_setnv(sv,(double)", name, ");\n",0);
|
||||
break;
|
||||
case T_CHAR :
|
||||
getf.add_local((char*)"char",(char*)"_ptemp[2]");
|
||||
Printv(getf.code,
|
||||
Wrapper_add_local(getf,(char*)"char",(char*)"_ptemp[2]",0);
|
||||
Printv(getf->code,
|
||||
tab4, "_ptemp[0] = ", name, ";\n",
|
||||
tab4, "_ptemp[1] = 0;\n",
|
||||
tab4, "sv_setpv((SV*) sv, _ptemp);\n",
|
||||
|
|
@ -1275,12 +1282,12 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
break;
|
||||
case T_USER:
|
||||
t->is_pointer++;
|
||||
Printv(getf.code,
|
||||
Printv(getf->code,
|
||||
tab4, "rsv = SvRV(sv);\n",
|
||||
tab4, "sv_setiv(rsv,(IV) &", name, ");\n",
|
||||
0);
|
||||
|
||||
getf.add_local((char*)"SV",(char*)"*rsv");
|
||||
Wrapper_add_local(getf,(char*)"SV",(char*)"*rsv",0);
|
||||
Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) &", name, ");\n",0);
|
||||
t->is_pointer--;
|
||||
|
||||
|
|
@ -1293,22 +1300,22 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
// Have some sort of arbitrary pointer type. Return it as a string
|
||||
|
||||
if ((t->type == T_CHAR) && (t->is_pointer == 1))
|
||||
Printv(getf.code, tab4, "sv_setpv((SV*) sv, ", name, ");\n", 0);
|
||||
Printv(getf->code, tab4, "sv_setpv((SV*) sv, ", name, ");\n", 0);
|
||||
else {
|
||||
Printv(getf.code,
|
||||
Printv(getf->code,
|
||||
tab4, "rsv = SvRV(sv);\n",
|
||||
tab4, "sv_setiv(rsv,(IV) ", name, ");\n",
|
||||
0);
|
||||
|
||||
getf.add_local((char*)"SV",(char*)"*rsv");
|
||||
Wrapper_add_local(getf,(char*)"SV",(char*)"*rsv",0);
|
||||
Printv(vinit, tab4, "sv_setref_pv(sv,\"", t->print_mangle(), "\",(void *) 1);\n",0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Printf(getf.code," return 1;\n}\n");
|
||||
Printf(getf->code," return 1;\n}\n");
|
||||
|
||||
Replace(getf.code,"$name",iname, DOH_REPLACE_ANY);
|
||||
getf.print(magic);
|
||||
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
|
||||
Wrapper_print(getf,magic);
|
||||
|
||||
// Now add symbol to the PERL interpreter
|
||||
if (Status & STAT_READONLY) {
|
||||
|
|
@ -1337,6 +1344,8 @@ void PERL5::link_variable(char *name, char *iname, DataType *t)
|
|||
if (export_all)
|
||||
Printf(exported,"$%s ", name);
|
||||
}
|
||||
DelWrapper(setf);
|
||||
DelWrapper(getf);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -496,7 +496,7 @@ void PYTHON::close_cmodule(void)
|
|||
|
||||
// ----------------------------------------------------------------------
|
||||
// PYTHON::get_pointer(char *iname, char *srcname, char *src, char *target,
|
||||
// DataType *t, WrapperFunction &f, char *ret)
|
||||
// DataType *t, DOHString *f, char *ret)
|
||||
//
|
||||
// Emits code to get a pointer and do type checking.
|
||||
// iname = name of the function/method (used for error messages)
|
||||
|
|
@ -537,20 +537,20 @@ PYTHON::get_pointer(char *iname, char *srcname, char *src, char *dest,
|
|||
//
|
||||
// Return the code to be used as a function header
|
||||
// ----------------------------------------------------------------------
|
||||
void PYTHON::emit_function_header(WrapperFunction &emit_to, char *wname)
|
||||
void PYTHON::emit_function_header(Wrapper *emit_to, char *wname)
|
||||
{
|
||||
if (!use_kw) {
|
||||
Printv(emit_to.def,
|
||||
Printv(emit_to->def,
|
||||
"static PyObject *", wname,
|
||||
"(PyObject *self, PyObject *args) {",
|
||||
0);
|
||||
} else {
|
||||
Printv(emit_to.def,
|
||||
Printv(emit_to->def,
|
||||
"static PyObject *", wname,
|
||||
"(PyObject *self, PyObject *args, PyObject *kwargs) {",
|
||||
0);
|
||||
}
|
||||
Printf(emit_to.code," self = self;\n");
|
||||
Printf(emit_to->code," self = self;\n");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
@ -562,7 +562,7 @@ void PYTHON::emit_function_header(WrapperFunction &emit_to, char *wname)
|
|||
//
|
||||
// Returns the name of the variable to use as the self pointer
|
||||
// ----------------------------------------------------------------------
|
||||
char *PYTHON::convert_self(WrapperFunction &)
|
||||
char *PYTHON::convert_self(Wrapper *f)
|
||||
{
|
||||
// Default behaviour is no translation
|
||||
return (char*)"";
|
||||
|
|
@ -619,7 +619,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
char wname[256], self_name[256], call_name[256];
|
||||
char source[64], target[64], temp[256], argnum[20];
|
||||
char *usage = 0;
|
||||
WrapperFunction f;
|
||||
Wrapper *f;
|
||||
DOHString *parse_args;
|
||||
DOHString *arglist;
|
||||
DOHString *get_pointers;
|
||||
|
|
@ -631,6 +631,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
char *tm;
|
||||
int numopt = 0;
|
||||
|
||||
f = NewWrapper();
|
||||
parse_args = NewString("");
|
||||
arglist = NewString("");
|
||||
get_pointers = NewString("");
|
||||
|
|
@ -652,7 +653,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
emit_function_header(f, wname);
|
||||
|
||||
f.add_local((char*)"PyObject *",(char*)"_resultobj");
|
||||
Wrapper_add_local(f,(char*)"PyObject *",(char*)"_resultobj",0);
|
||||
|
||||
// Get the function usage string for later use
|
||||
|
||||
|
|
@ -709,9 +710,9 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// Look for input typemap
|
||||
|
||||
if ((tm = typemap_lookup((char*)"in",(char*)"python",p->t,p->name,source,target,&f))) {
|
||||
if ((tm = typemap_lookup((char*)"in",(char*)"python",p->t,p->name,source,target,f))) {
|
||||
Putc('O',parse_args);
|
||||
f.add_local((char*)"PyObject *",source,(char*)"0");
|
||||
Wrapper_add_local(f, (char*)"PyObject *",source,(char*)"0");
|
||||
Printf(arglist,"&%s",source);
|
||||
if (i >= (pcount-numopt))
|
||||
Printv(get_pointers, tab4, "if (", source, ")\n",
|
||||
|
|
@ -764,9 +765,9 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
sprintf(tempb,"tempbool%d",i);
|
||||
Putc('i',parse_args);
|
||||
if (!p->defvalue)
|
||||
f.add_local((char*)"int",tempb);
|
||||
Wrapper_add_local(f,(char*)"int",tempb,0);
|
||||
else
|
||||
f.add_local((char*)"int",tempb,tempval);
|
||||
Wrapper_add_local(f,(char*)"int",tempb,tempval);
|
||||
Printv(get_pointers, tab4, target, " = ", p->t->print_cast(), " ", tempb, ";\n", 0);
|
||||
Printf(arglist,"&%s",tempb);
|
||||
}
|
||||
|
|
@ -812,7 +813,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
sprintf(target,"_arg%d", i);
|
||||
sprintf(temp,"argument %d",i+1);
|
||||
|
||||
f.add_local((char*)"PyObject *", source,(char*)"0");
|
||||
Wrapper_add_local(f,(char*)"PyObject *", source,(char*)"0");
|
||||
Printf(arglist,"&%s",source);
|
||||
get_pointer(iname, temp, source, target, p->t, get_pointers, (char*)"NULL");
|
||||
}
|
||||
|
|
@ -843,7 +844,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
Printf(kwargs," NULL }");
|
||||
if (use_kw) {
|
||||
Printv(f.locals,tab4, "char *_kwnames[] = ", kwargs, ";\n", 0);
|
||||
Printv(f->locals,tab4, "char *_kwnames[] = ", kwargs, ";\n", 0);
|
||||
}
|
||||
|
||||
Printf(parse_args,":%s\"", iname);
|
||||
|
|
@ -855,7 +856,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
strcpy(self_name,convert_self(f));
|
||||
|
||||
/* Now slap the whole first part of the wrapper function together */
|
||||
Printv(f.code, parse_args, get_pointers, check, 0);
|
||||
Printv(f->code, parse_args, get_pointers, check, 0);
|
||||
|
||||
// This function emits code to call the real function. Assuming you read
|
||||
// the parameters in correctly, this will work.
|
||||
|
|
@ -869,7 +870,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
if ((tm = typemap_lookup((char*)"out",(char*)"python",d,iname,(char*)"_result",(char*)"_resultobj"))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
} else {
|
||||
|
||||
if ((d->type != T_VOID) || (d->is_pointer)) {
|
||||
|
|
@ -884,38 +885,38 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
// Return an integer type
|
||||
|
||||
case T_INT: case T_SINT: case T_UINT: case T_BOOL:
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"i\",_result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"i\",_result);\n");
|
||||
break;
|
||||
case T_SHORT: case T_SSHORT: case T_USHORT:
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"h\",_result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"h\",_result);\n");
|
||||
break;
|
||||
case T_LONG : case T_SLONG : case T_ULONG:
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"l\",_result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"l\",_result);\n");
|
||||
break;
|
||||
case T_SCHAR: case T_UCHAR :
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"b\",_result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"b\",_result);\n");
|
||||
break;
|
||||
|
||||
// Return a floating point value
|
||||
|
||||
case T_DOUBLE :
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"d\",_result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"d\",_result);\n");
|
||||
break;
|
||||
case T_FLOAT :
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"f\",_result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"f\",_result);\n");
|
||||
break;
|
||||
|
||||
// Return a single ASCII value. Usually we need to convert
|
||||
// it to a NULL-terminate string and return that instead.
|
||||
|
||||
case T_CHAR :
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"c\",_result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"c\",_result);\n");
|
||||
break;
|
||||
|
||||
case T_USER :
|
||||
d->is_pointer++;
|
||||
d->remember();
|
||||
Printv(f.code,tab4, "_resultobj = SWIG_NewPointerObj((void *)_result, SWIGTYPE", d->print_mangle(), ");\n",0);
|
||||
Printv(f->code,tab4, "_resultobj = SWIG_NewPointerObj((void *)_result, SWIGTYPE", d->print_mangle(), ");\n",0);
|
||||
d->is_pointer--;
|
||||
break;
|
||||
default :
|
||||
|
|
@ -931,36 +932,36 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
|
||||
|
||||
// Return a character string
|
||||
Printf(f.code," _resultobj = Py_BuildValue(\"s\", _result);\n");
|
||||
Printf(f->code," _resultobj = Py_BuildValue(\"s\", _result);\n");
|
||||
|
||||
// If declared as a new object, free the result
|
||||
|
||||
} else {
|
||||
// Build a SWIG pointer.
|
||||
d->remember();
|
||||
Printv(f.code, tab4, "_resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE", d->print_mangle(), ");\n", 0);
|
||||
Printv(f->code, tab4, "_resultobj = SWIG_NewPointerObj((void *) _result, SWIGTYPE", d->print_mangle(), ");\n", 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Printf(f.code," Py_INCREF(Py_None);\n");
|
||||
Printf(f.code," _resultobj = Py_None;\n");
|
||||
Printf(f->code," Py_INCREF(Py_None);\n");
|
||||
Printf(f->code," _resultobj = Py_None;\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if there were any output arguments, if so we're going to
|
||||
// create a Python list object out of the current result
|
||||
|
||||
Printv(f.code,outarg,0);
|
||||
Printv(f->code,outarg,0);
|
||||
|
||||
// If there was any other cleanup needed, do that
|
||||
|
||||
Printv(f.code,cleanup,0);
|
||||
Printv(f->code,cleanup,0);
|
||||
|
||||
// Look to see if there is any newfree cleanup code
|
||||
|
||||
if (NewObject) {
|
||||
if ((tm = typemap_lookup((char*)"newfree",(char*)"python",d,iname,(char*)"_result",(char*)""))) {
|
||||
Printf(f.code,"%s\n",tm);
|
||||
Printf(f->code,"%s\n",tm);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -968,19 +969,19 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
if ((tm = typemap_lookup((char*)"ret",(char*)"python",d,iname,(char*)"_result",(char*)""))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f.code,"%s\n",tm);
|
||||
Printf(f->code,"%s\n",tm);
|
||||
}
|
||||
|
||||
Printf(f.code," return _resultobj;\n}\n");
|
||||
Printf(f->code," return _resultobj;\n}\n");
|
||||
|
||||
// Substitute the cleanup code
|
||||
Replace(f.code,"$cleanup",cleanup, DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY);
|
||||
|
||||
// Substitute the function name
|
||||
Replace(f.code,"$name",iname, DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$name",iname, DOH_REPLACE_ANY);
|
||||
|
||||
// Dump the function out
|
||||
f.print(f_wrappers);
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
// Now register the function with the interpreter.
|
||||
|
||||
|
|
@ -1049,6 +1050,7 @@ void PYTHON::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
Delete(outarg);
|
||||
Delete(check);
|
||||
Delete(kwargs);
|
||||
DelWrapper(f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
@ -1070,7 +1072,10 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
static int have_globals = 0;
|
||||
char *tm;
|
||||
|
||||
WrapperFunction getf, setf;
|
||||
Wrapper *getf, *setf;
|
||||
|
||||
getf = NewWrapper();
|
||||
setf = NewWrapper();
|
||||
|
||||
// If this is our first call, add the globals variable to the
|
||||
// Python dictionary.
|
||||
|
|
@ -1091,11 +1096,11 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
// Create a function for setting the value of the variable
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
Printf(setf.def,"static int %s_set(PyObject *val) {", wname);
|
||||
Printf(setf->def,"static int %s_set(PyObject *val) {", wname);
|
||||
if (!(Status & STAT_READONLY)) {
|
||||
if ((tm = typemap_lookup((char*)"varin",(char*)"python",t,name,(char*)"val",name))) {
|
||||
Printf(setf.code,"%s\n",tm);
|
||||
Replace(setf.code,"$name",iname, DOH_REPLACE_ANY);
|
||||
Printf(setf->code,"%s\n",tm);
|
||||
Replace(setf->code,"$name",iname, DOH_REPLACE_ANY);
|
||||
} else {
|
||||
if ((t->type != T_VOID) || (t->is_pointer)) {
|
||||
if (!t->is_pointer) {
|
||||
|
|
@ -1108,8 +1113,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
case T_SINT: case T_SSHORT: case T_SLONG:
|
||||
case T_SCHAR: case T_UCHAR: case T_BOOL:
|
||||
// Get an integer value
|
||||
setf.add_local(t->print_type(), (char*)"tval");
|
||||
Printv(setf.code,
|
||||
Wrapper_add_local(setf,t->print_type(), (char*)"tval",0);
|
||||
Printv(setf->code,
|
||||
tab4, "tval = ", t->print_cast(), "PyInt_AsLong(val);\n",
|
||||
tab4, "if (PyErr_Occurred()) {\n",
|
||||
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
|
||||
|
|
@ -1122,8 +1127,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
|
||||
case T_FLOAT: case T_DOUBLE:
|
||||
// Get a floating point value
|
||||
setf.add_local(t->print_type(), (char*)"tval");
|
||||
Printv(setf.code,
|
||||
Wrapper_add_local(setf,t->print_type(), (char*)"tval",0);
|
||||
Printv(setf->code,
|
||||
tab4, "tval = ", t->print_cast(), "PyFloat_AsDouble(val);\n",
|
||||
tab4, "if (PyErr_Occurred()) {\n",
|
||||
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
|
||||
|
|
@ -1137,8 +1142,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
// A single ascii character
|
||||
|
||||
case T_CHAR:
|
||||
setf.add_local((char*)"char *", (char*)"tval");
|
||||
Printv(setf.code,
|
||||
Wrapper_add_local(setf,(char*)"char *", (char*)"tval",0);
|
||||
Printv(setf->code,
|
||||
tab4, "tval = (char *) PyString_AsString(val);\n",
|
||||
tab4, "if (PyErr_Occurred()) {\n",
|
||||
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
|
||||
|
|
@ -1150,9 +1155,9 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
break;
|
||||
case T_USER:
|
||||
t->is_pointer++;
|
||||
setf.add_local(t->print_type(),(char*)"temp");
|
||||
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf.code,(char*)"1");
|
||||
Printv(setf.code, tab4, name, " = *temp;\n", 0);
|
||||
Wrapper_add_local(setf,t->print_type(),(char*)"temp",0);
|
||||
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1");
|
||||
Printv(setf->code, tab4, name, " = *temp;\n", 0);
|
||||
t->is_pointer--;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -1163,8 +1168,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
// Parse a pointer value
|
||||
|
||||
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
|
||||
setf.add_local((char*)"char *", (char*)"tval");
|
||||
Printv(setf.code,
|
||||
Wrapper_add_local(setf,(char*)"char *", (char*)"tval",0);
|
||||
Printv(setf->code,
|
||||
tab4, "tval = (char *) PyString_AsString(val);\n",
|
||||
tab4, "if (PyErr_Occurred()) {\n",
|
||||
tab8, "PyErr_SetString(PyExc_TypeError,\"C variable '",
|
||||
|
|
@ -1174,13 +1179,13 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
0);
|
||||
|
||||
if (CPlusPlus) {
|
||||
Printv(setf.code,
|
||||
Printv(setf->code,
|
||||
tab4, "if (", name, ") delete [] ", name, ";\n",
|
||||
tab4, name, " = new char[strlen(tval)+1];\n",
|
||||
tab4, "strcpy((char *)", name, ",tval);\n",
|
||||
0);
|
||||
} else {
|
||||
Printv(setf.code,
|
||||
Printv(setf->code,
|
||||
tab4, "if (", name, ") free(", name, ");\n",
|
||||
tab4, name, " = (char *) malloc(strlen(tval)+1);\n",
|
||||
tab4, "strcpy((char *)", name, ",tval);\n",
|
||||
|
|
@ -1190,41 +1195,41 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
|
||||
// Is a generic pointer value.
|
||||
|
||||
setf.add_local(t->print_type(),(char*)"temp");
|
||||
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf.code,(char*)"1");
|
||||
Printv(setf.code,tab4, name, " = temp;\n", 0);
|
||||
Wrapper_add_local(setf,t->print_type(),(char*)"temp",0);
|
||||
get_pointer(iname,(char*)"value",(char*)"val",(char*)"temp",t,setf->code,(char*)"1");
|
||||
Printv(setf->code,tab4, name, " = temp;\n", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Printf(setf.code," return 0;\n");
|
||||
Printf(setf->code," return 0;\n");
|
||||
} else {
|
||||
// Is a readonly variable. Issue an error
|
||||
Printv(setf.code,
|
||||
Printv(setf->code,
|
||||
tab4, "PyErr_SetString(PyExc_TypeError,\"Variable ", iname,
|
||||
" is read-only.\");\n",
|
||||
tab4, "return 1;\n",
|
||||
0);
|
||||
}
|
||||
|
||||
Printf(setf.code,"}\n");
|
||||
Printf(setf->code,"}\n");
|
||||
|
||||
// Dump out function for setting value
|
||||
|
||||
setf.print(f_wrappers);
|
||||
Wrapper_print(setf,f_wrappers);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Create a function for getting the value of a variable
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
Printf(getf.def,"static PyObject *%s_get() {", wname);
|
||||
getf.add_local((char*)"PyObject *",(char*)"pyobj");
|
||||
Printf(getf->def,"static PyObject *%s_get() {", wname);
|
||||
Wrapper_add_local(getf,(char*)"PyObject *",(char*)"pyobj",0);
|
||||
if ((tm = typemap_lookup((char*)"varout",(char*)"python",t,name,name,(char*)"pyobj"))) {
|
||||
Printf(getf.code,"%s\n",tm);
|
||||
Replace(getf.code,"$name",iname, DOH_REPLACE_ANY);
|
||||
Printf(getf->code,"%s\n",tm);
|
||||
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
|
||||
} else if ((tm = typemap_lookup((char*)"out",(char*)"python",t,name,name,(char*)"pyobj"))) {
|
||||
Printf(getf.code,"%s\n",tm);
|
||||
Replace(getf.code,"$name",iname, DOH_REPLACE_ANY);
|
||||
Printf(getf->code,"%s\n",tm);
|
||||
Replace(getf->code,"$name",iname, DOH_REPLACE_ANY);
|
||||
} else {
|
||||
if ((t->type != T_VOID) || (t->is_pointer)) {
|
||||
if (!t->is_pointer) {
|
||||
|
|
@ -1235,14 +1240,14 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
case T_SHORT: case T_SSHORT: case T_USHORT:
|
||||
case T_LONG: case T_SLONG: case T_ULONG:
|
||||
case T_SCHAR: case T_UCHAR: case T_BOOL:
|
||||
Printv(getf.code, tab4, "pyobj = PyInt_FromLong((long) ", name, ");\n", 0);
|
||||
Printv(getf->code, tab4, "pyobj = PyInt_FromLong((long) ", name, ");\n", 0);
|
||||
break;
|
||||
case T_FLOAT: case T_DOUBLE:
|
||||
Printv(getf.code, tab4, "pyobj = PyFloat_FromDouble((double) ", name, ");\n", 0);
|
||||
Printv(getf->code, tab4, "pyobj = PyFloat_FromDouble((double) ", name, ");\n", 0);
|
||||
break;
|
||||
case T_CHAR:
|
||||
getf.add_local((char*)"char",(char*)"ptemp[2]");
|
||||
Printv(getf.code,
|
||||
Wrapper_add_local(getf,(char*)"char",(char*)"ptemp[2]",0);
|
||||
Printv(getf->code,
|
||||
tab4, "ptemp[0] = ", name, ";\n",
|
||||
tab4, "ptemp[1] = 0;\n",
|
||||
tab4, "pyobj = PyString_FromString(ptemp);\n",
|
||||
|
|
@ -1252,7 +1257,7 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
// Hack this into a pointer
|
||||
t->is_pointer++;
|
||||
t->remember();
|
||||
Printv(getf.code,
|
||||
Printv(getf->code,
|
||||
tab4, "pyobj = SWIG_NewPointerObj((void *) &", name ,
|
||||
", SWIGTYPE", t->print_mangle(), ");\n",
|
||||
0);
|
||||
|
|
@ -1266,14 +1271,14 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
|
||||
// Is some sort of pointer value
|
||||
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
|
||||
Printv(getf.code,
|
||||
Printv(getf->code,
|
||||
tab4, "if (", name, ")\n",
|
||||
tab8, "pyobj = PyString_FromString(", name, ");\n",
|
||||
tab4, "else pyobj = PyString_FromString(\"(NULL)\");\n",
|
||||
0);
|
||||
} else {
|
||||
t->remember();
|
||||
Printv(getf.code,
|
||||
Printv(getf->code,
|
||||
tab4, "pyobj = SWIG_NewPointerObj((void *)", name,
|
||||
", SWIGTYPE", t->print_mangle(), ");\n",
|
||||
0);
|
||||
|
|
@ -1282,9 +1287,9 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
}
|
||||
}
|
||||
|
||||
Printf(getf.code," return pyobj;\n}\n");
|
||||
Printf(getf->code," return pyobj;\n}\n");
|
||||
|
||||
getf.print(f_wrappers);
|
||||
Wrapper_print(getf,f_wrappers);
|
||||
|
||||
// Now add this to the variable linking mechanism
|
||||
|
||||
|
|
@ -1301,6 +1306,8 @@ void PYTHON::link_variable(char *name, char *iname, DataType *t) {
|
|||
0);
|
||||
}
|
||||
}
|
||||
DelWrapper(setf);
|
||||
DelWrapper(getf);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ protected:
|
|||
|
||||
virtual void initialize_cmodule();
|
||||
virtual void close_cmodule();
|
||||
virtual void emit_function_header(WrapperFunction &emit_to, char *wname);
|
||||
virtual char *convert_self(WrapperFunction &f);
|
||||
virtual void emit_function_header(Wrapper *emit_to, char *wname);
|
||||
virtual char *convert_self(Wrapper *f);
|
||||
virtual char *make_funcname_wrapper(char *fnName);
|
||||
void emitAddPragmas(DOHString *output, char* name, char* spacing);
|
||||
|
||||
|
|
|
|||
|
|
@ -397,7 +397,7 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
char source[256], target[256];
|
||||
char *tm;
|
||||
DOHString *cleanup, *outarg;
|
||||
WrapperFunction f;
|
||||
Wrapper *f;
|
||||
int i;
|
||||
|
||||
// Ruby needs no destructor wrapper
|
||||
|
|
@ -410,6 +410,7 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
|
||||
cleanup = NewString("");
|
||||
outarg = NewString("");
|
||||
f = NewWrapper();
|
||||
|
||||
switch (current) {
|
||||
case MEMBER_FUNC:
|
||||
|
|
@ -450,18 +451,18 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
int vararg = (numoptreal != 0);
|
||||
|
||||
// Now write the wrapper function itself
|
||||
Printv(f.def, "static VALUE\n", wname, "(", 0);
|
||||
Printv(f->def, "static VALUE\n", wname, "(", 0);
|
||||
if (vararg) {
|
||||
Printv(f.def, "int argc, VALUE *argv, VALUE self",0);
|
||||
Printv(f->def, "int argc, VALUE *argv, VALUE self",0);
|
||||
} else {
|
||||
Printv(f.def, "VALUE self", 0);
|
||||
Printv(f->def, "VALUE self", 0);
|
||||
for (i = start; i < l->nparms; i++) {
|
||||
if (!l->get(i)->ignore) {
|
||||
Printf(f.def,", VALUE varg%d", i);
|
||||
Printf(f->def,", VALUE varg%d", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Printf(f.def,") {");
|
||||
Printf(f->def,") {");
|
||||
|
||||
// Emit all of the local variables for holding arguments.
|
||||
if (vararg) {
|
||||
|
|
@ -469,11 +470,11 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
if (!l->get(i)->ignore) {
|
||||
char s[256];
|
||||
sprintf(s,"varg%d",i);
|
||||
f.add_local((char*)"VALUE", s);
|
||||
Wrapper_add_local(f,(char*)"VALUE", s,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
f.add_local((char*)"VALUE", (char*)"vresult", (char*)"Qnil");
|
||||
Wrapper_add_local(f,(char*)"VALUE", (char*)"vresult", (char*)"Qnil");
|
||||
int pcount = emit_args(t,l,f);
|
||||
|
||||
#if 0
|
||||
|
|
@ -490,17 +491,17 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
<< (numarg-numoptreal) << numoptreal << "\") */" << br;
|
||||
temp << br;
|
||||
if (numignore != 0) Printf(stderr, temp);
|
||||
f.code << temp;
|
||||
f->code << temp;
|
||||
#endif
|
||||
// Emit count to check the number of arguments
|
||||
if (vararg) {
|
||||
Printf(f.code," rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numoptreal);
|
||||
Printf(f->code," rb_scan_args(argc, argv, \"%d%d\"", (numarg-numoptreal), numoptreal);
|
||||
for (i = start; i < l->nparms; i++) {
|
||||
if (!l->get(i)->ignore) {
|
||||
Printf(f.code,", &varg%d", i);
|
||||
Printf(f->code,", &varg%d", i);
|
||||
}
|
||||
}
|
||||
Printf(f.code,");\n");
|
||||
Printf(f->code,");\n");
|
||||
}
|
||||
|
||||
// Now walk the function parameter list and generate code
|
||||
|
|
@ -522,24 +523,24 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
if (!p.ignore) {
|
||||
char *tab = (char*)tab4;
|
||||
if (j >= (pcount-numopt)) { // Check if parsing an optional argument
|
||||
Printf(f.code," if (argc > %d) {\n", j - start);
|
||||
Printf(f->code," if (argc > %d) {\n", j - start);
|
||||
tab = (char*)tab8;
|
||||
}
|
||||
|
||||
// Get typemap for this argument
|
||||
tm = ruby_typemap_lookup((char*)"in",p.t,p.name,source,target,&f);
|
||||
tm = ruby_typemap_lookup((char*)"in",p.t,p.name,source,target,f);
|
||||
if (tm) {
|
||||
DOHString *s = NewString(tm);
|
||||
indent(s,tab);
|
||||
Printv(f.code, s, "\n", 0);
|
||||
Replace(f.code, "$arg", source, DOH_REPLACE_ANY);
|
||||
Printv(f->code, s, "\n", 0);
|
||||
Replace(f->code, "$arg", source, DOH_REPLACE_ANY);
|
||||
Delete(s);
|
||||
} else {
|
||||
Printf(stderr,"%s : Line %d. No typemapping for datatype %s\n",
|
||||
input_file,line_number, p.t->print_type());
|
||||
}
|
||||
if (j >= (pcount-numopt))
|
||||
Printv(f.code, tab4, "} \n");
|
||||
Printv(f->code, tab4, "} \n");
|
||||
j++;
|
||||
}
|
||||
|
||||
|
|
@ -548,8 +549,8 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
if (tm) {
|
||||
DOHString *s = NewString(tm);
|
||||
indent(s);
|
||||
Printv(f.code, s, "\n", 0);
|
||||
Replace(f.code, "$arg", source, DOH_REPLACE_ANY);
|
||||
Printv(f->code, s, "\n", 0);
|
||||
Replace(f->code, "$arg", source, DOH_REPLACE_ANY);
|
||||
Delete(s);
|
||||
}
|
||||
|
||||
|
|
@ -579,13 +580,13 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
// Return value if necessary
|
||||
if ((t->type != T_VOID) || (t->is_pointer)) {
|
||||
if (predicate) {
|
||||
Printv(f.code, tab4, "vresult = (_result ? Qtrue : Qfalse);\n", 0);
|
||||
Printv(f->code, tab4, "vresult = (_result ? Qtrue : Qfalse);\n", 0);
|
||||
} else {
|
||||
tm = ruby_typemap_lookup((char*)"out",t,name,(char*)"_result",(char*)"vresult");
|
||||
if (tm) {
|
||||
DOHString *s = NewString(tm);
|
||||
indent(s);
|
||||
Printv(f.code, s, "\n", 0);
|
||||
Printv(f->code, s, "\n", 0);
|
||||
Delete(s);
|
||||
} else {
|
||||
Printf(stderr,"%s : Line %d. No return typemap for datatype %s\n",
|
||||
|
|
@ -595,10 +596,10 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
}
|
||||
|
||||
// Dump argument output code;
|
||||
Printv(f.code,outarg,0);
|
||||
Printv(f->code,outarg,0);
|
||||
|
||||
// Dump the argument cleanup code
|
||||
Printv(f.code,cleanup,0);
|
||||
Printv(f->code,cleanup,0);
|
||||
|
||||
// Look for any remaining cleanup. This processes the %new directive
|
||||
if (NewObject) {
|
||||
|
|
@ -606,14 +607,14 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
if (tm) {
|
||||
DOHString *s = NewString(tm);
|
||||
indent(s);
|
||||
Printv(f.code,s,"\n", 0);
|
||||
Printv(f->code,s,"\n", 0);
|
||||
Delete(s);
|
||||
}
|
||||
}
|
||||
|
||||
// free pragma
|
||||
if (current == MEMBER_FUNC && Getattr(klass->freemethods, mname)) {
|
||||
Printv(f.code, tab4, "DATA_PTR(self) = 0;\n", 0);
|
||||
Printv(f->code, tab4, "DATA_PTR(self) = 0;\n", 0);
|
||||
}
|
||||
|
||||
// Special processing on return value.
|
||||
|
|
@ -621,22 +622,23 @@ void RUBY::create_function(char *name, char *iname, DataType *t, ParmList *l) {
|
|||
if (tm) {
|
||||
DOHString *s = NewString(tm);
|
||||
indent(s);
|
||||
Printv(f.code,s,"\n", 0);
|
||||
Printv(f->code,s,"\n", 0);
|
||||
}
|
||||
|
||||
// Wrap things up (in a manner of speaking)
|
||||
Printv(f.code, tab4, "return vresult;\n}\n", 0);
|
||||
Printv(f->code, tab4, "return vresult;\n}\n", 0);
|
||||
|
||||
// Substitute the cleanup code
|
||||
Replace(f.code,"$cleanup",cleanup, DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$cleanup",cleanup, DOH_REPLACE_ANY);
|
||||
|
||||
// Emit the function
|
||||
f.print(f_wrappers);
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
// Now register the function with the language
|
||||
create_command(name, iname, (vararg ? -1 : numarg));
|
||||
Delete(cleanup);
|
||||
Delete(outarg);
|
||||
DelWrapper(f);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
|
@ -651,9 +653,12 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
|
|||
char *tm;
|
||||
|
||||
DOHString *getfname, *setfname;
|
||||
WrapperFunction getf, setf;
|
||||
Wrapper *getf, *setf;
|
||||
int mod_attr = 0;
|
||||
|
||||
getf = NewWrapper();
|
||||
setf = NewWrapper();
|
||||
|
||||
// module attribute?
|
||||
if (current == STATIC_VAR || !toplevel)
|
||||
mod_attr = 1;
|
||||
|
|
@ -661,31 +666,31 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
|
|||
// create getter
|
||||
getfname = NewString(Swig_name_get(name));
|
||||
Replace(getfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */
|
||||
Printv(getf.def, "static VALUE\n", getfname, "(", 0);
|
||||
if (mod_attr) Printf(getf.def, "VALUE self");
|
||||
Printf(getf.def, ") {");
|
||||
getf.add_local((char*)"VALUE", (char*)"_val");
|
||||
Printv(getf->def, "static VALUE\n", getfname, "(", 0);
|
||||
if (mod_attr) Printf(getf->def, "VALUE self");
|
||||
Printf(getf->def, ") {");
|
||||
Wrapper_add_local(getf,(char*)"VALUE", (char*)"_val",0);
|
||||
tm = ruby_typemap_lookup((char*)"varout",t,name,name,(char*)"_val");
|
||||
if (!tm)
|
||||
tm = ruby_typemap_lookup((char*)"out",t,name,name,(char*)"_val");
|
||||
if (tm) {
|
||||
DOHString *s = NewString(tm);
|
||||
indent(s);
|
||||
Printv(getf.code,s,"\n", 0);
|
||||
Printv(getf->code,s,"\n", 0);
|
||||
Delete(s);
|
||||
} else if (!t->is_pointer && t->type == T_USER) {
|
||||
// Hack this into a pointer
|
||||
t->is_pointer++;
|
||||
t->remember();
|
||||
Printv(getf.code, tab4, "_val = SWIG_NewPointerObj((void *)&", name,
|
||||
Printv(getf->code, tab4, "_val = SWIG_NewPointerObj((void *)&", name,
|
||||
", \"", t->print_mangle(), "\");\n", 0);
|
||||
t->is_pointer--;
|
||||
} else {
|
||||
Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n",
|
||||
input_file,line_number,t->print_type());
|
||||
}
|
||||
Printv(getf.code, tab4, "return _val;\n}\n", 0);
|
||||
getf.print(f_wrappers);
|
||||
Printv(getf->code, tab4, "return _val;\n}\n", 0);
|
||||
Wrapper_print(getf,f_wrappers);
|
||||
|
||||
if (Status & STAT_READONLY) {
|
||||
setfname = NewString("NULL");
|
||||
|
|
@ -694,34 +699,34 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
|
|||
setfname = NewString(Swig_name_set(name));
|
||||
Replace(setfname,"::", "_", DOH_REPLACE_ANY); /* FIXME: Swig_name_get bug? */
|
||||
if (mod_attr)
|
||||
Printv(setf.def, "static VALUE\n", setfname, "(VALUE self, ", 0);
|
||||
Printv(setf->def, "static VALUE\n", setfname, "(VALUE self, ", 0);
|
||||
else
|
||||
Printv(setf.def, "static void\n", setfname, "(", 0);
|
||||
Printf(setf.def, "VALUE _val) {");
|
||||
Printv(setf->def, "static void\n", setfname, "(", 0);
|
||||
Printf(setf->def, "VALUE _val) {");
|
||||
tm = ruby_typemap_lookup((char*)"varin",t,name,(char*)"_val",name);
|
||||
if (!tm)
|
||||
tm = ruby_typemap_lookup((char*)"in",t,name,(char*)"_val",name);
|
||||
if (tm) {
|
||||
DOHString *s = NewString(tm);
|
||||
indent(s);
|
||||
Printv(setf.code,s,"\n",0);
|
||||
Printv(setf->code,s,"\n",0);
|
||||
Delete(s);
|
||||
} else if (!t->is_pointer && t->type == T_USER) {
|
||||
t->is_pointer++;
|
||||
setf.add_local(t->print_type(), (char*)"temp");
|
||||
Printv(setf.code, tab4, "temp = (", t->print_type(), ")",
|
||||
Wrapper_add_local(setf,t->print_type(), (char*)"temp",0);
|
||||
Printv(setf->code, tab4, "temp = (", t->print_type(), ")",
|
||||
"SWIG_ConvertPtr(_val, \"", t->print_mangle(), "\");\n",
|
||||
0);
|
||||
Printv(setf.code, tab4, name, " = *temp;\n",0);
|
||||
Printv(setf->code, tab4, name, " = *temp;\n",0);
|
||||
t->is_pointer--;
|
||||
} else {
|
||||
Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n",
|
||||
input_file,line_number,t->print_type());
|
||||
}
|
||||
if (mod_attr)
|
||||
Printv(setf.code, tab4, "return _val;\n",0);
|
||||
Printf(setf.code,"}\n");
|
||||
setf.print(f_wrappers);
|
||||
Printv(setf->code, tab4, "return _val;\n",0);
|
||||
Printf(setf->code,"}\n");
|
||||
Wrapper_print(setf,f_wrappers);
|
||||
}
|
||||
|
||||
// define accessor method
|
||||
|
|
@ -775,6 +780,8 @@ void RUBY::link_variable(char *name, char *iname, DataType *t) {
|
|||
}
|
||||
Delete(getfname);
|
||||
Delete(setfname);
|
||||
DelWrapper(setf);
|
||||
DelWrapper(getf);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -851,7 +858,7 @@ void RUBY::declare_const(char *name, char *iname, DataType *type, char *value) {
|
|||
// target = a string containing the target value
|
||||
// f = a wrapper function object (optional)
|
||||
// ---------------------------------------------------------------------
|
||||
char *RUBY::ruby_typemap_lookup(char *op, DataType *type, char *pname, char *source, char *target, WrapperFunction *f) {
|
||||
char *RUBY::ruby_typemap_lookup(char *op, DataType *type, char *pname, char *source, char *target, Wrapper *f) {
|
||||
static DOHString *s = 0;
|
||||
char *tm;
|
||||
DOHString *target_replace = NewString(target);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class RUBY : public Language {
|
|||
private:
|
||||
virtual char *make_wrapper_name(char *cname);
|
||||
virtual char *validate_const_name(char *name);
|
||||
virtual char *ruby_typemap_lookup(char *, DataType *, char *, char *, char *, WrapperFunction * = 0);
|
||||
virtual char *ruby_typemap_lookup(char *, DataType *, char *, char *, char *, Wrapper * = 0);
|
||||
virtual int to_VALUE(DataType *, char *, DOHString *, int = 0);
|
||||
virtual int from_VALUE(DataType *, char *, DOHString *);
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -470,11 +470,11 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
char source[64];
|
||||
char target[64];
|
||||
char argnum[32];
|
||||
WrapperFunction f;
|
||||
Wrapper *f;
|
||||
DOHString *incode, *cleanup, *outarg, *argstr, *args;
|
||||
int numopt= 0;
|
||||
|
||||
|
||||
f = NewWrapper();
|
||||
incode = NewString("");
|
||||
cleanup = NewString("");
|
||||
outarg = NewString("");
|
||||
|
|
@ -487,7 +487,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
// Now write the wrapper function itself....this is pretty ugly
|
||||
|
||||
Printv(f.def,
|
||||
Printv(f->def,
|
||||
"static int ", wname, "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {",
|
||||
0);
|
||||
|
||||
|
|
@ -520,7 +520,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
if (j == (pcount-numopt))
|
||||
Putc('|',argstr);
|
||||
|
||||
if ((tm = typemap_lookup((char*)"in",(char*)"tcl8",p->t,p->name,source,target,&f))) {
|
||||
if ((tm = typemap_lookup((char*)"in",(char*)"tcl8",p->t,p->name,source,target,f))) {
|
||||
Putc('o',argstr);
|
||||
Printf(args,",0");
|
||||
|
||||
|
|
@ -548,7 +548,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
{
|
||||
char tb[32];
|
||||
sprintf(tb,"tempb%d",i);
|
||||
f.add_local((char*)"int",tb);
|
||||
Wrapper_add_local(f,(char*)"int",tb,0);
|
||||
Printf(args,",&%s",tb);
|
||||
Printv(incode, tab4, target, " = (bool) ", tb, ";\n", 0);
|
||||
}
|
||||
|
|
@ -646,11 +646,11 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
p = l->get_next(); // Get next parameter and continue
|
||||
}
|
||||
Printf(argstr,":%s\"",usage);
|
||||
Printv(f.code,
|
||||
Printv(f->code,
|
||||
tab4, "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) return TCL_ERROR;\n",
|
||||
0);
|
||||
|
||||
Printv(f.code,incode,0);
|
||||
Printv(f->code,incode,0);
|
||||
|
||||
// Now write code to make the function call
|
||||
|
||||
|
|
@ -660,7 +660,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
if ((tm = typemap_lookup((char*)"out",(char*)"tcl8",d,name,(char*)"_result",(char*)"tcl_result"))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
} else if ((d->type != T_VOID) || (d->is_pointer)) {
|
||||
if (!d->is_pointer) {
|
||||
|
||||
|
|
@ -680,18 +680,18 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
case T_USHORT:
|
||||
case T_ULONG:
|
||||
case T_UCHAR:
|
||||
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewIntObj((long) _result));\n",0);
|
||||
Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewIntObj((long) _result));\n",0);
|
||||
break;
|
||||
|
||||
// Is a single character. Assume we return it as a string
|
||||
case T_CHAR :
|
||||
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(&_result,1));\n",0);
|
||||
Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(&_result,1));\n",0);
|
||||
break;
|
||||
|
||||
// Floating point number
|
||||
case T_DOUBLE :
|
||||
case T_FLOAT :
|
||||
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) _result));\n",0);
|
||||
Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) _result));\n",0);
|
||||
break;
|
||||
|
||||
// User defined type
|
||||
|
|
@ -702,7 +702,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
d->is_pointer++;
|
||||
d->remember();
|
||||
Printv(f.code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE",
|
||||
Printv(f->code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE",
|
||||
d->print_mangle(), "));\n", 0);
|
||||
|
||||
d->is_pointer--;
|
||||
|
|
@ -720,10 +720,10 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
|
||||
if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
|
||||
// Return a character string
|
||||
Printv(f.code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(_result,-1));\n",0);
|
||||
Printv(f->code, tab4, "Tcl_SetObjResult(interp,Tcl_NewStringObj(_result,-1));\n",0);
|
||||
} else {
|
||||
d->remember();
|
||||
Printv(f.code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE",
|
||||
Printv(f->code, tab4, "Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) _result,SWIGTYPE",
|
||||
d->print_mangle(), "));\n",
|
||||
0);
|
||||
}
|
||||
|
|
@ -731,32 +731,32 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
}
|
||||
|
||||
// Dump output argument code
|
||||
Printv(f.code,outarg,0);
|
||||
Printv(f->code,outarg,0);
|
||||
|
||||
// Dump the argument cleanup code
|
||||
Printv(f.code,cleanup,0);
|
||||
Printv(f->code,cleanup,0);
|
||||
|
||||
// Look for any remaining cleanup
|
||||
|
||||
if (NewObject) {
|
||||
if ((tm = typemap_lookup((char*)"newfree",(char*)"tcl8",d,iname,(char*)"_result",(char*)""))) {
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tm = typemap_lookup((char*)"ret",(char*)"tcl8",d,name,(char*)"_result",(char*)""))) {
|
||||
// Yep. Use it instead of the default
|
||||
Printf(f.code,"%s\n", tm);
|
||||
Printf(f->code,"%s\n", tm);
|
||||
}
|
||||
Printv(f.code,tab4, "return TCL_OK;\n}", 0);
|
||||
Printv(f->code,tab4, "return TCL_OK;\n}", 0);
|
||||
|
||||
// Substitute the cleanup code
|
||||
Replace(f.code,"$cleanup",cleanup,DOH_REPLACE_ANY);
|
||||
Replace(f.code,"$name", iname, DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$cleanup",cleanup,DOH_REPLACE_ANY);
|
||||
Replace(f->code,"$name", iname, DOH_REPLACE_ANY);
|
||||
|
||||
// Dump out the function
|
||||
|
||||
f.print(f_wrappers);
|
||||
Wrapper_print(f,f_wrappers);
|
||||
|
||||
// Now register the function with Tcl
|
||||
|
||||
|
|
@ -767,7 +767,7 @@ void TCL8::create_function(char *name, char *iname, DataType *d, ParmList *l)
|
|||
Delete(outarg);
|
||||
Delete(argstr);
|
||||
Delete(args);
|
||||
|
||||
DelWrapper(f);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
|
@ -792,21 +792,22 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
// Dump a collection of set/get functions suitable for variable tracing
|
||||
if (!Getattr(setget,t->print_type())) {
|
||||
Setattr(setget,t->print_type(),"1");
|
||||
WrapperFunction get;
|
||||
WrapperFunction set;
|
||||
Printv(set.def, "static char *_swig_", t->print_mangle(), "_set(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0);
|
||||
Wrapper *get, *set;
|
||||
get = NewWrapper();
|
||||
set = NewWrapper();
|
||||
Printv(set->def, "static char *_swig_", t->print_mangle(), "_set(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0);
|
||||
|
||||
Printv(get.def, "static char *_swig_", t->print_mangle(), "_get(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0);
|
||||
Printv(get->def, "static char *_swig_", t->print_mangle(), "_get(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {",0);
|
||||
t->is_pointer++;
|
||||
get.add_local(t->print_type(),(char*)"addr");
|
||||
set.add_local(t->print_type(),(char*)"addr");
|
||||
Printv(set.code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0);
|
||||
Printv(get.code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0);
|
||||
Wrapper_add_local(get,t->print_type(),(char*)"addr",0);
|
||||
Wrapper_add_local(set,t->print_type(),(char*)"addr",0);
|
||||
Printv(set->code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0);
|
||||
Printv(get->code, tab4, "addr = ", t->print_cast(), " clientData;\n", 0);
|
||||
t->is_pointer--;
|
||||
set.add_local((char*)"char *",(char*)"value");
|
||||
get.add_local((char*)"Tcl_Obj *",(char*)"value");
|
||||
Wrapper_add_local(set,(char*)"char *",(char*)"value",0);
|
||||
Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
|
||||
|
||||
Printv(set.code, tab4, "value = Tcl_GetVar2(interp, name1, name2, flags);\n",
|
||||
Printv(set->code, tab4, "value = Tcl_GetVar2(interp, name1, name2, flags);\n",
|
||||
tab4, "if (!value) return NULL;\n", 0);
|
||||
|
||||
if (!t->is_pointer) {
|
||||
|
|
@ -821,24 +822,24 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
case T_UCHAR:
|
||||
case T_SCHAR:
|
||||
case T_BOOL:
|
||||
Printv(set.code, tab4, "*(addr) = ", t->print_cast(), "atol(value);\n", 0);
|
||||
Printv(set->code, tab4, "*(addr) = ", t->print_cast(), "atol(value);\n", 0);
|
||||
break;
|
||||
case T_UINT:
|
||||
case T_ULONG:
|
||||
Printv(set.code, tab4, "*(addr) = ", t->print_cast(), "strtoul(value,0,0);\n",0);
|
||||
Printv(set->code, tab4, "*(addr) = ", t->print_cast(), "strtoul(value,0,0);\n",0);
|
||||
break;
|
||||
case T_FLOAT:
|
||||
case T_DOUBLE:
|
||||
Printv(set.code, tab4, "*(addr) = ", t->print_cast(), "atof(value);\n",0);
|
||||
Printv(set->code, tab4, "*(addr) = ", t->print_cast(), "atof(value);\n",0);
|
||||
break;
|
||||
case T_CHAR: /* Single character. */
|
||||
Printv(set.code, tab4, "*(addr) = *value;\n",0);
|
||||
Printv(set->code, tab4, "*(addr) = *value;\n",0);
|
||||
break;
|
||||
case T_USER:
|
||||
// User defined type. We return it as a pointer
|
||||
t->is_pointer++;
|
||||
t->remember();
|
||||
Printv(set.code, tab4, "{\n",
|
||||
Printv(set->code, tab4, "{\n",
|
||||
tab8, "void *ptr;\n",
|
||||
tab8, "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", t->print_mangle(), ") != TCL_OK) {\n",
|
||||
tab8, tab4, "return \"Type Error\";\n",
|
||||
|
|
@ -855,14 +856,14 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
}
|
||||
} else {
|
||||
if ((t->is_pointer == 1) && (t->type == T_CHAR)) {
|
||||
Printv(set.code, tab4, "if (*addr) free(*addr);\n",
|
||||
Printv(set->code, tab4, "if (*addr) free(*addr);\n",
|
||||
tab4, "*addr = (char *) malloc(strlen(value)+1);\n",
|
||||
tab4, "strcpy(*addr,value);\n",
|
||||
0);
|
||||
} else {
|
||||
// User defined type. We return it as a pointer
|
||||
t->remember();
|
||||
Printv(set.code, tab4, "{\n",
|
||||
Printv(set->code, tab4, "{\n",
|
||||
tab8, "void *ptr;\n",
|
||||
tab8, "if (SWIG_ConvertPtrFromString(interp,value,&ptr,SWIGTYPE", t->print_mangle(), ") != TCL_OK) {\n",
|
||||
tab8, tab4, "return \"Type Error\";\n",
|
||||
|
|
@ -874,7 +875,7 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
/* A Pointer */
|
||||
}
|
||||
}
|
||||
Printv(set.code, tab4, "return NULL;\n", "}\n",0);
|
||||
Printv(set->code, tab4, "return NULL;\n", "}\n",0);
|
||||
|
||||
if (!t->is_pointer) {
|
||||
switch(t->type) {
|
||||
|
|
@ -890,8 +891,8 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
case T_UCHAR:
|
||||
case T_SCHAR:
|
||||
case T_BOOL:
|
||||
get.add_local((char*)"Tcl_Obj *",(char*)"value");
|
||||
Printv(get.code,
|
||||
Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
|
||||
Printv(get->code,
|
||||
tab4, "value = Tcl_NewIntObj((int) *addr);\n",
|
||||
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
|
||||
tab4, "Tcl_DecrRefCount(value);\n",
|
||||
|
|
@ -899,8 +900,8 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
break;
|
||||
case T_FLOAT:
|
||||
case T_DOUBLE:
|
||||
get.add_local((char*)"Tcl_Obj *",(char*)"value");
|
||||
Printv(get.code,
|
||||
Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
|
||||
Printv(get->code,
|
||||
tab4, "value = Tcl_NewDoubleObj((double) *addr);\n",
|
||||
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
|
||||
tab4, "Tcl_DecrRefCount(value);\n",
|
||||
|
|
@ -908,17 +909,17 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
break;
|
||||
|
||||
case T_CHAR:
|
||||
get.add_local((char*)"char",(char*)"temp[4]");
|
||||
Printv(get.code,tab4, "temp[0] = *addr; temp[1] = 0;\n",
|
||||
Wrapper_add_local(get,(char*)"char",(char*)"temp[4]",0);
|
||||
Printv(get->code,tab4, "temp[0] = *addr; temp[1] = 0;\n",
|
||||
tab4, "Tcl_SetVar2(interp,name1,name2,temp,flags);\n",
|
||||
0);
|
||||
break;
|
||||
|
||||
case T_USER:
|
||||
get.add_local((char*)"Tcl_Obj *",(char*)"value");
|
||||
Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
|
||||
t->is_pointer++;
|
||||
t->remember();
|
||||
Printv(get.code, tab4, "value = SWIG_NewPointerObj(addr, SWIGTYPE", t->print_mangle(), ");\n",
|
||||
Printv(get->code, tab4, "value = SWIG_NewPointerObj(addr, SWIGTYPE", t->print_mangle(), ");\n",
|
||||
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
|
||||
tab4, "Tcl_DecrRefCount(value);\n",0);
|
||||
t->is_pointer--;
|
||||
|
|
@ -929,11 +930,11 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
}
|
||||
} else {
|
||||
if ((t->is_pointer == 1) && (t->type == T_CHAR)) {
|
||||
Printv(get.code, tab4, "Tcl_SetVar2(interp,name1,name2,*addr, flags);\n",0);
|
||||
Printv(get->code, tab4, "Tcl_SetVar2(interp,name1,name2,*addr, flags);\n",0);
|
||||
} else {
|
||||
get.add_local((char*)"Tcl_Obj *",(char*)"value");
|
||||
Wrapper_add_local(get,(char*)"Tcl_Obj *",(char*)"value",0);
|
||||
t->remember();
|
||||
Printv(get.code,
|
||||
Printv(get->code,
|
||||
tab4, "value = SWIG_NewPointerObj(*addr, SWIGTYPE", t->print_mangle(), ");\n",
|
||||
tab4, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n",
|
||||
tab4, "Tcl_DecrRefCount(value);\n",
|
||||
|
|
@ -941,20 +942,23 @@ void TCL8::link_variable(char *name, char *iname, DataType *t)
|
|||
}
|
||||
}
|
||||
|
||||
Printv(get.code, tab4, "return NULL;\n", "}\n",0);
|
||||
get.print(f_wrappers);
|
||||
set.print(f_wrappers);
|
||||
Printv(get->code, tab4, "return NULL;\n", "}\n",0);
|
||||
Wrapper_print(get,f_wrappers);
|
||||
Wrapper_print(set,f_wrappers);
|
||||
DelWrapper(get);
|
||||
DelWrapper(set);
|
||||
}
|
||||
Printv(var_info, tab4,"{ SWIG_prefix \"", iname, "\", (void *) &", name, ", _swig_", t->print_mangle(), "_get,", 0);
|
||||
|
||||
if (Status & STAT_READONLY) {
|
||||
static int readonly = 0;
|
||||
if (!readonly) {
|
||||
WrapperFunction ro;
|
||||
Printf(ro.def, "static char *_swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {");
|
||||
Printv(ro.code, tab4, "return \"Variable is read-only\";\n", "}\n", 0);
|
||||
ro.print(f_wrappers);
|
||||
Wrapper *ro = NewWrapper();
|
||||
Printf(ro->def, "static char *_swig_readonly(ClientData clientData, Tcl_Interp *interp, char *name1, char *name2, int flags) {");
|
||||
Printv(ro->code, tab4, "return \"Variable is read-only\";\n", "}\n", 0);
|
||||
Wrapper_print(ro,f_wrappers);
|
||||
readonly = 1;
|
||||
DelWrapper(ro);
|
||||
}
|
||||
Printf(var_info, "_swig_readonly},\n");
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue