fix anon enums
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5935 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
da6e5673e8
commit
9c6a029e75
4 changed files with 29 additions and 8 deletions
|
|
@ -35,4 +35,6 @@ struct StructWithEnums {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {Hi, Hello } hi;
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,8 @@ f.hola = f.Hello
|
||||||
if f.hola != f.Hello:
|
if f.hola != f.Hello:
|
||||||
print f.hola
|
print f.hola
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
cpp_enum.cvar.hi = cpp_enum.Hello
|
||||||
|
if cpp_enum.cvar.hi != cpp_enum.Hello:
|
||||||
|
print cpp_enum.cvar.hi
|
||||||
|
raise RuntimeError
|
||||||
|
|
|
||||||
21
Lib/python/pyenum.swg
Normal file
21
Lib/python/pyenum.swg
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* ------------------------------------------------------------
|
||||||
|
* Enums
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
|
%apply int { enum SWIGTYPE };
|
||||||
|
|
||||||
|
%typemap(varin,fragment=SWIG_AsVal_frag(int)) enum SWIGTYPE
|
||||||
|
{
|
||||||
|
if (sizeof(int) != sizeof($1)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "enum variable '$name' can not be set");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!SWIG_AsVal(int)($input, (int*)(void*)&($1))) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* this doesn't work now, you need to redefined it for each enum. */
|
||||||
|
%apply const int& { const enum SWIGTYPE& };
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -41,14 +41,7 @@
|
||||||
%include "pyptrtypes.swg"
|
%include "pyptrtypes.swg"
|
||||||
%include "pyprimtypes.swg"
|
%include "pyprimtypes.swg"
|
||||||
%include "pymisctypes.swg"
|
%include "pymisctypes.swg"
|
||||||
|
%include "pyenum.swg"
|
||||||
/* ------------------------------------------------------------
|
|
||||||
* Enums
|
|
||||||
* ------------------------------------------------------------ */
|
|
||||||
%apply int { enum SWIGTYPE };
|
|
||||||
/* this doesn't work now, you need to redefined it for each enum. */
|
|
||||||
%apply const int& { const enum SWIGTYPE& };
|
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
* Overloaded operator support
|
* Overloaded operator support
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue