PageRenderTime 20ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/go/cdata.i

#
Swig | 64 lines | 40 code | 11 blank | 13 comment | 0 complexity | a610a2dcaeb8751b2fe4571553f0e38e MD5 | raw file
 1/* -----------------------------------------------------------------------------
 2 * cdata.i
 3 *
 4 * SWIG library file containing macros for manipulating raw C data as strings.
 5 * ----------------------------------------------------------------------------- */
 6
 7%{
 8typedef struct SWIGCDATA {
 9    char *data;
10    int   len;
11} SWIGCDATA;
12%}
13
14%typemap(gotype) SWIGCDATA %{ []byte %}
15%typemap(out) SWIGCDATA %{
16  $result.data = (char*)_swig_goallocate($1.len);
17  memcpy($result.data, $1.data, $1.len);
18  $result.len = (int)$1.len;
19%}
20
21/* -----------------------------------------------------------------------------
22 * %cdata(TYPE [, NAME]) 
23 *
24 * Convert raw C data to a binary string.
25 * ----------------------------------------------------------------------------- */
26
27%define %cdata(TYPE,NAME...)
28
29%insert("header") {
30#if #NAME == ""
31static SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements) {
32#else
33static SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements) {
34#endif
35   SWIGCDATA d;
36   d.data = (char *) ptr;
37#if #TYPE != "void"
38   d.len  = nelements*sizeof(TYPE);
39#else
40   d.len  = nelements;
41#endif
42   return d;
43}
44}
45
46%typemap(default) int nelements "$1 = 1;"
47
48#if #NAME == ""
49SWIGCDATA cdata_##TYPE(TYPE *ptr, int nelements);
50#else
51SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
52#endif
53%enddef
54
55%typemap(default) int nelements;
56
57%rename(cdata) ::cdata_void(void *ptr, int nelements);
58
59%cdata(void);
60
61/* Memory move function. Due to multi-argument typemaps this appears
62   to be wrapped as
63   void memmove(void *data, const char *s); */
64void memmove(void *data, char *indata, int inlen);