1/* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
4 *
5 * const.i
6 *
7 * Typemaps for constants
8 * ----------------------------------------------------------------------------- */
9
10%typemap(consttab) int,
11                   unsigned int,
12                   short,
13                   unsigned short,
14                   long,
15                   unsigned long,
16                   unsigned char,
17                   signed char,
18                   bool,
19                   enum SWIGTYPE
20  "SWIG_LONG_CONSTANT($symname, $value);";
21
22%typemap(consttab) float,
23                   double
24  "SWIG_DOUBLE_CONSTANT($symname, $value);";
25
26%typemap(consttab) char
27  "SWIG_CHAR_CONSTANT($symname, $value);";
28
29%typemap(consttab) char *,
30                   const char *,
31                   char [],
32                   const char []
33  "SWIG_STRING_CONSTANT($symname, $value);";
34
35%typemap(consttab) SWIGTYPE *,
36                   SWIGTYPE &,
37                   SWIGTYPE [] {
38  /* This actually registers it as a global variable and constant.  I don't
39   * like it, but I can't figure out the zend_constant code... */
40  zval *z_var;
41  MAKE_STD_ZVAL(z_var);
42  SWIG_SetPointerZval(z_var, (void*)$value, $1_descriptor, 0);
43  /* zend_hash_add(&EG(symbol_table), "$1", sizeof("$1"), (void *)&z_var,sizeof(zval *), NULL); */
44  zend_constant c;
45  c.value = *z_var;
46  zval_copy_ctor(&c.value);
47  size_t len = sizeof("$1") - 1;
48  c.name = zend_strndup("$1", len);
49  c.name_len = len+1;
50  c.flags = CONST_CS | CONST_PERSISTENT;
51  c.module_number = module_number;
52  zend_register_constant( &c TSRMLS_CC );
53}
54