diff --git a/CHANGES.current b/CHANGES.current index bdb9c682c..6256f0469 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== +2012-12-14: kkaempf + [Ruby] Apply patch 3530439 and finally replace all occurences of the STR2CSTR() macro + with StringValuePtr(). STR2CSTR was deprecated since years and got removed in Ruby 1.9 + 2012-12-14: kkaempf [Ruby] Applied patches #3530442 and 3530443 to adapt compile and runtime include pathes to match Ruby 1.9+ diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html index 969de7a3d..47cf4f303 100644 --- a/Doc/Manual/Ruby.html +++ b/Doc/Manual/Ruby.html @@ -4926,7 +4926,7 @@ arguments. For example:

-
%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) {
$1 = StringValuePtr($input);
$2 = (int) RSTRING($input)->len;
};

int count(char c, char *str, int len);
@@ -7135,7 +7135,7 @@ Ruby_Format_TypeError( "$1_name", "$1_type","$symname", $argnum, $input - char * STR2CSTR(String) + char * StringValuePtr(String) SWIG_AsCharPtrAndSize(VALUE, char*, size_t, int* alloc) @@ -7518,7 +7518,7 @@ Array instance to be used as a char ** object.

-
%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

// 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;
}
%}

@@ -7796,7 +7796,7 @@ equivalents and store them in our local C arrays:

-
%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)
(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);

}
}
}
diff --git a/Examples/ruby/hashargs/example.i b/Examples/ruby/hashargs/example.i index 159bbd32a..10e209e5f 100644 --- a/Examples/ruby/hashargs/example.i +++ b/Examples/ruby/hashargs/example.i @@ -14,7 +14,7 @@ val = rb_hash_aref($input, key); Check_Type(key, T_STRING); Check_Type(val, T_FIXNUM); - $2[i] = STR2CSTR(key); + $2[i] = StringValuePtr(key); $3[i] = NUM2INT(val); } } diff --git a/Examples/ruby/multimap/example.i b/Examples/ruby/multimap/example.i index f68422a18..34f0b899b 100644 --- a/Examples/ruby/multimap/example.i +++ b/Examples/ruby/multimap/example.i @@ -31,7 +31,7 @@ extern int gcd(int x, int y); free($2); SWIG_exception(SWIG_ValueError, "List items must be strings"); } - $2[i] = STR2CSTR(s); + $2[i] = StringValuePtr(s); } $2[i] = 0; } @@ -46,7 +46,7 @@ extern int gcdmain(int argc, char *argv[]); if (TYPE($input) != T_STRING) { SWIG_exception(SWIG_ValueError, "Expected a string"); } - $1 = STR2CSTR($input); + $1 = StringValuePtr($input); $2 = RSTRING_LEN($input); } @@ -60,7 +60,7 @@ extern int count(char *bytes, int len, char c); if (TYPE($input) != T_STRING) { SWIG_exception(SWIG_ValueError,"Expected a string"); } - temp = STR2CSTR($input); + temp = StringValuePtr($input); $2 = RSTRING_LEN($input); $1 = (char *) malloc($2+1); memmove($1,temp,$2); diff --git a/Examples/test-suite/memberin1.i b/Examples/test-suite/memberin1.i index 920323044..ece489e3d 100644 --- a/Examples/test-suite/memberin1.i +++ b/Examples/test-suite/memberin1.i @@ -47,7 +47,7 @@ public: #ifdef SWIGRUBY %typemap(in) String { Check_Type($input, T_STRING); - $1 = String(STR2CSTR($input)); + $1 = String(StringValuePtr($input)); } #endif diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index f25f88574..8ead78c6c 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -100,7 +100,7 @@ namespace test { #endif #ifdef SWIGRUBY %typemap(in) string_class * { - $1 = new string_class(STR2CSTR($input)); + $1 = new string_class(StringValuePtr($input)); } %typemap(freearg) string_class * { delete $1; diff --git a/Lib/ruby/argcargv.i b/Lib/ruby/argcargv.i index ae1f6bbd3..fc0bc406a 100644 --- a/Lib/ruby/argcargv.i +++ b/Lib/ruby/argcargv.i @@ -30,7 +30,7 @@ $2 = (char **) malloc((size+1)*sizeof(char *)); VALUE *ptr = RARRAY_PTR($input); for (i=0; i < size; i++, ptr++) { - $2[i]= STR2CSTR(*ptr); + $2[i]= StringValuePtr(*ptr); } $2[i]=NULL; } else { diff --git a/Lib/ruby/rubystrings.swg b/Lib/ruby/rubystrings.swg index e6b92ef58..3adf0008b 100644 --- a/Lib/ruby/rubystrings.swg +++ b/Lib/ruby/rubystrings.swg @@ -7,11 +7,7 @@ SWIGINTERN int SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc) { if (TYPE(obj) == T_STRING) { - %#if defined(StringValuePtr) char *cstr = StringValuePtr(obj); - %#else - char *cstr = STR2CSTR(obj); - %#endif size_t size = RSTRING_LEN(obj) + 1; if (cptr) { if (alloc) {