From 9ef1a68a4428fbbba900a1c8ab162fe6fd6ce299 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?=
%typemap(in) (char *str, int len) {+
$1 = STR2CSTR($input);
$2 = (int) RSTRING($input)->len;
};
int count(char c, char *str, int len);
%typemap(in) (char *str, int len) {@@ -7134,7 +7134,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input
$1 = StringValuePtr($input);
$2 = (int) RSTRING($input)->len;
};
int count(char c, char *str, int len);
%module argv+
// This tells SWIG to treat char ** as a special case
%typemap(in) char ** {
/* Get the length of the array */
int size = RARRAY($input)->len;
int i;
$1 = (char **) malloc((size+1)*sizeof(char *));
/* Get the first element in memory */
VALUE *ptr = RARRAY($input)->ptr;
for (i=0; i < size; i++, ptr++)
/* Convert Ruby Object String to char* */
$1[i]= STR2CSTR(*ptr);
$1[i]=NULL; /* End of list */
}
// This cleans up the char ** array created before
// the function call
%typemap(freearg) char ** {
free((char *) $1);
}
// Now a test function
%inline %{
int print_args(char **argv) {
int i = 0;
while (argv[i]) {
printf("argv[%d] = %s\n", i,argv[i]);
i++;
}
return i;
}
%}
%module argv@@ -7795,7 +7795,7 @@ equivalents and store them in our local C arrays:
// This tells SWIG to treat char ** as a special case
%typemap(in) char ** {
/* Get the length of the array */
int size = RARRAY($input)->len;
int i;
$1 = (char **) malloc((size+1)*sizeof(char *));
/* Get the first element in memory */
VALUE *ptr = RARRAY($input)->ptr;
for (i=0; i < size; i++, ptr++)
/* Convert Ruby Object String to char* */
$1[i]= StringValuePtr(*ptr);
$1[i]=NULL; /* End of list */
}
// This cleans up the char ** array created before
// the function call
%typemap(freearg) char ** {
free((char *) $1);
}
// Now a test function
%inline %{
int print_args(char **argv) {
int i = 0;
while (argv[i]) {
printf("argv[%d] = %s\n", i,argv[i]);
i++;
}
return i;
}
%}
%typemap(in) (int nattributes, const char **names, const int *values)+
(VALUE keys_arr, int i, VALUE key, VALUE val) {
Check_Type($input, T_HASH);
$1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
$2 = NULL;
$3 = NULL;
if ($1 > 0) {
$2 = (char **) malloc($1*sizeof(char *));
$3 = (int *) malloc($1*sizeof(int));
keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
for (i = 0; i < $1; i++) {
key = rb_ary_entry(keys_arr, i);
val = rb_hash_aref($input, key);
Check_Type(key, T_STRING);
Check_Type(val, T_FIXNUM);
$2[i] = STR2CSTR(key);
$3[i] = NUM2INT(val);
}
}
}
%typemap(in) (int nattributes, const char **names, const int *values)diff --git a/Doc/Manual/SWIGDocumentation.html b/Doc/Manual/SWIGDocumentation.html index 85100fa..42f84c5 100644 --- a/Doc/Manual/SWIGDocumentation.html +++ b/Doc/Manual/SWIGDocumentation.html @@ -46771,7 +46771,7 @@ const int. In addition, the typemap system follows typedef example:
(VALUE keys_arr, int i, VALUE key, VALUE val) {
Check_Type($input, T_HASH);
$1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));
$2 = NULL;
$3 = NULL;
if ($1 > 0) {
$2 = (char **) malloc($1*sizeof(char *));
$3 = (int *) malloc($1*sizeof(int));
keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);
for (i = 0; i < $1; i++) {
key = rb_ary_entry(keys_arr, i);
val = rb_hash_aref($input, key);
Check_Type(key, T_STRING);
Check_Type(val, T_FIXNUM);
$2[i] = StringValuePtr(key);
$3[i] = NUM2INT(val);
}
}
}
%typemap(in) (char *str, int len) { -
$1 = STR2CSTR($input); +
$1 = StringValuePtr($input);
$2 = (int) RSTRING($input)->len;
};
@@ -47405,7 +47405,7 @@ style="font-family: monospace;">SWIG_AsVal_unsigned_SS_long(VALUE, unsigned long*)- char NUM2CHR(Numeric or String) SWIG_AsVal_char(VALUE, int*) char * STR2CSTR(String) + char * StringValuePtr(String) SWIG_AsCharPtrAndSize(VALUE, char*, size_t, int* alloc) @@ -47518,7 +47518,7 @@ printf(). char * rb_str2cstr(String, int*length)