scirun.swg 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* -----------------------------------------------------------------------------
  2. * Scilab support runtime
  3. * -----------------------------------------------------------------------------*/
  4. /* Scilab version macro */
  5. #include "version.h"
  6. #define SWIG_SCILAB_VERSION (SCI_VERSION_MAJOR * 100) + (SCI_VERSION_MINOR * 10) + SCI_VERSION_MAINTENANCE
  7. /* Scilab standard headers */
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include "api_scilab.h"
  12. #if SWIG_SCILAB_VERSION < 540
  13. #define __USE_DEPRECATED_STACK_FUNCTIONS__
  14. #include "stack-c.h"
  15. #endif
  16. #include "MALLOC.h"
  17. #include "Scierror.h"
  18. #include "localization.h"
  19. #include "freeArrayOfString.h"
  20. #include <sci_gateway.h>
  21. #include <mex.h>
  22. #ifdef __cplusplus
  23. }
  24. #endif
  25. /* Gateway signature */
  26. #if SWIG_SCILAB_VERSION >= 600
  27. #define SWIG_GatewayParameters char* fname, void *pvApiCtx
  28. #define SWIG_GatewayArguments fname, pvApiCtx
  29. #else
  30. #define SWIG_GatewayParameters char* fname, unsigned long fname_len
  31. #define SWIG_GatewayArguments fname, fname_len
  32. #endif
  33. /* Function name management functions */
  34. #include <stdlib.h>
  35. static char *SwigFuncName = NULL;
  36. static char *SWIG_Scilab_GetFuncName(void) {
  37. return SwigFuncName;
  38. }
  39. static void SWIG_Scilab_SetFuncName(char *funcName) {
  40. if (SwigFuncName != NULL) {
  41. free(SwigFuncName);
  42. }
  43. SwigFuncName = strdup(funcName);
  44. }
  45. /* Api context management functions */
  46. #if SWIG_SCILAB_VERSION >= 600
  47. static void *pvApiCtx = NULL;
  48. static void SWIG_Scilab_SetApiContext(void *apiCtx) {
  49. pvApiCtx = apiCtx;
  50. }
  51. #else
  52. #define SWIG_Scilab_SetApiContext(apiCtx)
  53. #endif
  54. /* Argument management functions */
  55. #if SWIG_SCILAB_VERSION >= 540
  56. #define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument)
  57. #define SWIG_CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) CheckInputArgumentAtLeast(pvApiCtx, minInputArgument)
  58. #define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument)
  59. #define SWIG_NbInputArgument(pvApiCtx) nbInputArgument(pvApiCtx)
  60. #define SWIG_AssignOutputArgument(pvApiCtx, outputArgumentPos, argumentPos) AssignOutputVariable(pvApiCtx, outputArgumentPos) = argumentPos
  61. #else
  62. #define SWIG_CheckInputArgument(pvApiCtx, minInputArgument, maxInputArgument) CheckRhs(minInputArgument, maxInputArgument)
  63. #define SWIG_CheckInputArgumentAtLeast(pvApiCtx, minInputArgument) CheckRhs(minInputArgument, 256)
  64. #define SWIG_CheckOutputArgument(pvApiCtx, minOutputArgument, maxOutputArgument) CheckLhs(minOutputArgument, maxOutputArgument)
  65. #define SWIG_NbInputArgument(pvApiCtx) Rhs
  66. #define SWIG_AssignOutputArgument(pvApiCtx, outputArgumentPos, argumentPos) LhsVar(outputArgumentPos) = argumentPos
  67. #endif
  68. typedef int SwigSciObject;
  69. static int SwigOutputPosition = -1;
  70. static int SWIG_Scilab_GetOutputPosition(void) {
  71. return SwigOutputPosition;
  72. }
  73. static void SWIG_Scilab_SetOutputPosition(int outputPosition) {
  74. SwigOutputPosition = outputPosition;
  75. }
  76. SWIGRUNTIME int
  77. SWIG_Scilab_SetOutput(void *pvApiCtx, SwigSciObject output) {
  78. int outputPosition = SWIG_Scilab_GetOutputPosition();
  79. if (outputPosition < 0)
  80. return SWIG_ERROR;
  81. SWIG_AssignOutputArgument(pvApiCtx, outputPosition,
  82. SWIG_NbInputArgument(pvApiCtx) + outputPosition);
  83. return SWIG_OK;
  84. }
  85. /* Pointer conversion functions */
  86. SWIGINTERN int
  87. SwigScilabPtrToObject(void *pvApiCtx, int iVar, void **pObjValue, swig_type_info *descriptor, int flags, char *fname) {
  88. SciErr sciErr;
  89. int iType = 0;
  90. int *piAddrVar = NULL;
  91. sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar);
  92. if (sciErr.iErr) {
  93. printError(&sciErr, 0);
  94. return SWIG_ERROR;
  95. }
  96. sciErr = getVarType(pvApiCtx, piAddrVar, &iType);
  97. if (sciErr.iErr) {
  98. printError(&sciErr, 0);
  99. return SWIG_ERROR;
  100. }
  101. if (iType == sci_pointer) {
  102. sciErr = getPointer(pvApiCtx, piAddrVar, pObjValue);
  103. if (sciErr.iErr) {
  104. printError(&sciErr, 0);
  105. return SWIG_ERROR;
  106. }
  107. }
  108. else {
  109. return SWIG_ERROR;
  110. }
  111. return SWIG_OK;
  112. }
  113. SWIGRUNTIMEINLINE int
  114. SwigScilabPtrFromObject(void *pvApiCtx, int iVarOut, void *obj, swig_type_info *descriptor, int flags) {
  115. SciErr sciErr;
  116. sciErr = createPointer(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, (void *)obj);
  117. if (sciErr.iErr) {
  118. printError(&sciErr, 0);
  119. return SWIG_ERROR;
  120. }
  121. return SWIG_OK;
  122. }
  123. SWIGRUNTIME int
  124. SWIG_Scilab_ConvertPacked(void *pvApiCtx, int iVar, void *ptr, int sz, swig_type_info *ty, char *fname) {
  125. swig_cast_info *tc;
  126. int *piAddrVar = NULL;
  127. char *pstString = NULL;
  128. char *pstStringPtr = NULL;
  129. SciErr sciErr;
  130. sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar);
  131. if (sciErr.iErr) {
  132. printError(&sciErr, 0);
  133. return SWIG_ERROR;
  134. }
  135. if (getAllocatedSingleString(pvApiCtx, piAddrVar, &pstString)) {
  136. return SWIG_ERROR;
  137. }
  138. /* Pointer values must start with leading underscore */
  139. if (*pstString != '_') {
  140. freeAllocatedSingleString(pstString);
  141. return SWIG_ERROR;
  142. }
  143. pstStringPtr = pstString;
  144. pstStringPtr++;
  145. pstStringPtr = (char*)SWIG_UnpackData(pstStringPtr, ptr, sz);
  146. if (ty) {
  147. if (!pstStringPtr) {
  148. freeAllocatedSingleString(pstString);
  149. return SWIG_ERROR;
  150. }
  151. tc = SWIG_TypeCheck(pstStringPtr, ty);
  152. if (!tc) {
  153. freeAllocatedSingleString(pstString);
  154. return SWIG_ERROR;
  155. }
  156. }
  157. freeAllocatedSingleString(pstString);
  158. return SWIG_OK;
  159. }
  160. SWIGRUNTIME int
  161. SWIG_Scilab_NewMemberObj(void *pvApiCtx, int iVarOut, void *ptr, int sz, swig_type_info *type) {
  162. char result[1024];
  163. char *r = result;
  164. if ((2*sz + 1 + strlen(type->name)) > 1000) {
  165. return SWIG_ERROR;
  166. }
  167. *(r++) = '_';
  168. r = SWIG_PackData(r, ptr, sz);
  169. strcpy(r, type->name);
  170. if (createSingleString(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, &result[0]))
  171. return SWIG_ERROR;
  172. return SWIG_OK;
  173. }
  174. /* Error functions */
  175. #define SCILAB_API_ARGUMENT_ERROR 999
  176. SWIGINTERN const char*
  177. SWIG_Scilab_ErrorType(int code) {
  178. switch(code) {
  179. case SWIG_MemoryError:
  180. return "MemoryError";
  181. case SWIG_IOError:
  182. return "IOError";
  183. case SWIG_RuntimeError:
  184. return "RuntimeError";
  185. case SWIG_IndexError:
  186. return "IndexError";
  187. case SWIG_TypeError:
  188. return "TypeError";
  189. case SWIG_DivisionByZero:
  190. return "ZeroDivisionError";
  191. case SWIG_OverflowError:
  192. return "OverflowError";
  193. case SWIG_SyntaxError:
  194. return "SyntaxError";
  195. case SWIG_ValueError:
  196. return "ValueError";
  197. case SWIG_SystemError:
  198. return "SystemError";
  199. case SWIG_AttributeError:
  200. return "AttributeError";
  201. default:
  202. return "RuntimeError";
  203. }
  204. }
  205. #define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code)
  206. #ifndef SWIG_SCILAB_ERROR
  207. #define SWIG_SCILAB_ERROR 20000
  208. #endif
  209. SWIGINTERN void
  210. SWIG_Scilab_Error(int code, const char *msg)
  211. {
  212. Scierror(SWIG_SCILAB_ERROR - code, _("SWIG/Scilab: %s: %s\n"), SWIG_Scilab_ErrorType(code), msg);
  213. }
  214. #define SWIG_Error(code, msg) SWIG_Scilab_Error(code, msg)
  215. #define SWIG_fail return SWIG_ERROR;
  216. SWIGRUNTIME void
  217. SWIG_Scilab_Raise_Ex(const char *obj, const char *type, swig_type_info *descriptor) {
  218. if (type) {
  219. if (obj)
  220. Scierror(SWIG_SCILAB_ERROR, "SWIG/Scilab: Exception (%s) occured: %s\n", type, obj);
  221. else
  222. Scierror(SWIG_SCILAB_ERROR, "SWIG/Scilab: Exception (%s) occured.\n", type);
  223. }
  224. }
  225. SWIGRUNTIME void
  226. SWIG_Scilab_Raise(const int obj, const char *type, swig_type_info *descriptor) {
  227. Scierror(SWIG_SCILAB_ERROR, "SWIG/Scilab: Exception (%s) occured.\n", type);
  228. }
  229. /*
  230. * Pointer utility functions
  231. */
  232. #include <stdint.h>
  233. #ifdef __cplusplus
  234. extern "C"
  235. #endif
  236. int SWIG_this(SWIG_GatewayParameters) {
  237. void *ptrValue = NULL;
  238. if (SwigScilabPtrToObject(pvApiCtx, 1, &ptrValue, NULL, 0, fname) == SWIG_OK) {
  239. SWIG_Scilab_SetOutputPosition(1);
  240. return SWIG_Scilab_SetOutput(pvApiCtx,
  241. createScalarDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + 1,
  242. (double)(uintptr_t)ptrValue));
  243. }
  244. else {
  245. Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The value is not a pointer.\n"), fname, 1);
  246. return SWIG_ERROR;
  247. }
  248. }
  249. #ifdef __cplusplus
  250. extern "C"
  251. #endif
  252. int SWIG_ptr(SWIG_GatewayParameters) {
  253. double dValue = 0;
  254. int *piAddr;
  255. SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
  256. if(sciErr.iErr) {
  257. printError(&sciErr, 0);
  258. return SWIG_ERROR;
  259. }
  260. if (getScalarDouble(pvApiCtx, piAddr, &dValue) == 0) {
  261. if (dValue != (uintptr_t)dValue) {
  262. Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Incorrect value for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1);
  263. return SWIG_ValueError;
  264. }
  265. if ((dValue < 0) || (dValue > ULONG_MAX)) {
  266. Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Overflow error for input argument #%d: The double value cannot be converted to a pointer.\n"), fname, 1);
  267. return SWIG_OverflowError;
  268. }
  269. SWIG_Scilab_SetOutputPosition(1);
  270. return SWIG_Scilab_SetOutput(pvApiCtx,
  271. SwigScilabPtrFromObject(pvApiCtx, 1, (void *) (uintptr_t)dValue, NULL, 0));
  272. }
  273. else {
  274. return SWIG_ERROR;
  275. }
  276. }