Additional fixes for Ruby 1.8 compatibility.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4688 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3acd792de3
commit
7cfddcffc7
3 changed files with 34 additions and 19 deletions
|
|
@ -390,7 +390,7 @@ typedef unsigned long VALUE;
|
|||
|
||||
%typemap(in) (char *STRING, int LENGTH) {
|
||||
$1 = ($1_ltype) StringValuePtr($input);
|
||||
$2 = ($2_ltype) RSTRING($input)->len;
|
||||
$2 = ($2_ltype) StringValueLen($input);
|
||||
}
|
||||
|
||||
/* Some ANSI C typemaps */
|
||||
|
|
|
|||
|
|
@ -38,11 +38,6 @@
|
|||
#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.
|
||||
|
|
@ -80,3 +75,28 @@ typedef struct {
|
|||
void (*mark)(void *);
|
||||
void (*destroy)(void *);
|
||||
} swig_class;
|
||||
|
||||
/* Don't use for expressions have side effect */
|
||||
#ifndef RB_STRING_VALUE
|
||||
#define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
|
||||
#endif
|
||||
#ifndef StringValue
|
||||
#define StringValue(s) RB_STRING_VALUE(s)
|
||||
#endif
|
||||
#ifndef StringValuePtr
|
||||
#define StringValuePtr(s) RSTRING(RB_STRING_VALUE(s))->ptr
|
||||
#endif
|
||||
#ifndef StringValueLen
|
||||
#define StringValueLen(s) RSTRING(RB_STRING_VALUE(s))->len
|
||||
#endif
|
||||
#ifndef SafeStringValue
|
||||
#define SafeStringValue(v) do {\
|
||||
StringValue(v);\
|
||||
rb_check_safe_str(v);\
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_RB_DEFINE_ALLOC_FUNC
|
||||
#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF(klass), "new")
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -458,8 +458,8 @@ public:
|
|||
|
||||
void create_command(Node *n, const String_or_char *iname) {
|
||||
|
||||
String *alloc_func_name = Swig_name_wrapper(iname);
|
||||
String *wname = Swig_name_wrapper(iname);
|
||||
String *wname2 = Swig_name_wrapper(iname);
|
||||
if (CPlusPlus) {
|
||||
Insert(wname,0,"VALUEFUNC(");
|
||||
Append(wname,")");
|
||||
|
|
@ -479,13 +479,11 @@ public:
|
|||
iname, "\", ", wname, ", -1);\n", NIL);
|
||||
break;
|
||||
case CONSTRUCTOR_ALLOCATE:
|
||||
Printv(s, "#ifdef HAVE_RB_DEFINE_ALLOC_FUNC\n", NIL);
|
||||
Printv(s, tab4, "rb_define_alloc_func(", klass->vname,
|
||||
", ", wname2, ");\n", NIL);
|
||||
Printv(s, "#else\n", NIL);
|
||||
Printv(s, tab4, "rb_define_singleton_method(", klass->vname,
|
||||
", \"new\", ", wname, ", -1);\n", NIL);
|
||||
Printv(s, "#endif\n", NIL);
|
||||
Printf(s, "#ifdef HAVE_RB_DEFINE_ALLOC_FUNC\n");
|
||||
Printv(s, tab4, "rb_define_alloc_func(", klass->vname, ", ", alloc_func_name, ");\n", NIL);
|
||||
Printf(s, "#else\n");
|
||||
Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"new\", ", wname, ", -1);\n", NIL);
|
||||
Printf(s, "#endif\n");
|
||||
Replaceall(klass->init,"$allocator", s);
|
||||
break;
|
||||
case CONSTRUCTOR_INITIALIZE:
|
||||
|
|
@ -516,7 +514,7 @@ public:
|
|||
Delete(temp);
|
||||
Delete(s);
|
||||
Delete(wname);
|
||||
Delete(wname2);
|
||||
Delete(alloc_func_name);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
|
|
@ -1342,10 +1340,7 @@ public:
|
|||
Printv(f_header, klass->header,NIL);
|
||||
|
||||
String *s = NewString("");
|
||||
Printv(s, "#ifndef HAVE_RB_DEFINE_ALLOC_FUNC\n", NIL);
|
||||
Printv(s, tab4, "rb_undef_method(CLASS_OF(", klass->vname,
|
||||
"), \"new\");\n", NIL);
|
||||
Printv(s, "#endif\n", NIL);
|
||||
Printv(s, tab4, "rb_undef_alloc_func(", klass->vname, ");\n", NIL);
|
||||
Replaceall(klass->init,"$allocator", s);
|
||||
Replaceall(klass->init,"$initializer", "");
|
||||
Replaceall(klass->init,"$super", "rb_cObject");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue