cffi.swg 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* Define a C preprocessor symbol that can be used in interface files
  2. to distinguish between the SWIG language modules. */
  3. #define SWIG_CFFI
  4. /* Typespecs for basic types. */
  5. %typemap(cin) void ":void";
  6. %typemap(cin) char ":char";
  7. %typemap(cin) char * ":string";
  8. %typemap(cin) unsigned char ":unsigned-char";
  9. %typemap(cin) signed char ":char";
  10. %typemap(cin) short ":short";
  11. %typemap(cin) signed short ":short";
  12. %typemap(cin) unsigned short ":unsigned-short";
  13. %typemap(cin) int ":int";
  14. %typemap(cin) signed int ":int";
  15. %typemap(cin) unsigned int ":unsigned-int";
  16. %typemap(cin) long ":long";
  17. %typemap(cin) signed long ":long";
  18. %typemap(cin) unsigned long ":unsigned-long";
  19. %typemap(cin) long long ":long-long";
  20. %typemap(cin) signed long long ":long-long";
  21. %typemap(cin) unsigned long long ":unsigned-long-long";
  22. %typemap(cin) float ":float";
  23. %typemap(cin) double ":double";
  24. %typemap(cin) SWIGTYPE ":pointer";
  25. %typemap(cout) void ":void";
  26. %typemap(cout) char ":char";
  27. %typemap(cout) char * ":string";
  28. %typemap(cout) unsigned char ":unsigned-char";
  29. %typemap(cout) signed char ":char";
  30. %typemap(cout) short ":short";
  31. %typemap(cout) signed short ":short";
  32. %typemap(cout) unsigned short ":unsigned-short";
  33. %typemap(cout) int ":int";
  34. %typemap(cout) signed int ":int";
  35. %typemap(cout) unsigned int ":unsigned-int";
  36. %typemap(cout) long ":long";
  37. %typemap(cout) signed long ":long";
  38. %typemap(cout) unsigned long ":unsigned-long";
  39. %typemap(cout) long long ":long-long";
  40. %typemap(cout) signed long long ":long-long";
  41. %typemap(cout) unsigned long long ":unsigned-long-long";
  42. %typemap(cout) float ":float";
  43. %typemap(cout) double ":double";
  44. %typemap(cout) SWIGTYPE ":pointer";
  45. %typemap(ctype) bool "int";
  46. %typemap(ctype) char, unsigned char, signed char,
  47. short, signed short, unsigned short,
  48. int, signed int, unsigned int,
  49. long, signed long, unsigned long,
  50. float, double, long double, char *, void *, void,
  51. enum SWIGTYPE, SWIGTYPE *,
  52. SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1_ltype";
  53. %typemap(ctype) SWIGTYPE "$&1_type";
  54. %typemap(in) bool "$1 = (bool)$input;";
  55. %typemap(in) char, unsigned char, signed char,
  56. short, signed short, unsigned short,
  57. int, signed int, unsigned int,
  58. long, signed long, unsigned long,
  59. float, double, long double, char *, void *, void,
  60. enum SWIGTYPE, SWIGTYPE *,
  61. SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1 = $input;";
  62. %typemap(in) SWIGTYPE "$1 = *$input;";
  63. %typemap(out) void "";
  64. %typemap(out) bool "$result = (int)$1;";
  65. %typemap(out) char, unsigned char, signed char,
  66. short, signed short, unsigned short,
  67. int, signed int, unsigned int,
  68. long, signed long, unsigned long,
  69. float, double, long double, char *, void *,
  70. enum SWIGTYPE, SWIGTYPE *,
  71. SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;";
  72. #ifdef __cplusplus
  73. %typemap(out) SWIGTYPE "$result = new $1_type($1);";
  74. #else
  75. %typemap(out) SWIGTYPE {
  76. $result = ($&1_ltype) malloc(sizeof($1_type));
  77. memmove($result, &$1, sizeof($1_type));
  78. }
  79. #endif
  80. %typecheck(SWIG_TYPECHECK_BOOL) bool { $1 = 1; };
  81. %typecheck(SWIG_TYPECHECK_CHAR) char { $1 = 1; };
  82. %typecheck(SWIG_TYPECHECK_FLOAT) float { $1 = 1; };
  83. %typecheck(SWIG_TYPECHECK_DOUBLE) double { $1 = 1; };
  84. %typecheck(SWIG_TYPECHECK_STRING) char * { $1 = 1; };
  85. %typecheck(SWIG_TYPECHECK_INTEGER)
  86. unsigned char, signed char,
  87. short, signed short, unsigned short,
  88. int, signed int, unsigned int,
  89. long, signed long, unsigned long,
  90. enum SWIGTYPE { $1 = 1; };
  91. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&,
  92. SWIGTYPE[ANY], SWIGTYPE { $1 = 1; };
  93. /* This maps C/C++ types to Lisp classes for overload dispatch */
  94. %typemap(lisptype) bool "cl:boolean";
  95. %typemap(lisptype) char "cl:character";
  96. %typemap(lisptype) unsigned char "cl:integer";
  97. %typemap(lisptype) signed char "cl:integer";
  98. %typemap(lispclass) bool "t";
  99. %typemap(lispclass) char "cl:character";
  100. %typemap(lispclass) unsigned char, signed char,
  101. short, signed short, unsigned short,
  102. int, signed int, unsigned int,
  103. long, signed long, unsigned long,
  104. enum SWIGTYPE "cl:integer";
  105. /* CLOS methods can't be specialized on single-float or double-float */
  106. %typemap(lispclass) float "cl:number";
  107. %typemap(lispclass) double "cl:number";
  108. %typemap(lispclass) char * "cl:string";
  109. /* Array reference typemaps */
  110. %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
  111. %apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) }
  112. /* const pointers */
  113. %apply SWIGTYPE * { SWIGTYPE *const }
  114. %{
  115. #ifdef __cplusplus
  116. # define EXTERN extern "C"
  117. #else
  118. # define EXTERN extern
  119. #endif
  120. #define EXPORT EXTERN SWIGEXPORT
  121. #include <string.h>
  122. %}
  123. %insert("swiglisp") %{
  124. ;;;SWIG wrapper code starts here
  125. (cl:defmacro defanonenum (cl:&body enums)
  126. "Converts anonymous enums to defconstants."
  127. `(cl:progn ,@(cl:loop for value in enums
  128. for index = 0 then (cl:1+ index)
  129. when (cl:listp value) do (cl:setf index (cl:second value)
  130. value (cl:first value))
  131. collect `(cl:defconstant ,value ,index))))
  132. (cl:eval-when (:compile-toplevel :load-toplevel)
  133. (cl:unless (cl:fboundp 'swig-lispify)
  134. (cl:defun swig-lispify (name flag cl:&optional (package cl:*package*))
  135. (cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst)))
  136. (cl:cond
  137. ((cl:null lst)
  138. rest)
  139. ((cl:upper-case-p c)
  140. (helper (cl:cdr lst) 'upper
  141. (cl:case last
  142. ((lower digit) (cl:list* c #\- rest))
  143. (cl:t (cl:cons c rest)))))
  144. ((cl:lower-case-p c)
  145. (helper (cl:cdr lst) 'lower (cl:cons (cl:char-upcase c) rest)))
  146. ((cl:digit-char-p c)
  147. (helper (cl:cdr lst) 'digit
  148. (cl:case last
  149. ((upper lower) (cl:list* c #\- rest))
  150. (cl:t (cl:cons c rest)))))
  151. ((cl:char-equal c #\_)
  152. (helper (cl:cdr lst) '_ (cl:cons #\- rest)))
  153. (cl:t
  154. (cl:error "Invalid character: ~A" c)))))
  155. (cl:let ((fix (cl:case flag
  156. ((constant enumvalue) "+")
  157. (variable "*")
  158. (cl:t ""))))
  159. (cl:intern
  160. (cl:concatenate
  161. 'cl:string
  162. fix
  163. (cl:nreverse (helper (cl:concatenate 'cl:list name) cl:nil cl:nil))
  164. fix)
  165. package))))))
  166. ;;;SWIG wrapper code ends here
  167. %}
  168. #ifdef __cplusplus
  169. %typemap(out) SWIGTYPE "$result = new $1_type($1);";
  170. #else
  171. %typemap(out) SWIGTYPE {
  172. $result = ($&1_ltype) malloc(sizeof($1_type));
  173. memmove($result, &$1, sizeof($1_type));
  174. }
  175. #endif
  176. //////////////////////////////////////////////////////////////
  177. /* name conversion for overloaded operators. */
  178. #ifdef __cplusplus
  179. %rename(__add__) *::operator+;
  180. %rename(__pos__) *::operator+();
  181. %rename(__pos__) *::operator+() const;
  182. %rename(__sub__) *::operator-;
  183. %rename(__neg__) *::operator-() const;
  184. %rename(__neg__) *::operator-();
  185. %rename(__mul__) *::operator*;
  186. %rename(__deref__) *::operator*();
  187. %rename(__deref__) *::operator*() const;
  188. %rename(__div__) *::operator/;
  189. %rename(__mod__) *::operator%;
  190. %rename(__logxor__) *::operator^;
  191. %rename(__logand__) *::operator&;
  192. %rename(__logior__) *::operator|;
  193. %rename(__lognot__) *::operator~();
  194. %rename(__lognot__) *::operator~() const;
  195. %rename(__not__) *::operator!();
  196. %rename(__not__) *::operator!() const;
  197. %rename(__assign__) *::operator=;
  198. %rename(__add_assign__) *::operator+=;
  199. %rename(__sub_assign__) *::operator-=;
  200. %rename(__mul_assign__) *::operator*=;
  201. %rename(__div_assign__) *::operator/=;
  202. %rename(__mod_assign__) *::operator%=;
  203. %rename(__logxor_assign__) *::operator^=;
  204. %rename(__logand_assign__) *::operator&=;
  205. %rename(__logior_assign__) *::operator|=;
  206. %rename(__lshift__) *::operator<<;
  207. %rename(__lshift_assign__) *::operator<<=;
  208. %rename(__rshift__) *::operator>>;
  209. %rename(__rshift_assign__) *::operator>>=;
  210. %rename(__eq__) *::operator==;
  211. %rename(__ne__) *::operator!=;
  212. %rename(__lt__) *::operator<;
  213. %rename(__gt__) *::operator>;
  214. %rename(__lte__) *::operator<=;
  215. %rename(__gte__) *::operator>=;
  216. %rename(__and__) *::operator&&;
  217. %rename(__or__) *::operator||;
  218. %rename(__preincr__) *::operator++();
  219. %rename(__postincr__) *::operator++(int);
  220. %rename(__predecr__) *::operator--();
  221. %rename(__postdecr__) *::operator--(int);
  222. %rename(__comma__) *::operator,();
  223. %rename(__comma__) *::operator,() const;
  224. %rename(__member_ref__) *::operator->;
  225. %rename(__member_func_ref__) *::operator->*;
  226. %rename(__funcall__) *::operator();
  227. %rename(__aref__) *::operator[];
  228. #endif
  229. %{
  230. #ifdef __cplusplus
  231. # define EXTERN extern "C"
  232. #else
  233. # define EXTERN extern
  234. #endif
  235. #define EXPORT EXTERN SWIGEXPORT
  236. #include <string.h>
  237. #include <stdlib.h>
  238. %}