1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/* -----------------------------------------------------------------------------
* cdata.i
*
* Author(s): David Beazley (beazley@cs.uchicago.edu)
*
* This library file contains macros for manipulating raw C data as strings.
*
* $Header$
* ----------------------------------------------------------------------------- */
%{
typedef struct SWIGCDATA {
char *data;
int len;
} SWIGCDATA;
%}
/* -----------------------------------------------------------------------------
* Typemaps for returning binary data
* ----------------------------------------------------------------------------- */
#if SWIGGUILE
%typemap(out) SWIGCDATA {
$result = gh_str2scm($1.data,$1.len);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#elif SWIGCHICKEN
%typemap(out) SWIGCDATA {
C_word *string_space = C_alloc(C_SIZEOF_STRING($1.len));
$result = C_string(&string_space, $1.len, $1.data);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
#else
%echo "cdata.i module not supported."
#endif
/* -----------------------------------------------------------------------------
* %cdata(TYPE [, NAME])
*
* Convert raw C data to a binary string.
* ----------------------------------------------------------------------------- */
%define %cdata(TYPE,NAME...)
%insert("header") {
#if #NAME == ""
static SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements) {
#else
static SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements) {
#endif
SWIGCDATA d;
d.data = (char *) ptr;
#if #TYPE != "void"
d.len = nelements*sizeof(TYPE);
#else
d.len = nelements;
#endif
return d;
}
}
%typemap(default) int nelements "$1 = 1;"
#if #NAME == ""
SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements);
#else
SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
#endif
%enddef
%typemap(default) int nelements;
%rename(cdata) ::cdata_void(void *ptr, int nelements);
%cdata(void);
/* Memory move function */
void memmove(void *data, const void *indata, int inlen);
|