Replaced all occurrences of the deprecated STR2CSTR() in Ruby code with

the new StringValuePtr().


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4682 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Logan Johnson 2003-04-15 17:14:18 +00:00
commit 961b144d29
5 changed files with 19 additions and 14 deletions

View file

@ -39,8 +39,8 @@
%typemap(in) char "$1 = NUM2CHR($input);";
%typemap(in) float, double "$1 = ($1_ltype) NUM2DBL($input);";
%typemap(in) bool "$1 = RTEST($input);";
%typemap(in) char * "$1 = STR2CSTR($input);";
%typemap(in) char [ANY] "$1 = STR2CSTR($input);";
%typemap(in) char * "$1 = StringValuePtr($input);";
%typemap(in) char [ANY] "$1 = StringValuePtr($input);";
%typemap(in) enum SWIGTYPE "$1 = ($1_ltype) NUM2INT($input);";
/* Long long */
@ -119,7 +119,7 @@
$1 = &temp;";
%typemap(in) const char &(char temp) {
char *stemp = STR2CSTR($input);
char *stemp = StringValuePtr($input);
temp = *stemp;
$1 = &temp;
}
@ -238,32 +238,32 @@
/* A string */
#ifdef __cplusplus
%typemap(varin) char * {
char *temp = (char *) STR2CSTR($input);
char *temp = (char *) StringValuePtr($input);
if ($1) delete [] $1;
$1 = ($type) new char[strlen(temp)+1];
strcpy((char*)$1,temp);
}
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
char *temp = (char *) STR2CSTR($input);
char *temp = (char *) StringValuePtr($input);
$1 = ($type) new char[strlen(temp)+1];
strcpy((char*)$1,temp);
}
#else
%typemap(varin) char * {
char *temp = (char *) STR2CSTR($input);
char *temp = (char *) StringValuePtr($input);
if ($1) free((char*) $1);
$1 = ($type) malloc(strlen(temp)+1);
strcpy((char*)$1,temp);
}
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
char *temp = (char *) STR2CSTR($input);
char *temp = (char *) StringValuePtr($input);
$1 = ($type) malloc(strlen(temp)+1);
strcpy((char*)$1,temp);
}
#endif
%typemap(varin) char [ANY] "strncpy($1,STR2CSTR($input),$1_dim0);";
%typemap(varin) char [ANY] "strncpy($1,StringValuePtr($input),$1_dim0);";
%typemap(varin) enum SWIGTYPE "$1 = ($1_type) NUM2INT($input);";
/* Typemaps for pointers. Note: the SWIG run-time type checker works
@ -389,7 +389,7 @@ typedef unsigned long VALUE;
* ------------------------------------------------------------ */
%typemap(in) (char *STRING, int LENGTH) {
$1 = ($1_ltype) STR2CSTR($input);
$1 = ($1_ltype) StringValuePtr($input);
$2 = ($2_ltype) RSTRING($input)->len;
}

View file

@ -72,7 +72,7 @@ SWIGRUNTIME(char *)
SWIG_MangleStr(VALUE obj)
{
VALUE stype = rb_iv_get(obj, "__swigtype__");
return STR2CSTR(stype);
return StringValuePtr(stype);
}
/* Convert a pointer value */
@ -186,7 +186,7 @@ SWIG_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags)
char *c;
if (TYPE(obj) != T_STRING) goto type_error;
c = STR2CSTR(obj);
c = StringValuePtr(obj);
/* Pointer values must start with leading underscore */
if (*c != '_') goto type_error;
c++;

View file

@ -38,6 +38,11 @@
#endif
#endif
/* Ruby 1.8 deprecates STR2CSTR() in favor of StringValuePtr() */
#ifndef StringValuePtr
#define StringValuePtr(x) STR2CSTR((x))
#endif
/*
* Need to be very careful about how these macros are defined, especially
* when compiling C++ code or C code with an ANSI C compiler.

View file

@ -27,7 +27,7 @@ bool SWIG_STRING_P(VALUE x) {
return TYPE(x) == T_STRING;
}
std::string SWIG_RB2STR(VALUE x) {
return std::string(STR2CSTR(x));
return std::string(StringValuePtr(x));
}
VALUE SWIG_STR2RB(const std::string& s) {
return rb_str_new2(s.c_str());

View file

@ -30,7 +30,7 @@ namespace std {
%typemap(in) string {
if (TYPE($input) == T_STRING) {
$1 = std::string(STR2CSTR($input));
$1 = std::string(StringValuePtr($input));
} else {
SWIG_exception(SWIG_TypeError, "not a string");
}
@ -38,7 +38,7 @@ namespace std {
%typemap(in) const string & (std::string temp) {
if (TYPE($input) == T_STRING) {
temp = std::string(STR2CSTR($input));
temp = std::string(StringValuePtr($input));
$1 = &temp;
} else {
SWIG_exception(SWIG_TypeError, "not a string");