PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/perl5/perlrun.swg

#
Unknown | 506 lines | 428 code | 78 blank | 0 comment | 0 complexity | 085939992c90b7470224f6fcd2e98477 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * perlrun.swg
  3. *
  4. * This file contains the runtime support for Perl modules
  5. * and includes code for managing global variables and pointer
  6. * type checking.
  7. * ----------------------------------------------------------------------------- */
  8. #ifdef PERL_OBJECT
  9. #define SWIG_PERL_OBJECT_DECL CPerlObj *SWIGUNUSEDPARM(pPerl),
  10. #define SWIG_PERL_OBJECT_CALL pPerl,
  11. #else
  12. #define SWIG_PERL_OBJECT_DECL
  13. #define SWIG_PERL_OBJECT_CALL
  14. #endif
  15. /* Common SWIG API */
  16. /* for raw pointers */
  17. #define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags)
  18. #define SWIG_ConvertPtrAndOwn(obj, pp, type, flags,own) SWIG_Perl_ConvertPtrAndOwn(SWIG_PERL_OBJECT_CALL obj, pp, type, flags, own)
  19. #define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags)
  20. /* for raw packed data */
  21. #define SWIG_ConvertPacked(obj, p, s, type) SWIG_Perl_ConvertPacked(SWIG_PERL_OBJECT_CALL obj, p, s, type)
  22. #define SWIG_NewPackedObj(p, s, type) SWIG_Perl_NewPackedObj(SWIG_PERL_OBJECT_CALL p, s, type)
  23. /* for class or struct pointers */
  24. #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags)
  25. #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags)
  26. /* for C or C++ function pointers */
  27. #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0)
  28. #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0)
  29. /* for C++ member pointers, ie, member methods */
  30. #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_ConvertPacked(obj, ptr, sz, ty)
  31. #define SWIG_NewMemberObj(ptr, sz, type) SWIG_NewPackedObj(ptr, sz, type)
  32. /* Runtime API */
  33. #define SWIG_GetModule(clientdata) SWIG_Perl_GetModule()
  34. #define SWIG_SetModule(clientdata, pointer) SWIG_Perl_SetModule(pointer)
  35. /* Error manipulation */
  36. #define SWIG_ErrorType(code) SWIG_Perl_ErrorType(code)
  37. #define SWIG_Error(code, msg) sv_setpvf(get_sv("@", GV_ADD), "%s %s", SWIG_ErrorType(code), msg)
  38. #define SWIG_fail goto fail
  39. /* Perl-specific SWIG API */
  40. #define SWIG_MakePtr(sv, ptr, type, flags) SWIG_Perl_MakePtr(SWIG_PERL_OBJECT_CALL sv, ptr, type, flags)
  41. #define SWIG_MakePackedObj(sv, p, s, type) SWIG_Perl_MakePackedObj(SWIG_PERL_OBJECT_CALL sv, p, s, type)
  42. #define SWIG_SetError(str) SWIG_Error(SWIG_RuntimeError, str)
  43. #define SWIG_PERL_DECL_ARGS_1(arg1) (SWIG_PERL_OBJECT_DECL arg1)
  44. #define SWIG_PERL_CALL_ARGS_1(arg1) (SWIG_PERL_OBJECT_CALL arg1)
  45. #define SWIG_PERL_DECL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_DECL arg1, arg2)
  46. #define SWIG_PERL_CALL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_CALL arg1, arg2)
  47. /* -----------------------------------------------------------------------------
  48. * pointers/data manipulation
  49. * ----------------------------------------------------------------------------- */
  50. /* For backward compatibility only */
  51. #define SWIG_POINTER_EXCEPTION 0
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. #define SWIG_OWNER SWIG_POINTER_OWN
  56. #define SWIG_SHADOW SWIG_OWNER << 1
  57. #define SWIG_MAYBE_PERL_OBJECT SWIG_PERL_OBJECT_DECL
  58. /* SWIG Perl macros */
  59. /* Macro to declare an XS function */
  60. #ifndef XSPROTO
  61. # define XSPROTO(name) void name(pTHX_ CV* cv)
  62. #endif
  63. /* Macro to call an XS function */
  64. #ifdef PERL_OBJECT
  65. # define SWIG_CALLXS(_name) _name(cv,pPerl)
  66. #else
  67. # ifndef MULTIPLICITY
  68. # define SWIG_CALLXS(_name) _name(cv)
  69. # else
  70. # define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv)
  71. # endif
  72. #endif
  73. #ifdef PERL_OBJECT
  74. #define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78. typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *);
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
  83. #define SWIGCLASS_STATIC
  84. #else /* PERL_OBJECT */
  85. #define MAGIC_PPERL
  86. #define SWIGCLASS_STATIC static SWIGUNUSED
  87. #ifndef MULTIPLICITY
  88. #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
  89. #ifdef __cplusplus
  90. extern "C" {
  91. #endif
  92. typedef int (*SwigMagicFunc)(SV *, MAGIC *);
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #else /* MULTIPLICITY */
  97. #define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b)
  98. #ifdef __cplusplus
  99. extern "C" {
  100. #endif
  101. typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* MULTIPLICITY */
  106. #endif /* PERL_OBJECT */
  107. # ifdef PERL_OBJECT
  108. # define SWIG_croak_null() SWIG_Perl_croak_null(pPerl)
  109. static void SWIG_Perl_croak_null(CPerlObj *pPerl)
  110. # else
  111. static void SWIG_croak_null()
  112. # endif
  113. {
  114. SV *err = get_sv("@", GV_ADD);
  115. # if (PERL_VERSION < 6)
  116. croak("%_", err);
  117. # else
  118. if (sv_isobject(err))
  119. croak(0);
  120. else
  121. croak("%s", SvPV_nolen(err));
  122. # endif
  123. }
  124. /*
  125. Define how strict is the cast between strings and integers/doubles
  126. when overloading between these types occurs.
  127. The default is making it as strict as possible by using SWIG_AddCast
  128. when needed.
  129. You can use -DSWIG_PERL_NO_STRICT_STR2NUM at compilation time to
  130. disable the SWIG_AddCast, making the casting between string and
  131. numbers less strict.
  132. In the end, we try to solve the overloading between strings and
  133. numerical types in the more natural way, but if you can avoid it,
  134. well, avoid it using %rename, for example.
  135. */
  136. #ifndef SWIG_PERL_NO_STRICT_STR2NUM
  137. # ifndef SWIG_PERL_STRICT_STR2NUM
  138. # define SWIG_PERL_STRICT_STR2NUM
  139. # endif
  140. #endif
  141. #ifdef SWIG_PERL_STRICT_STR2NUM
  142. /* string takes precedence */
  143. #define SWIG_Str2NumCast(x) SWIG_AddCast(x)
  144. #else
  145. /* number takes precedence */
  146. #define SWIG_Str2NumCast(x) x
  147. #endif
  148. #include <stdlib.h>
  149. SWIGRUNTIME const char *
  150. SWIG_Perl_TypeProxyName(const swig_type_info *type) {
  151. if (!type) return NULL;
  152. if (type->clientdata != NULL) {
  153. return (const char*) type->clientdata;
  154. }
  155. else {
  156. return type->name;
  157. }
  158. }
  159. /* Identical to SWIG_TypeCheck, except for strcmp comparison */
  160. SWIGRUNTIME swig_cast_info *
  161. SWIG_TypeProxyCheck(const char *c, swig_type_info *ty) {
  162. if (ty) {
  163. swig_cast_info *iter = ty->cast;
  164. while (iter) {
  165. if (strcmp(SWIG_Perl_TypeProxyName(iter->type), c) == 0) {
  166. if (iter == ty->cast)
  167. return iter;
  168. /* Move iter to the top of the linked list */
  169. iter->prev->next = iter->next;
  170. if (iter->next)
  171. iter->next->prev = iter->prev;
  172. iter->next = ty->cast;
  173. iter->prev = 0;
  174. if (ty->cast) ty->cast->prev = iter;
  175. ty->cast = iter;
  176. return iter;
  177. }
  178. iter = iter->next;
  179. }
  180. }
  181. return 0;
  182. }
  183. /* Function for getting a pointer value */
  184. SWIGRUNTIME int
  185. SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags, int *own) {
  186. swig_cast_info *tc;
  187. void *voidptr = (void *)0;
  188. SV *tsv = 0;
  189. if (own)
  190. *own = 0;
  191. /* If magical, apply more magic */
  192. if (SvGMAGICAL(sv))
  193. mg_get(sv);
  194. /* Check to see if this is an object */
  195. if (sv_isobject(sv)) {
  196. IV tmp = 0;
  197. tsv = (SV*) SvRV(sv);
  198. if ((SvTYPE(tsv) == SVt_PVHV)) {
  199. MAGIC *mg;
  200. if (SvMAGICAL(tsv)) {
  201. mg = mg_find(tsv,'P');
  202. if (mg) {
  203. sv = mg->mg_obj;
  204. if (sv_isobject(sv)) {
  205. tsv = (SV*)SvRV(sv);
  206. tmp = SvIV(tsv);
  207. }
  208. }
  209. } else {
  210. return SWIG_ERROR;
  211. }
  212. } else {
  213. tmp = SvIV(tsv);
  214. }
  215. voidptr = INT2PTR(void *,tmp);
  216. } else if (! SvOK(sv)) { /* Check for undef */
  217. *(ptr) = (void *) 0;
  218. return SWIG_OK;
  219. } else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */
  220. if (!SvROK(sv)) {
  221. /* In Perl 5.12 and later, SVt_RV == SVt_IV, so sv could be a valid integer value. */
  222. if (SvIOK(sv)) {
  223. return SWIG_ERROR;
  224. } else {
  225. /* NULL pointer (reference to undef). */
  226. *(ptr) = (void *) 0;
  227. return SWIG_OK;
  228. }
  229. } else {
  230. return SWIG_ERROR;
  231. }
  232. } else { /* Don't know what it is */
  233. return SWIG_ERROR;
  234. }
  235. if (_t) {
  236. /* Now see if the types match */
  237. char *_c = HvNAME(SvSTASH(SvRV(sv)));
  238. tc = SWIG_TypeProxyCheck(_c,_t);
  239. if (!tc) {
  240. return SWIG_ERROR;
  241. }
  242. {
  243. int newmemory = 0;
  244. *ptr = SWIG_TypeCast(tc,voidptr,&newmemory);
  245. if (newmemory == SWIG_CAST_NEW_MEMORY) {
  246. assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
  247. if (own)
  248. *own = *own | SWIG_CAST_NEW_MEMORY;
  249. }
  250. }
  251. } else {
  252. *ptr = voidptr;
  253. }
  254. /*
  255. * DISOWN implementation: we need a perl guru to check this one.
  256. */
  257. if (tsv && (flags & SWIG_POINTER_DISOWN)) {
  258. /*
  259. * almost copy paste code from below SWIG_POINTER_OWN setting
  260. */
  261. SV *obj = sv;
  262. HV *stash = SvSTASH(SvRV(obj));
  263. GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
  264. if (isGV(gv)) {
  265. HV *hv = GvHVn(gv);
  266. /*
  267. * To set ownership (see below), a newSViv(1) entry is added.
  268. * Hence, to remove ownership, we delete the entry.
  269. */
  270. if (hv_exists_ent(hv, obj, 0)) {
  271. hv_delete_ent(hv, obj, 0, 0);
  272. }
  273. }
  274. }
  275. return SWIG_OK;
  276. }
  277. SWIGRUNTIME int
  278. SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
  279. return SWIG_Perl_ConvertPtrAndOwn(sv, ptr, _t, flags, 0);
  280. }
  281. SWIGRUNTIME void
  282. SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) {
  283. if (ptr && (flags & (SWIG_SHADOW | SWIG_POINTER_OWN))) {
  284. SV *self;
  285. SV *obj=newSV(0);
  286. HV *hash=newHV();
  287. HV *stash;
  288. sv_setref_pv(obj, SWIG_Perl_TypeProxyName(t), ptr);
  289. stash=SvSTASH(SvRV(obj));
  290. if (flags & SWIG_POINTER_OWN) {
  291. HV *hv;
  292. GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
  293. if (!isGV(gv))
  294. gv_init(gv, stash, "OWNER", 5, FALSE);
  295. hv=GvHVn(gv);
  296. hv_store_ent(hv, obj, newSViv(1), 0);
  297. }
  298. sv_magic((SV *)hash, (SV *)obj, 'P', Nullch, 0);
  299. SvREFCNT_dec(obj);
  300. self=newRV_noinc((SV *)hash);
  301. sv_setsv(sv, self);
  302. SvREFCNT_dec((SV *)self);
  303. sv_bless(sv, stash);
  304. }
  305. else {
  306. sv_setref_pv(sv, SWIG_Perl_TypeProxyName(t), ptr);
  307. }
  308. }
  309. SWIGRUNTIMEINLINE SV *
  310. SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) {
  311. SV *result = sv_newmortal();
  312. SWIG_MakePtr(result, ptr, t, flags);
  313. return result;
  314. }
  315. SWIGRUNTIME void
  316. SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) {
  317. char result[1024];
  318. char *r = result;
  319. if ((2*sz + 1 + strlen(SWIG_Perl_TypeProxyName(type))) > 1000) return;
  320. *(r++) = '_';
  321. r = SWIG_PackData(r,ptr,sz);
  322. strcpy(r,SWIG_Perl_TypeProxyName(type));
  323. sv_setpv(sv, result);
  324. }
  325. SWIGRUNTIME SV *
  326. SWIG_Perl_NewPackedObj(SWIG_MAYBE_PERL_OBJECT void *ptr, int sz, swig_type_info *type) {
  327. SV *result = sv_newmortal();
  328. SWIG_Perl_MakePackedObj(result, ptr, sz, type);
  329. return result;
  330. }
  331. /* Convert a packed value value */
  332. SWIGRUNTIME int
  333. SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty) {
  334. swig_cast_info *tc;
  335. const char *c = 0;
  336. if ((!obj) || (!SvOK(obj))) return SWIG_ERROR;
  337. c = SvPV_nolen(obj);
  338. /* Pointer values must start with leading underscore */
  339. if (*c != '_') return SWIG_ERROR;
  340. c++;
  341. c = SWIG_UnpackData(c,ptr,sz);
  342. if (ty) {
  343. tc = SWIG_TypeCheck(c,ty);
  344. if (!tc) return SWIG_ERROR;
  345. }
  346. return SWIG_OK;
  347. }
  348. /* Macros for low-level exception handling */
  349. #define SWIG_croak(x) { SWIG_Error(SWIG_RuntimeError, x); SWIG_fail; }
  350. typedef XSPROTO(SwigPerlWrapper);
  351. typedef SwigPerlWrapper *SwigPerlWrapperPtr;
  352. /* Structure for command table */
  353. typedef struct {
  354. const char *name;
  355. SwigPerlWrapperPtr wrapper;
  356. } swig_command_info;
  357. /* Information for constant table */
  358. #define SWIG_INT 1
  359. #define SWIG_FLOAT 2
  360. #define SWIG_STRING 3
  361. #define SWIG_POINTER 4
  362. #define SWIG_BINARY 5
  363. /* Constant information structure */
  364. typedef struct swig_constant_info {
  365. int type;
  366. const char *name;
  367. long lvalue;
  368. double dvalue;
  369. void *pvalue;
  370. swig_type_info **ptype;
  371. } swig_constant_info;
  372. /* Structure for variable table */
  373. typedef struct {
  374. const char *name;
  375. SwigMagicFunc set;
  376. SwigMagicFunc get;
  377. swig_type_info **type;
  378. } swig_variable_info;
  379. /* Magic variable code */
  380. #ifndef PERL_OBJECT
  381. # ifdef __cplusplus
  382. # define swig_create_magic(s,a,b,c) _swig_create_magic(s,const_cast<char*>(a),b,c)
  383. # else
  384. # define swig_create_magic(s,a,b,c) _swig_create_magic(s,(char*)(a),b,c)
  385. # endif
  386. # ifndef MULTIPLICITY
  387. SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *))
  388. # else
  389. SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *))
  390. # endif
  391. #else
  392. # define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c)
  393. SWIGRUNTIME void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *))
  394. #endif
  395. {
  396. MAGIC *mg;
  397. sv_magic(sv,sv,'U',name,strlen(name));
  398. mg = mg_find(sv,'U');
  399. mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL));
  400. mg->mg_virtual->svt_get = (SwigMagicFunc) get;
  401. mg->mg_virtual->svt_set = (SwigMagicFunc) set;
  402. mg->mg_virtual->svt_len = 0;
  403. mg->mg_virtual->svt_clear = 0;
  404. mg->mg_virtual->svt_free = 0;
  405. }
  406. SWIGRUNTIME swig_module_info *
  407. SWIG_Perl_GetModule(void) {
  408. static void *type_pointer = (void *)0;
  409. SV *pointer;
  410. /* first check if pointer already created */
  411. if (!type_pointer) {
  412. pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, FALSE | GV_ADDMULTI);
  413. if (pointer && SvOK(pointer)) {
  414. type_pointer = INT2PTR(swig_type_info **, SvIV(pointer));
  415. }
  416. }
  417. return (swig_module_info *) type_pointer;
  418. }
  419. SWIGRUNTIME void
  420. SWIG_Perl_SetModule(swig_module_info *module) {
  421. SV *pointer;
  422. /* create a new pointer */
  423. pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE | GV_ADDMULTI);
  424. sv_setiv(pointer, PTR2IV(module));
  425. }
  426. #ifdef __cplusplus
  427. }
  428. #endif