/* --- Input Values --- */
%typemap(in) char * "$1 = StringValuePtr($input);";
%typemap(in) char [ANY] "$1 = StringValuePtr($input);";
/* ------------------------------------------------------------
* ------------------------------------------------------------ */
%typemap(in) (int LENGTH, char *STRING) {
$1 = ($1_ltype) StringValueLen($input);
$2 = ($2_ltype) StringValuePtr($input);
%typemap(in) (char *STRING, int LENGTH) {
$1 = ($1_ltype) StringValuePtr($input);
$2 = ($2_ltype) StringValueLen($input);
/* --- Output typemaps --- */
%typemap(out) char "$result = rb_str_new(&$1,1);";
%typemap(out) const char & "$result = rb_str_new($1, 1);";
%typemap(out) char * "$result = rb_str_new2($1);";
/* Special typemap for character array return values */
%typemap(out) char [ANY], const char [ANY] "$result = rb_str_new2($1);";
/* --- Variable Input --- */
char *temp = (char *) StringValuePtr($input);
$1 = ($type) new char[strlen(temp)+1];
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
char *temp = (char *) StringValuePtr($input);
$1 = ($type) new char[strlen(temp)+1];
char *temp = (char *) StringValuePtr($input);
if ($1) free((char*) $1);
$1 = ($type) malloc(strlen(temp)+1);
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
char *temp = (char *) StringValuePtr($input);
$1 = ($type) malloc(strlen(temp)+1);
/* Special case for string array variables */
warning="462:Unable to set variable of type char []") char[]
rb_raise(rb_eTypeError, "C/C++ variable '$name' is read-only.");
%typemap(varin) char[ANY] "strncpy($1,StringValuePtr($input),$1_dim0);";
/* --- Variable Output --- */
%typemap(varout) char "$result = rb_str_new(&$1,1);";
%typemap(varout) char * "$result = rb_str_new2($1);";
/* Special typemap for character array return values */
%typemap(varout) char [ANY], const char [ANY] "$result = rb_str_new2($1);";
%typemap(constant) char {
rb_define_const($module,"$symname", rb_str_new(&temp,1));
%typemap(constant) char *
"rb_define_const($module,\"$symname\", rb_str_new2($1));";
/* directorin typemaps */
%typemap(directorin) char * "$input = rb_str_new2($1);";
/* directorout typemaps */
%typemap(directorout) char * "$result = STR2CSTR($1);";
%typemap(directorout) const char * "$result = STR2CSTR($1);";
/* ------------------------------------------------------------
* ------------------------------------------------------------ */
%typecheck(SWIG_TYPECHECK_CHAR) char {
$1 = (TYPE($input) == T_STRING && (RSTRING($input)->len == 1)) ? 1 : 0;
%typecheck(SWIG_TYPECHECK_STRING) char * {
$1 = (TYPE($input) == T_STRING) ? 1 : 0;
/* ------------------------------------------------------------
* ------------------------------------------------------------ */
%typemap(throws) char * {
rb_raise(rb_eRuntimeError, $1);