ocaml.swg 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /* -*-c-*- */
  2. /* SWIG pointer structure */
  3. #include <string.h>
  4. #include <assert.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #define C_bool 0
  9. #define C_char 1
  10. #define C_uchar 2
  11. #define C_short 3
  12. #define C_ushort 4
  13. #define C_int 5
  14. #define C_uint 6
  15. #define C_int32 7
  16. #define C_int64 8
  17. #define C_float 9
  18. #define C_double 10
  19. #define C_ptr 11
  20. #define C_array 12
  21. #define C_list 13
  22. #define C_obj 14
  23. #define C_string 15
  24. #define C_enum 16
  25. #define C_director_core 17
  26. /* Cast a pointer if possible; returns 1 if successful */
  27. SWIGSTATIC int
  28. SWIG_Cast (void *source, swig_type_info *source_type,
  29. void **ptr, swig_type_info *dest_type)
  30. {
  31. if( !source ) { // Special case for NULL. This is a popular question
  32. // for other modules on the list, so I want an easy way out...
  33. *ptr = 0;
  34. return 0;
  35. }
  36. #ifdef TYPE_CAST_VERBOSE
  37. fprintf( stderr, "Trying to cast %s to %s\n",
  38. source_type ? source_type->str : "<none>",
  39. dest_type ? dest_type->str : "<none>" );
  40. #endif
  41. if (dest_type != source_type) {
  42. /* We have a type mismatch. Will have to look through our type
  43. mapping table to figure out whether or not we can accept this
  44. datatype.
  45. --
  46. Ignore typechecks for void *. Allow any conversion. */
  47. if( !dest_type || !source_type ||
  48. !strcmp(dest_type->name,"_p_void") ||
  49. !strcmp(source_type->name,"_p_void") ) {
  50. *ptr = source;
  51. return 0;
  52. } else {
  53. swig_cast_info *tc =
  54. SWIG_TypeCheckStruct(source_type, dest_type );
  55. #ifdef TYPE_CAST_VERBOSE
  56. fprintf( stderr, "Typecheck -> %s\n",
  57. tc ? tc->str : "<none>" );
  58. #endif
  59. if( tc ) {
  60. int newmemory = 0;
  61. *ptr = SWIG_TypeCast(tc, source, &newmemory);
  62. assert(!newmemory); /* newmemory handling not yet implemented */
  63. return 0;
  64. } else
  65. return -1;
  66. }
  67. } else {
  68. *ptr = source;
  69. return 0;
  70. }
  71. }
  72. /* Return 0 if successful. */
  73. SWIGSTATIC int
  74. SWIG_GetPtr(void *inptr, void **outptr,
  75. swig_type_info *intype, swig_type_info *outtype) {
  76. if (intype) {
  77. return SWIG_Cast(inptr, intype,
  78. outptr, outtype) == -1;
  79. } else {
  80. *outptr = inptr;
  81. return 0;
  82. }
  83. }
  84. SWIGSTATIC void caml_print_list( CAML_VALUE v );
  85. SWIGSTATIC void caml_print_val( CAML_VALUE v ) {
  86. switch( SWIG_Tag_val(v) ) {
  87. case C_bool:
  88. if( Bool_val(SWIG_Field(v,0)) ) fprintf( stderr, "true " );
  89. else fprintf( stderr, "false " );
  90. break;
  91. case C_char:
  92. case C_uchar:
  93. fprintf( stderr, "'%c' (\\%03d) ",
  94. (Int_val(SWIG_Field(v,0)) >= ' ' &&
  95. Int_val(SWIG_Field(v,0)) < 127) ? Int_val(SWIG_Field(v,0)) : '.',
  96. Int_val(SWIG_Field(v,0)) );
  97. break;
  98. case C_short:
  99. case C_ushort:
  100. case C_int:
  101. fprintf( stderr, "%d ", (int)caml_long_val(v) );
  102. break;
  103. case C_uint:
  104. case C_int32:
  105. fprintf( stderr, "%ud ", (unsigned int)caml_long_val(v) );
  106. break;
  107. case C_int64:
  108. fprintf( stderr, "%ld ", caml_long_val(v) );
  109. break;
  110. case C_float:
  111. case C_double:
  112. fprintf( stderr, "%f ", caml_double_val(v) );
  113. break;
  114. case C_ptr:
  115. {
  116. void *vout = 0;
  117. swig_type_info *ty = (swig_type_info *)(long)SWIG_Int64_val(SWIG_Field(v,1));
  118. caml_ptr_val_internal(v,&vout,0);
  119. fprintf( stderr, "PTR(%p,%s) ",
  120. vout,
  121. ty ? ty->name : "(null)" );
  122. }
  123. break;
  124. case C_array:
  125. {
  126. unsigned int i;
  127. for( i = 0; i < Wosize_val( SWIG_Field(v,0) ); i++ )
  128. caml_print_val( SWIG_Field(SWIG_Field(v,0),i) );
  129. }
  130. break;
  131. case C_list:
  132. caml_print_list( SWIG_Field(v,0) );
  133. break;
  134. case C_obj:
  135. fprintf( stderr, "OBJ(%p) ", (void *)SWIG_Field(v,0) );
  136. break;
  137. case C_string:
  138. {
  139. void *cout;
  140. caml_ptr_val_internal(v,&cout,0);
  141. fprintf( stderr, "'%s' ", (char *)cout );
  142. }
  143. break;
  144. }
  145. }
  146. SWIGSTATIC void caml_print_list( CAML_VALUE v ) {
  147. CAMLparam1(v);
  148. while( v && Is_block(v) ) {
  149. fprintf( stderr, "[ " );
  150. caml_print_val( SWIG_Field(v,0) );
  151. fprintf( stderr, "]\n" );
  152. v = SWIG_Field(v,1);
  153. }
  154. CAMLreturn0;
  155. }
  156. SWIGSTATIC CAML_VALUE caml_list_nth( CAML_VALUE lst, int n ) {
  157. CAMLparam1(lst);
  158. int i = 0;
  159. while( i < n && lst && Is_block(lst) ) {
  160. i++; lst = SWIG_Field(lst,1);
  161. }
  162. if( lst == Val_unit ) CAMLreturn(Val_unit);
  163. else CAMLreturn(SWIG_Field(lst,0));
  164. }
  165. SWIGSTATIC CAML_VALUE caml_list_append( CAML_VALUE lst, CAML_VALUE elt ) {
  166. CAMLparam2(lst,elt);
  167. SWIG_CAMLlocal3(v,vt,lh);
  168. lh = Val_unit;
  169. v = Val_unit;
  170. /* Appending C_void should have no effect */
  171. if( !Is_block(elt) ) return lst;
  172. while( lst && Is_block(lst) ) {
  173. if( v && v != Val_unit ) {
  174. vt = alloc_tuple(2);
  175. SWIG_Store_field(v,1,vt);
  176. v = vt;
  177. } else {
  178. v = lh = alloc_tuple(2);
  179. }
  180. SWIG_Store_field(v,0,SWIG_Field(lst,0));
  181. lst = SWIG_Field(lst,1);
  182. }
  183. if( v && Is_block(v) ) {
  184. vt = alloc_tuple(2);
  185. SWIG_Store_field(v,1,vt);
  186. v = vt;
  187. } else {
  188. v = lh = alloc_tuple(2);
  189. }
  190. SWIG_Store_field(v,0,elt);
  191. SWIG_Store_field(v,1,Val_unit);
  192. CAMLreturn(lh);
  193. }
  194. SWIGSTATIC int caml_list_length( CAML_VALUE lst ) {
  195. CAMLparam1(lst);
  196. int i = 0;
  197. while( lst && Is_block(lst) ) { i++; lst = SWIG_Field(lst,1); }
  198. CAMLreturn(i);
  199. }
  200. SWIGSTATIC void caml_array_set( CAML_VALUE arr, int n, CAML_VALUE item ) {
  201. CAMLparam2(arr,item);
  202. SWIG_Store_field(SWIG_Field(arr,0),n,item);
  203. CAMLreturn0;
  204. }
  205. SWIGSTATIC value caml_array_nth( CAML_VALUE arr, int n ) {
  206. CAMLparam1(arr);
  207. if( SWIG_Tag_val(arr) == C_array )
  208. CAMLreturn(SWIG_Field(SWIG_Field(arr,0),n));
  209. else if( SWIG_Tag_val(arr) == C_list )
  210. CAMLreturn(caml_list_nth(arr,0));
  211. else
  212. failwith("Need array or list");
  213. }
  214. SWIGSTATIC int caml_array_len( CAML_VALUE arr ) {
  215. CAMLparam1(arr);
  216. if( SWIG_Tag_val(arr) == C_array )
  217. CAMLreturn(Wosize_val(SWIG_Field(arr,0)));
  218. else if( SWIG_Tag_val(arr) == C_list )
  219. CAMLreturn(caml_list_length(arr));
  220. else
  221. failwith("Need array or list");
  222. }
  223. SWIGSTATIC CAML_VALUE caml_swig_alloc(int x,int y) {
  224. return caml_alloc(x,y);
  225. }
  226. SWIGSTATIC value caml_array_new( int n ) {
  227. CAMLparam0();
  228. SWIG_CAMLlocal1(vv);
  229. vv = caml_swig_alloc(1,C_array);
  230. SWIG_Store_field(vv,0,alloc_tuple(n));
  231. CAMLreturn(vv);
  232. }
  233. SWIGSTATIC CAML_VALUE caml_val_bool( int b ) {
  234. CAMLparam0();
  235. SWIG_CAMLlocal1(bv);
  236. bv = caml_swig_alloc(1,C_bool);
  237. SWIG_Store_field(bv,0,Val_bool(b));
  238. CAMLreturn(bv);
  239. }
  240. SWIGSTATIC CAML_VALUE caml_val_char( char c ) {
  241. CAMLparam0();
  242. SWIG_CAMLlocal1(cv);
  243. cv = caml_swig_alloc(1,C_char);
  244. SWIG_Store_field(cv,0,Val_int(c));
  245. CAMLreturn(cv);
  246. }
  247. SWIGSTATIC CAML_VALUE caml_val_uchar( unsigned char uc ) {
  248. CAMLparam0();
  249. SWIG_CAMLlocal1(ucv);
  250. ucv = caml_swig_alloc(1,C_uchar);
  251. SWIG_Store_field(ucv,0,Val_int(uc));
  252. CAMLreturn(ucv);
  253. }
  254. SWIGSTATIC CAML_VALUE caml_val_short( short s ) {
  255. CAMLparam0();
  256. SWIG_CAMLlocal1(sv);
  257. sv = caml_swig_alloc(1,C_short);
  258. SWIG_Store_field(sv,0,Val_int(s));
  259. CAMLreturn(sv);
  260. }
  261. SWIGSTATIC CAML_VALUE caml_val_ushort( unsigned short us ) {
  262. CAMLparam0();
  263. SWIG_CAMLlocal1(usv);
  264. usv = caml_swig_alloc(1,C_ushort);
  265. SWIG_Store_field(usv,0,Val_int(us));
  266. CAMLreturn(usv);
  267. }
  268. SWIGSTATIC CAML_VALUE caml_val_int( int i ) {
  269. CAMLparam0();
  270. SWIG_CAMLlocal1(iv);
  271. iv = caml_swig_alloc(1,C_int);
  272. SWIG_Store_field(iv,0,Val_int(i));
  273. CAMLreturn(iv);
  274. }
  275. SWIGSTATIC CAML_VALUE caml_val_uint( unsigned int ui ) {
  276. CAMLparam0();
  277. SWIG_CAMLlocal1(uiv);
  278. uiv = caml_swig_alloc(1,C_int);
  279. SWIG_Store_field(uiv,0,Val_int(ui));
  280. CAMLreturn(uiv);
  281. }
  282. SWIGSTATIC CAML_VALUE caml_val_long( long l ) {
  283. CAMLparam0();
  284. SWIG_CAMLlocal1(lv);
  285. lv = caml_swig_alloc(1,C_int64);
  286. SWIG_Store_field(lv,0,copy_int64(l));
  287. CAMLreturn(lv);
  288. }
  289. SWIGSTATIC CAML_VALUE caml_val_ulong( unsigned long ul ) {
  290. CAMLparam0();
  291. SWIG_CAMLlocal1(ulv);
  292. ulv = caml_swig_alloc(1,C_int64);
  293. SWIG_Store_field(ulv,0,copy_int64(ul));
  294. CAMLreturn(ulv);
  295. }
  296. SWIGSTATIC CAML_VALUE caml_val_float( float f ) {
  297. CAMLparam0();
  298. SWIG_CAMLlocal1(fv);
  299. fv = caml_swig_alloc(1,C_float);
  300. SWIG_Store_field(fv,0,copy_double((double)f));
  301. CAMLreturn(fv);
  302. }
  303. SWIGSTATIC CAML_VALUE caml_val_double( double d ) {
  304. CAMLparam0();
  305. SWIG_CAMLlocal1(fv);
  306. fv = caml_swig_alloc(1,C_double);
  307. SWIG_Store_field(fv,0,copy_double(d));
  308. CAMLreturn(fv);
  309. }
  310. SWIGSTATIC CAML_VALUE caml_val_ptr( void *p, swig_type_info *info ) {
  311. CAMLparam0();
  312. SWIG_CAMLlocal1(vv);
  313. vv = caml_swig_alloc(2,C_ptr);
  314. SWIG_Store_field(vv,0,copy_int64((long)p));
  315. SWIG_Store_field(vv,1,copy_int64((long)info));
  316. CAMLreturn(vv);
  317. }
  318. SWIGSTATIC CAML_VALUE caml_val_string( const char *p ) {
  319. CAMLparam0();
  320. SWIG_CAMLlocal1(vv);
  321. if( !p ) CAMLreturn(caml_val_ptr( (void *)p, 0 ));
  322. vv = caml_swig_alloc(1,C_string);
  323. SWIG_Store_field(vv,0,copy_string(p));
  324. CAMLreturn(vv);
  325. }
  326. SWIGSTATIC CAML_VALUE caml_val_string_len( const char *p, int len ) {
  327. CAMLparam0();
  328. SWIG_CAMLlocal1(vv);
  329. if( !p || len < 0 ) CAMLreturn(caml_val_ptr( (void *)p, 0 ));
  330. vv = caml_swig_alloc(1,C_string);
  331. SWIG_Store_field(vv,0,alloc_string(len));
  332. memcpy(String_val(SWIG_Field(vv,0)),p,len);
  333. CAMLreturn(vv);
  334. }
  335. #define caml_val_obj(v, name) caml_val_obj_helper(v, SWIG_TypeQuery((name)), name)
  336. SWIGSTATIC CAML_VALUE caml_val_obj_helper( void *v, swig_type_info *type, char *name) {
  337. CAMLparam0();
  338. CAMLreturn(callback2(*caml_named_value("caml_create_object_fn"),
  339. caml_val_ptr(v,type),
  340. copy_string(name)));
  341. }
  342. SWIGSTATIC long caml_long_val_full( CAML_VALUE v, char *name ) {
  343. CAMLparam1(v);
  344. if( !Is_block(v) ) return 0;
  345. switch( SWIG_Tag_val(v) ) {
  346. case C_bool:
  347. case C_char:
  348. case C_uchar:
  349. case C_short:
  350. case C_ushort:
  351. case C_int:
  352. CAMLreturn(Int_val(SWIG_Field(v,0)));
  353. case C_uint:
  354. case C_int32:
  355. CAMLreturn(Int32_val(SWIG_Field(v,0)));
  356. case C_int64:
  357. CAMLreturn((long)SWIG_Int64_val(SWIG_Field(v,0)));
  358. case C_float:
  359. case C_double:
  360. CAMLreturn((long)Double_val(SWIG_Field(v,0)));
  361. case C_string:
  362. CAMLreturn((long)String_val(SWIG_Field(v,0)));
  363. case C_ptr:
  364. CAMLreturn((long)SWIG_Int64_val(SWIG_Field(SWIG_Field(v,0),0)));
  365. case C_enum: {
  366. SWIG_CAMLlocal1(ret);
  367. CAML_VALUE *enum_to_int = caml_named_value(SWIG_MODULE "_enum_to_int");
  368. if( !name ) failwith( "Not an enum conversion" );
  369. ret = callback2(*enum_to_int,*caml_named_value(name),v);
  370. CAMLreturn(caml_long_val(ret));
  371. }
  372. default:
  373. failwith("No conversion to int");
  374. }
  375. }
  376. SWIGSTATIC long caml_long_val( CAML_VALUE v ) {
  377. return caml_long_val_full(v,0);
  378. }
  379. SWIGSTATIC double caml_double_val( CAML_VALUE v ) {
  380. CAMLparam1(v);
  381. if( !Is_block(v) ) return 0.0;
  382. switch( SWIG_Tag_val(v) ) {
  383. case C_bool:
  384. case C_char:
  385. case C_uchar:
  386. case C_short:
  387. case C_ushort:
  388. case C_int:
  389. CAMLreturn_type(Int_val(SWIG_Field(v,0)));
  390. case C_uint:
  391. case C_int32:
  392. CAMLreturn_type(Int32_val(SWIG_Field(v,0)));
  393. case C_int64:
  394. CAMLreturn_type(SWIG_Int64_val(SWIG_Field(v,0)));
  395. case C_float:
  396. case C_double:
  397. CAMLreturn_type(Double_val(SWIG_Field(v,0)));
  398. default:
  399. fprintf( stderr, "Unknown block tag %d\n", SWIG_Tag_val(v) );
  400. failwith("No conversion to double");
  401. }
  402. }
  403. SWIGSTATIC int caml_ptr_val_internal( CAML_VALUE v, void **out,
  404. swig_type_info *descriptor ) {
  405. CAMLparam1(v);
  406. void *outptr = NULL;
  407. swig_type_info *outdescr = NULL;
  408. if( v == Val_unit ) {
  409. *out = 0;
  410. CAMLreturn(0);
  411. }
  412. if( !Is_block(v) ) return -1;
  413. switch( SWIG_Tag_val(v) ) {
  414. case C_int:
  415. if( !caml_long_val( v ) ) {
  416. *out = 0;
  417. CAMLreturn(0);
  418. } else {
  419. *out = 0;
  420. CAMLreturn(1);
  421. }
  422. break;
  423. case C_obj:
  424. CAMLreturn
  425. (caml_ptr_val_internal
  426. (callback(*caml_named_value("caml_obj_ptr"),v),
  427. out,descriptor));
  428. case C_string:
  429. outptr = (void *)String_val(SWIG_Field(v,0));
  430. break;
  431. case C_ptr:
  432. outptr = (void *)(long)SWIG_Int64_val(SWIG_Field(v,0));
  433. outdescr = (swig_type_info *)(long)SWIG_Int64_val(SWIG_Field(v,1));
  434. break;
  435. default:
  436. *out = 0;
  437. CAMLreturn(1);
  438. break;
  439. }
  440. CAMLreturn(SWIG_GetPtr(outptr,out,outdescr,descriptor));
  441. }
  442. SWIGSTATIC void *caml_ptr_val( CAML_VALUE v, swig_type_info *descriptor ) {
  443. CAMLparam0();
  444. #ifdef TYPE_CAST_VERBOSE
  445. caml_print_val( v );
  446. #endif
  447. void *out = NULL;
  448. if( !caml_ptr_val_internal( v, &out, descriptor ) )
  449. CAMLreturn_type(out);
  450. else
  451. failwith( "No appropriate conversion found." );
  452. }
  453. SWIGSTATIC char *caml_string_val( CAML_VALUE v ) {
  454. return (char *)caml_ptr_val( v, 0 );
  455. }
  456. SWIGSTATIC int caml_string_len( CAML_VALUE v ) {
  457. switch( SWIG_Tag_val(v) ) {
  458. case C_string:
  459. return string_length(SWIG_Field(v,0));
  460. default:
  461. return strlen((char *)caml_ptr_val(v,0));
  462. }
  463. }
  464. SWIGSTATIC int caml_bool_check( CAML_VALUE v ) {
  465. CAMLparam1(v);
  466. if( !Is_block(v) ) return 0;
  467. switch( SWIG_Tag_val(v) ) {
  468. case C_bool:
  469. case C_ptr:
  470. case C_string:
  471. CAMLreturn(1);
  472. default:
  473. CAMLreturn(0);
  474. }
  475. }
  476. SWIGSTATIC int caml_int_check( CAML_VALUE v ) {
  477. CAMLparam1(v);
  478. if( !Is_block(v) ) return 0;
  479. switch( SWIG_Tag_val(v) ) {
  480. case C_char:
  481. case C_uchar:
  482. case C_short:
  483. case C_ushort:
  484. case C_int:
  485. case C_uint:
  486. case C_int32:
  487. case C_int64:
  488. CAMLreturn(1);
  489. default:
  490. CAMLreturn(0);
  491. }
  492. }
  493. SWIGSTATIC int caml_float_check( CAML_VALUE v ) {
  494. CAMLparam1(v);
  495. if( !Is_block(v) ) return 0;
  496. switch( SWIG_Tag_val(v) ) {
  497. case C_float:
  498. case C_double:
  499. CAMLreturn(1);
  500. default:
  501. CAMLreturn(0);
  502. }
  503. }
  504. SWIGSTATIC int caml_ptr_check( CAML_VALUE v ) {
  505. CAMLparam1(v);
  506. if( !Is_block(v) ) return 0;
  507. switch( SWIG_Tag_val(v) ) {
  508. case C_string:
  509. case C_ptr:
  510. case C_int64:
  511. CAMLreturn(1);
  512. default:
  513. CAMLreturn(0);
  514. }
  515. }
  516. static swig_module_info *SWIG_Ocaml_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
  517. CAML_VALUE pointer;
  518. pointer = callback(*caml_named_value("swig_find_type_info"), caml_val_int(0));
  519. if (Is_block(pointer) && SWIG_Tag_val(pointer) == C_ptr) {
  520. return (swig_module_info *)(void *)(long)SWIG_Int64_val(SWIG_Field(pointer,0));
  521. }
  522. return 0;
  523. }
  524. static void SWIG_Ocaml_SetModule(swig_module_info *pointer) {
  525. CAML_VALUE mod_pointer;
  526. mod_pointer = caml_val_ptr(pointer, NULL);
  527. callback(*caml_named_value("swig_set_type_info"), mod_pointer);
  528. }
  529. #ifdef __cplusplus
  530. }
  531. #endif
  532. #undef value