more on uniforming and 'securing' the typemap declarations

for primitive types.

Finally, you can safetly write:

%apply int {enum Hello};
%apply long {size_t};
%apply int {MyIntClass};

or using references

%apply const int& {const enum Hello&};
%apply const long& {const size_t&};
%apply const int& {MyIntClass&};

and all the primitive typemaps(in, out, directorin, directorout,
constcode, throws, varin, varout) are safetly applied to the
desired types (including the proper conversions when needed).

In fact, the python.swg file now has no typemap
defined for enums, and only use the %apply directives
as above.

Now the primitive_types.i extensive test runs properly.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5683 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-01-24 00:43:47 +00:00
commit 7c6097b392
2 changed files with 341 additions and 390 deletions

View file

@ -12,6 +12,7 @@
#include <limits.h>
#include <float.h>
#include <string.h>
#ifdef __cplusplus
#define SWIG_STATIC_INLINE static inline
@ -168,14 +169,31 @@ SWIG_STATIC_INLINE PyObject *
SPyObj_FromCharPtr(const char* cptr) {
return cptr ? PyString_FromString(cptr) : Py_BuildValue((char*)"");
}
SWIG_STATIC_INLINE PyObject *
SPyObj_FromCharArray(const char* carray, size_t size) {
return PyString_FromStringAndSize(carray, strnlen(carray, size));
}
SWIG_STATIC_INLINE void
SPyObj_AsCharArray(PyObject *obj, char* carray, size_t size) {
const char* s = PyString_Check(obj) ? PyString_AsString(obj) : 0;
if (!PyErr_Occurred()) {
size_t len = strlen(s);
if (len > size) {
PyErr_SetObject(PyExc_TypeError,
PyString_FromFormat("a string of maximum size %d is required", size));
}
strncpy(carray, s, size);
}
}
SWIG_STATIC_INLINE int
SPyObj_AsBool(PyObject *obj) {
return SPyObj_AsLongLong(obj) ? 1 : 0;
}
#ifdef __cplusplus
extern "C" {
#endif
@ -539,7 +557,7 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
obj = PyFloat_FromDouble(constants[i].dvalue);
break;
case SWIG_PY_STRING:
obj = PyString_FromString((char *) constants[i].pvalue);
obj = SPyObj_FromCharPtr((const char *) constants[i].pvalue);
break;
case SWIG_PY_POINTER:
obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);