fix premature object deletion reported by Paul in tcl3d
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8836 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
fbb04095a1
commit
609c14457d
3 changed files with 95 additions and 6 deletions
41
SWIG/Examples/test-suite/tcl/union.i
Normal file
41
SWIG/Examples/test-suite/tcl/union.i
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
%module unions
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
typedef unsigned char Uint8;
|
||||||
|
|
||||||
|
typedef struct SDL_ActiveEvent {
|
||||||
|
Uint8 type; /* SDL_ACTIVEEVENT */
|
||||||
|
Uint8 gain; /* Whether given states were gained or lost (1/0) */
|
||||||
|
Uint8 state; /* A mask of the focus states */
|
||||||
|
} SDL_ActiveEvent;
|
||||||
|
|
||||||
|
/* Keyboard event structure */
|
||||||
|
typedef struct SDL_KeyboardEvent {
|
||||||
|
Uint8 type; /* SDL_KEYDOWN or SDL_KEYUP */
|
||||||
|
int which; /* The keyboard device index */
|
||||||
|
int state; /* SDL_PRESSED or SDL_RELEASED */
|
||||||
|
} SDL_KeyboardEvent;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
Uint8 type;
|
||||||
|
SDL_ActiveEvent active;
|
||||||
|
SDL_KeyboardEvent key;
|
||||||
|
} SDL_Event;
|
||||||
|
|
||||||
|
int SDL_PollEvent (SDL_Event *ev) {
|
||||||
|
static int toggle = 0;
|
||||||
|
if (toggle == 0) {
|
||||||
|
ev->type = 1;
|
||||||
|
ev->active.gain = 20;
|
||||||
|
ev->active.state = 30;
|
||||||
|
} else {
|
||||||
|
ev->type = 2;
|
||||||
|
ev->key.which = 2000;
|
||||||
|
ev->key.state = 3000;
|
||||||
|
}
|
||||||
|
toggle = 1 - toggle;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
%}
|
||||||
36
SWIG/Examples/test-suite/tcl/union_runme.tcl
Executable file
36
SWIG/Examples/test-suite/tcl/union_runme.tcl
Executable file
|
|
@ -0,0 +1,36 @@
|
||||||
|
if [ catch { load ./union[info sharedlibextension] unions} err_msg ] {
|
||||||
|
puts stderr "Could not load shared object:\n$err_msg"
|
||||||
|
}
|
||||||
|
|
||||||
|
set event [SDL_Event]
|
||||||
|
|
||||||
|
for { set i 0 } { $i < 2 } { incr i } {
|
||||||
|
# puts -nonewline "Loop $i: "
|
||||||
|
set evAvailable [SDL_PollEvent $event]
|
||||||
|
set evType [$event cget -type]
|
||||||
|
# puts "evType = $evType"
|
||||||
|
|
||||||
|
if { $evType == 1 } {
|
||||||
|
set specEvent [$event cget -active]
|
||||||
|
# puts "specEvent = $specEvent"
|
||||||
|
set type [$specEvent cget -type]
|
||||||
|
if { $type != $evType } {
|
||||||
|
error "Type $type should be $evType"
|
||||||
|
}
|
||||||
|
set gain [$specEvent cget -gain]
|
||||||
|
set state [$specEvent cget -state]
|
||||||
|
# puts "gain=$gain state=$state"
|
||||||
|
}
|
||||||
|
if { $evType == 2 } {
|
||||||
|
set specEvent [$event cget -key]
|
||||||
|
# puts "specEvent = $specEvent"
|
||||||
|
set type [$specEvent cget -type]
|
||||||
|
if { $type != $evType } {
|
||||||
|
error "Type $type should be $evType"
|
||||||
|
}
|
||||||
|
set which [$specEvent cget -which]
|
||||||
|
set state [$specEvent cget -state]
|
||||||
|
# puts "which=$which state=$state"
|
||||||
|
}
|
||||||
|
# puts ""
|
||||||
|
}
|
||||||
|
|
@ -64,14 +64,26 @@
|
||||||
* Tcl extra typemaps
|
* Tcl extra typemaps
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// Old 1.3.25 typemaps needed to avoid premature object deletion
|
||||||
|
%typemap(out,noblock=1) SWIGTYPE *INSTANCE, SWIGTYPE &INSTANCE, SWIGTYPE INSTANCE[] {
|
||||||
|
Tcl_SetObjResult(interp, SWIG_NewInstanceObj( %as_voidptr($1), $1_descriptor,0));
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
|
||||||
|
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,%as_voidptrptr(&$1));
|
||||||
|
Tcl_SetObjResult(interp,SWIG_NewInstanceObj(%as_voidptr($1), ty,0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
%typemap(throws,noblock=1) SWIGTYPE CLASS {
|
||||||
|
SWIG_set_result(SWIG_NewInstanceObj(%as_voidptr(SWIG_new_copy($1, $1_ltype)), $&1_descriptor, 1));
|
||||||
|
SWIG_fail;
|
||||||
|
}
|
||||||
|
|
||||||
%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE;
|
%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE;
|
||||||
%typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE;
|
%typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE;
|
||||||
%typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE;
|
%typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE;
|
||||||
%typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[];
|
%typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[];
|
||||||
%typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE;
|
%typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE;
|
||||||
|
|
||||||
%typemap(throws,noblock=1) SWIGTYPE CLASS {
|
|
||||||
SWIG_set_result(SWIG_NewInstanceObj(SWIG_as_voidptr(SWIG_new_copy($1, $1_ltype)), $&1_descriptor, 1));
|
|
||||||
SWIG_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue