mirror of
https://github.com/eclipse/upm.git
synced 2025-07-05 11:21:12 +03:00
swig: ensure that all uint*_t passed in have the correct type.
Otherwise, we generate an exception. This should fix Issue #172: https://github.com/intel-iot-devkit/upm/issues/172 Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
e003a11723
commit
387b2b86b0
@ -6,3 +6,51 @@
|
||||
%include "stdint.i"
|
||||
%include "carrays.i"
|
||||
%array_class(uint32_t, uint32Array);
|
||||
|
||||
// Adding these typemaps because SWIG is converting uint8, uint16, and uint32 into a short by default
|
||||
// This forces SWIG to convert it correctly
|
||||
|
||||
#if (SWIG_JAVASCRIPT_V8)
|
||||
%typemap(in) uint32_t * {
|
||||
void *argp = 0 ;
|
||||
int res = SWIG_ConvertPtr($input, &argp, SWIGTYPE_p_uint32Array, 0 | 0 );
|
||||
if (!SWIG_IsOK(res)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(res), "failed to convert input to uint32 *");
|
||||
}
|
||||
$1 = (uint32_t *)(argp);
|
||||
}
|
||||
|
||||
/*$input (non-pointer) is a v8::object, which inherits from v8::value */
|
||||
%typemap(in) uint32_t {
|
||||
int ecode2 = 0 ;
|
||||
if (($input)->IsInt32())
|
||||
$1 = ($input)->Uint32Value();
|
||||
else
|
||||
SWIG_exception_fail(SWIG_ArgError(ecode2), "failed to convert uint32");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (SWIGPYTHON)
|
||||
%typemap(in) uint32_t * {
|
||||
void *argp = 0 ;
|
||||
int res = SWIG_ConvertPtr($input, &argp, SWIGTYPE_p_uint32Array, 0 | 0 );
|
||||
if (!SWIG_IsOK(res)) {
|
||||
SWIG_exception_fail(SWIG_ArgError(res), "failed to convert input to uint32 *");
|
||||
}
|
||||
$1 = reinterpret_cast< uint32_t * >(argp);
|
||||
}
|
||||
|
||||
/*$input (non-pointer) */
|
||||
%typemap(in) uint32_t {
|
||||
long v;
|
||||
int res = SWIG_AsVal_long ($input, &v);
|
||||
if (SWIG_IsOK(res)) {
|
||||
$1 = PyInt_AsLong($input);
|
||||
}
|
||||
else {
|
||||
SWIG_exception_fail(SWIG_ArgError(res), "failed to convert uint32");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//#elsif (SWIGJAVA)
|
||||
|
Reference in New Issue
Block a user