comparison lib/swig/swigwin-2.0.11/Lib/cdata.i @ 1899:b3009adc0e2f

Adding swig, gitignore, hgignore
author Nomad
date Mon, 21 Oct 2013 10:42:27 +0200
parents
children
comparison
equal deleted inserted replaced
1867:eb580660bbbb 1899:b3009adc0e2f
1 /* -----------------------------------------------------------------------------
2 * cdata.i
3 *
4 * SWIG library file containing macros for manipulating raw C data as strings.
5 * ----------------------------------------------------------------------------- */
6
7 %{
8 typedef struct SWIGCDATA {
9 char *data;
10 int len;
11 } SWIGCDATA;
12 %}
13
14 /* -----------------------------------------------------------------------------
15 * Typemaps for returning binary data
16 * ----------------------------------------------------------------------------- */
17
18 #if SWIGGUILE
19 %typemap(out) SWIGCDATA {
20 $result = scm_from_locale_stringn($1.data,$1.len);
21 }
22 %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
23 #elif SWIGCHICKEN
24 %typemap(out) SWIGCDATA {
25 C_word *string_space = C_alloc(C_SIZEOF_STRING($1.len));
26 $result = C_string(&string_space, $1.len, $1.data);
27 }
28 %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
29 #elif SWIGPHP
30 %typemap(out) SWIGCDATA {
31 ZVAL_STRINGL($result, $1.data, $1.len, 1);
32 }
33 %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
34 #else
35 %echo "cdata.i module not supported."
36 #endif
37
38
39 /* -----------------------------------------------------------------------------
40 * %cdata(TYPE [, NAME])
41 *
42 * Convert raw C data to a binary string.
43 * ----------------------------------------------------------------------------- */
44
45 %define %cdata(TYPE,NAME...)
46
47 %insert("header") {
48 #if #NAME == ""
49 static SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements) {
50 #else
51 static SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements) {
52 #endif
53 SWIGCDATA d;
54 d.data = (char *) ptr;
55 #if #TYPE != "void"
56 d.len = nelements*sizeof(TYPE);
57 #else
58 d.len = nelements;
59 #endif
60 return d;
61 }
62 }
63
64 %typemap(default) int nelements "$1 = 1;"
65
66 #if #NAME == ""
67 SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements);
68 #else
69 SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
70 #endif
71 %enddef
72
73 %typemap(default) int nelements;
74
75 %rename(cdata) ::cdata_void(void *ptr, int nelements);
76
77 %cdata(void);
78
79 /* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
80 void memmove(void *data, const char *s); */
81 void memmove(void *data, const void *indata, int inlen);