Add $isvoid special variable expansion for directors

Complete the removal of Ruby's output_helper macro and replacement
with SWIG_AppendOutput for director typemaps.
Requires $isvoid special variable support in director code.
This commit is contained in:
William S Fulton 2024-10-06 15:00:37 +01:00
parent a95017050e
commit 09001ee302
13 changed files with 25 additions and 7 deletions

View File

@ -10,7 +10,9 @@ Version 4.3.0 (in progress)
2024-10-05: wsfulton
[Ruby] Removed backwards compatible output_helper fragment and macro.
Use SWIG_AppendOutput instead of output_helper (does not require the
output_helper macro).
output_helper fragment).
*** POTENTIAL INCOMPATIBILITY ***
2024-10-05: wsfulton
[Ruby] #2907 Fix returning null from functions with output parameters.
@ -315,6 +317,8 @@ Version 4.3.0 (in progress)
[Python] Removed deprecated pytuplehlp.swg file and t_output_helper.
Use SWIG_Python_AppendOutput instead of t_output_helper.
*** POTENTIAL INCOMPATIBILITY ***
2024-06-15: vadz
[Python] #2907 Fix returning null from functions with output parameters.
Ensures OUTPUT and INOUT typemaps are handled consistently wrt return

View File

@ -2885,9 +2885,9 @@ example:</p>
$1 = &amp;temp;
}
%typemap(argout, fragment="output_helper") int *out {
%typemap(argout) int *out {
// Append output value $1 to $result (assuming a single integer in this case)
$result = output_helper( $result, INT2NUM(*$1) );
$result = SWIG_AppendOutput( $result, INT2NUM(*$1) );
}</pre>
</div>
@ -3187,9 +3187,8 @@ exception.
member functions.</p>
<div class="code"><pre>
%typemap(directorargout,
fragment="output_helper") int {
$result = output_helper( $result, NUM2INT($1) );
%typemap(directorargout) int {
$result = SWIG_AppendOutput( $result, NUM2INT($1) );
}
</pre></div>

View File

@ -127,6 +127,7 @@ void DirectorTest_director_testmethodSwigExplicitDirectorTest(int i) {}
%}
%typemap(directorargout) int i {
$symname(99);
int isvoid_special_variable = $isvoid;
}
%feature("director") DirectorTest;
%inline %{

View File

@ -4440,6 +4440,7 @@ public:
} else {
Replaceall(w->code, "$null", "");
}
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!ignored_method)
Printv(director_delegate_callback, "\n", callback_def, callback_code, NIL);
if (!Getattr(n, "defaultargs")) {

View File

@ -2347,6 +2347,7 @@ public:
} else {
Replaceall(w->code, "$null", "");
}
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!ignored_method)
Printv(director_dcallbacks_code, callback_def, callback_code, NIL);
if (!Getattr(n, "defaultargs")) {

View File

@ -3264,7 +3264,9 @@ private:
Swig_typemap_attach_parms("imtype", parms, NULL);
int parm_count = emit_num_arguments(parms);
SwigType *result = Getattr(n, "type");
SwigType *returntype = Getattr(n, "type");
SwigType *result = returntype;
bool is_void = !(Cmp(returntype, "void"));
// Save the type for overload processing.
Setattr(n, "go:type", result);
@ -3998,6 +4000,7 @@ private:
Printv(w->code, "}", NULL);
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_c_directors);
}

View File

@ -4518,6 +4518,7 @@ public:
} else {
Replaceall(w->code, "$null", "");
}
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!GetFlag(n, "feature:ignore"))
Printv(imclass_directors, callback_def, callback_code, NIL);
if (!Getattr(n, "defaultargs")) {

View File

@ -1669,6 +1669,7 @@ public:
/* emit the director method */
if (status == SWIG_OK) {
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);

View File

@ -1538,6 +1538,7 @@ public:
}
// emit the director method
if (status == SWIG_OK) {
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);

View File

@ -2442,6 +2442,7 @@ public:
/* emit the director method */
if (status == SWIG_OK) {
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);
@ -2456,6 +2457,7 @@ public:
DelWrapper(w);
return status;
}
int classDirectorDisown(Node *n) {
int rv;
member_func = 1;
@ -2468,6 +2470,7 @@ public:
}
return rv;
}
int classDirectorDestructor(Node *n) {
/* TODO: it would be nice if this didn't have to copy the body of Language::classDirectorDestructor() */
String *DirectorClassName = directorClassName(getCurrentClass());

View File

@ -2517,6 +2517,7 @@ public:
/* emit the director method */
if (status == SWIG_OK) {
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);

View File

@ -5891,6 +5891,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* emit the director method */
if (status == SWIG_OK) {
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);

View File

@ -3366,6 +3366,7 @@ public:
/* emit the director method */
if (status == SWIG_OK) {
Replaceall(w->code, "$isvoid", is_void ? "1" : "0");
if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors);