Ruby module changed to use pointer object instead of mangled string.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@690 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3c1ffc640e
commit
aa1f1ac3c2
6 changed files with 229 additions and 485 deletions
|
|
@ -1,15 +1,3 @@
|
||||||
//
|
|
||||||
// SWIG pointer conversion and utility library for Ruby
|
|
||||||
//
|
|
||||||
// $Header$
|
|
||||||
//
|
|
||||||
// Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
|
||||||
// Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
|
||||||
//
|
|
||||||
// Masaki Fukushima
|
|
||||||
//
|
|
||||||
// This file is originally derived from python/ptrlang.i
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// SWIG pointer conversion and utility library
|
// SWIG pointer conversion and utility library
|
||||||
//
|
//
|
||||||
|
|
@ -20,9 +8,37 @@
|
||||||
// by the file ../pointer.i
|
// by the file ../pointer.i
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/* Pointer library specific types */
|
||||||
|
|
||||||
|
static _swig_type_info _swig_pointer_int_p[] = {{"_p_int",0},{"_p_int",0},{0}};
|
||||||
|
static _swig_type_info _swig_pointer_short_p[] = {{"_p_short",0},{"_p_short",0},{0}};
|
||||||
|
static _swig_type_info _swig_pointer_long_p[] = {{"_p_long",0},{"_p_long",0},{0}};
|
||||||
|
static _swig_type_info _swig_pointer_float_p[] = {{"_p_float",0},{"_p_float",0},{0}};
|
||||||
|
static _swig_type_info _swig_pointer_double_p[] = {{"_p_double",0},{"_p_double",0},{0}};
|
||||||
|
static _swig_type_info _swig_pointer_char_p[] = {{"_p_char",0},{"_p_char",0},{0}};
|
||||||
|
static _swig_type_info _swig_pointer_char_pp[] = {{"_pp_char",0},{"_pp_char",0},{0}};
|
||||||
|
|
||||||
|
static _swig_type_info *_swig_pointer_types[] = {
|
||||||
|
_swig_pointer_int_p,
|
||||||
|
_swig_pointer_short_p,
|
||||||
|
_swig_pointer_long_p,
|
||||||
|
_swig_pointer_float_p,
|
||||||
|
_swig_pointer_double_p,
|
||||||
|
_swig_pointer_char_p,
|
||||||
|
_swig_pointer_char_pp,
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SWIG_POINTER_int_p _swig_pointer_types[0]
|
||||||
|
#define SWIG_POINTER_short_p _swig_pointer_types[1]
|
||||||
|
#define SWIG_POINTER_long_p _swig_pointer_types[2]
|
||||||
|
#define SWIG_POINTER_float_p _swig_pointer_types[3]
|
||||||
|
#define SWIG_POINTER_double_p _swig_pointer_types[4]
|
||||||
|
#define SWIG_POINTER_char_p _swig_pointer_types[5]
|
||||||
|
#define SWIG_POINTER_char_pp _swig_pointer_types[6]
|
||||||
|
|
||||||
/*------------------------------------------------------------------
|
/*------------------------------------------------------------------
|
||||||
ptrcast(value,type)
|
ptrcast(value,type)
|
||||||
|
|
||||||
|
|
@ -41,10 +57,11 @@ static VALUE ptrcast(VALUE _PTRVALUE, char *type) {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
char *typestr,*c;
|
char *typestr,*c;
|
||||||
|
_swig_type_info temptype;
|
||||||
|
|
||||||
/* Produce a "mangled" version of the type string. */
|
/* Produce a "mangled" version of the type string. */
|
||||||
|
|
||||||
typestr = (char *) xmalloc(strlen(type)+2);
|
typestr = (char *) malloc(strlen(type)+2);
|
||||||
|
|
||||||
/* Go through and munge the typestring */
|
/* Go through and munge the typestring */
|
||||||
|
|
||||||
|
|
@ -63,47 +80,22 @@ static VALUE ptrcast(VALUE _PTRVALUE, char *type) {
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
*(r++) = 0;
|
*(r++) = 0;
|
||||||
|
|
||||||
/* Check to see what kind of object _PTRVALUE is */
|
/* Check to see what kind of object _PTRVALUE is */
|
||||||
|
|
||||||
switch (TYPE(_PTRVALUE)) {
|
switch (TYPE(_PTRVALUE)) {
|
||||||
case T_FIXNUM:
|
case T_FIXNUM:
|
||||||
case T_BIGNUM:
|
case T_BIGNUM:
|
||||||
ptr = (void *) NUM2ULONG(_PTRVALUE);
|
ptr = (void *) NUM2LONG(_PTRVALUE);
|
||||||
/* Received a numerical value. Make a pointer out of it */
|
/* Received a numerical value. Make a pointer out of it */
|
||||||
r = (char *) xmalloc(strlen(typestr)+22);
|
temptype.name = typestr;
|
||||||
if (ptr) {
|
obj = SWIG_NewPointerObj(ptr,&temptype);
|
||||||
SWIG_MakePtr(r, ptr, typestr);
|
|
||||||
} else {
|
|
||||||
sprintf(r,"_0%s",typestr);
|
|
||||||
}
|
|
||||||
obj = rb_str_new2(r);
|
obj = rb_str_new2(r);
|
||||||
free(r);
|
|
||||||
break;
|
|
||||||
case T_STRING:
|
|
||||||
/* Have a real pointer value now. Try to strip out the pointer
|
|
||||||
value */
|
|
||||||
s = STR2CSTR(_PTRVALUE);
|
|
||||||
r = (char *) xmalloc(strlen(type)+22);
|
|
||||||
|
|
||||||
/* Now extract the pointer value */
|
|
||||||
if (!SWIG_GetPtr(s,&ptr,0)) {
|
|
||||||
if (ptr) {
|
|
||||||
SWIG_MakePtr(r,ptr,typestr);
|
|
||||||
} else {
|
|
||||||
sprintf(r,"_0%s",typestr);
|
|
||||||
}
|
|
||||||
obj = rb_str_new2(r);
|
|
||||||
} else {
|
|
||||||
obj = Qnil;
|
|
||||||
}
|
|
||||||
free(r);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
obj = Qnil;
|
/* Now extract the pointer value */
|
||||||
break;
|
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||||
|
temptype.name=typestr;
|
||||||
|
obj = SWIG_NewPointerObj(ptr,&temptype);
|
||||||
}
|
}
|
||||||
free(typestr);
|
|
||||||
if (!obj)
|
if (!obj)
|
||||||
rb_raise(rb_eTypeError,"Type error in ptrcast. Argument is not a valid pointer value.");
|
rb_raise(rb_eTypeError,"Type error in ptrcast. Argument is not a valid pointer value.");
|
||||||
return obj;
|
return obj;
|
||||||
|
|
@ -123,50 +115,41 @@ static VALUE ptrvalue(VALUE _PTRVALUE, int index, char *type) {
|
||||||
char *s;
|
char *s;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
|
|
||||||
Check_Type(_PTRVALUE, T_STRING);
|
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||||
s = STR2CSTR(_PTRVALUE);
|
|
||||||
if (SWIG_GetPtr(s,&ptr,0)) {
|
|
||||||
rb_raise(rb_eTypeError,"Type error in ptrvalue. Argument is not a valid pointer value.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If no datatype was passed, try a few common datatypes first */
|
/* If no datatype was passed, try a few common datatypes first */
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
|
|
||||||
/* No datatype was passed. Type to figure out if it's a common one */
|
/* No datatype was passed. Type to figure out if it's a common one */
|
||||||
|
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||||
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
|
|
||||||
type = "int";
|
type = "int";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||||
type = "double";
|
type = "double";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||||
type = "short";
|
type = "short";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||||
type = "long";
|
type = "long";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||||
type = "float";
|
type = "float";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||||
type = "char";
|
type = "char";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"char_pp")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||||
type = "char *";
|
type = "char *";
|
||||||
} else {
|
} else {
|
||||||
type = "unknown";
|
type = "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
rb_raise(rb_eTypeError,"Unable to dereference NULL pointer.");
|
rb_raise(rb_eTypeError,"Unable to dereference NULL pointer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now we have a datatype. Try to figure out what to do about it */
|
/* Now we have a datatype. Try to figure out what to do about it */
|
||||||
if (strcmp(type,"int") == 0) {
|
if (strcmp(type,"int") == 0) {
|
||||||
obj = INT2NUM(*(((int *) ptr) + index));
|
obj = LONG2NUM((long) *(((int *) ptr) + index));
|
||||||
} else if (strcmp(type,"double") == 0) {
|
} else if (strcmp(type,"double") == 0) {
|
||||||
obj = rb_float_new((double) *(((double *) ptr)+index));
|
obj = rb_float_new((double) *(((double *) ptr)+index));
|
||||||
} else if (strcmp(type,"short") == 0) {
|
} else if (strcmp(type,"short") == 0) {
|
||||||
obj = INT2NUM(*(((short *) ptr)+index));
|
obj = LONG2NUM((long) *(((short *) ptr)+index));
|
||||||
} else if (strcmp(type,"long") == 0) {
|
} else if (strcmp(type,"long") == 0) {
|
||||||
obj = INT2NUM(*(((long *) ptr)+index));
|
obj = LONG2NUM((long) *(((long *) ptr)+index));
|
||||||
} else if (strcmp(type,"float") == 0) {
|
} else if (strcmp(type,"float") == 0) {
|
||||||
obj = rb_float_new((double) *(((float *) ptr)+index));
|
obj = rb_float_new((double) *(((float *) ptr)+index));
|
||||||
} else if (strcmp(type,"char") == 0) {
|
} else if (strcmp(type,"char") == 0) {
|
||||||
|
|
@ -192,60 +175,63 @@ static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
int sz;
|
int sz;
|
||||||
char *cast;
|
_swig_type_info *cast;
|
||||||
char temp[40];
|
char temp[40];
|
||||||
|
|
||||||
/* Check the type string against a variety of possibilities */
|
/* Check the type string against a variety of possibilities */
|
||||||
|
|
||||||
if (strcmp(type,"int") == 0) {
|
if (strcmp(type,"int") == 0) {
|
||||||
sz = sizeof(int)*numelements;
|
sz = sizeof(int)*numelements;
|
||||||
cast = "_int_p";
|
cast = SWIG_POINTER_int_p;
|
||||||
} else if (strcmp(type,"short") == 0) {
|
} else if (strcmp(type,"short") == 0) {
|
||||||
sz = sizeof(short)*numelements;
|
sz = sizeof(short)*numelements;
|
||||||
cast = "_short_p";
|
cast = SWIG_POINTER_short_p;
|
||||||
} else if (strcmp(type,"long") == 0) {
|
} else if (strcmp(type,"long") == 0) {
|
||||||
sz = sizeof(long)*numelements;
|
sz = sizeof(long)*numelements;
|
||||||
cast = "_long_p";
|
cast = SWIG_POINTER_long_p;
|
||||||
} else if (strcmp(type,"double") == 0) {
|
} else if (strcmp(type,"double") == 0) {
|
||||||
sz = sizeof(double)*numelements;
|
sz = sizeof(double)*numelements;
|
||||||
cast = "_double_p";
|
cast = SWIG_POINTER_double_p;
|
||||||
} else if (strcmp(type,"float") == 0) {
|
} else if (strcmp(type,"float") == 0) {
|
||||||
sz = sizeof(float)*numelements;
|
sz = sizeof(float)*numelements;
|
||||||
cast = "_float_p";
|
cast = SWIG_POINTER_float_p;
|
||||||
} else if (strcmp(type,"char") == 0) {
|
} else if (strcmp(type,"char") == 0) {
|
||||||
sz = sizeof(char)*numelements;
|
sz = sizeof(char)*numelements;
|
||||||
cast = "_char_p";
|
cast = SWIG_POINTER_char_p;
|
||||||
} else if (strcmp(type,"char *") == 0) {
|
} else if (strcmp(type,"char *") == 0) {
|
||||||
sz = sizeof(char *)*(numelements+1);
|
sz = sizeof(char *)*(numelements+1);
|
||||||
cast = "char_pp";
|
cast = SWIG_POINTER_char_pp;
|
||||||
} else {
|
} else {
|
||||||
rb_raise(rb_eTypeError,"Unable to create unknown datatype.");
|
rb_raise(rb_eTypeError,"Unable to create unknown datatype.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the new object */
|
/* Create the new object */
|
||||||
|
|
||||||
ptr = (void *) xmalloc(sz);
|
ptr = (void *) malloc(sz);
|
||||||
|
if (!ptr) {
|
||||||
|
rb_raise(rb_eFatal,"Out of memory in swig_create.");
|
||||||
|
}
|
||||||
|
|
||||||
/* Now try to set its default value */
|
/* Now try to set its default value */
|
||||||
|
|
||||||
if (_RBVALUE) {
|
if (_RBVALUE) {
|
||||||
if (strcmp(type,"int") == 0) {
|
if (strcmp(type,"int") == 0) {
|
||||||
int *ip,i,ivalue;
|
int *ip,i,ivalue;
|
||||||
ivalue = NUM2INT(_RBVALUE);
|
ivalue = (int) NUM2LONG(_RBVALUE);
|
||||||
ip = (int *) ptr;
|
ip = (int *) ptr;
|
||||||
for (i = 0; i < numelements; i++)
|
for (i = 0; i < numelements; i++)
|
||||||
ip[i] = ivalue;
|
ip[i] = ivalue;
|
||||||
} else if (strcmp(type,"short") == 0) {
|
} else if (strcmp(type,"short") == 0) {
|
||||||
short *ip,ivalue;
|
short *ip,ivalue;
|
||||||
int i;
|
int i;
|
||||||
ivalue = (short) NUM2INT(_RBVALUE);
|
ivalue = (short) NUM2LONG(_RBVALUE);
|
||||||
ip = (short *) ptr;
|
ip = (short *) ptr;
|
||||||
for (i = 0; i < numelements; i++)
|
for (i = 0; i < numelements; i++)
|
||||||
ip[i] = ivalue;
|
ip[i] = ivalue;
|
||||||
} else if (strcmp(type,"long") == 0) {
|
} else if (strcmp(type,"long") == 0) {
|
||||||
long *ip,ivalue;
|
long *ip,ivalue;
|
||||||
int i;
|
int i;
|
||||||
ivalue = NUM2LONG(_RBVALUE);
|
ivalue = (long) NUM2LONG(_RBVALUE);
|
||||||
ip = (long *) ptr;
|
ip = (long *) ptr;
|
||||||
for (i = 0; i < numelements; i++)
|
for (i = 0; i < numelements; i++)
|
||||||
ip[i] = ivalue;
|
ip[i] = ivalue;
|
||||||
|
|
@ -275,7 +261,7 @@ static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
||||||
ip = (char **) ptr;
|
ip = (char **) ptr;
|
||||||
for (i = 0; i < numelements; i++) {
|
for (i = 0; i < numelements; i++) {
|
||||||
if (ivalue) {
|
if (ivalue) {
|
||||||
ip[i] = (char *) xmalloc(strlen(ivalue)+1);
|
ip[i] = (char *) malloc(strlen(ivalue)+1);
|
||||||
strcpy(ip[i],ivalue);
|
strcpy(ip[i],ivalue);
|
||||||
} else {
|
} else {
|
||||||
ip[i] = 0;
|
ip[i] = 0;
|
||||||
|
|
@ -286,8 +272,7 @@ static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
||||||
}
|
}
|
||||||
/* Create the pointer value */
|
/* Create the pointer value */
|
||||||
|
|
||||||
SWIG_MakePtr(temp,ptr,cast);
|
obj = SWIG_NewPointerObj(ptr,cast);
|
||||||
obj = rb_str_new2(temp);
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,53 +286,44 @@ static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
||||||
|
|
||||||
static VALUE ptrset(VALUE _PTRVALUE, VALUE _RBVALUE, int index, char *type) {
|
static VALUE ptrset(VALUE _PTRVALUE, VALUE _RBVALUE, int index, char *type) {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
char *s;
|
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
|
|
||||||
Check_Type(_PTRVALUE, T_STRING);
|
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||||
s = STR2CSTR(_PTRVALUE);
|
|
||||||
if (SWIG_GetPtr(s,&ptr,0)) {
|
|
||||||
rb_raise(rb_eTypeError,"Type error in ptrset. Argument is not a valid pointer value.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If no datatype was passed, try a few common datatypes first */
|
/* If no datatype was passed, try a few common datatypes first */
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
|
|
||||||
/* No datatype was passed. Type to figure out if it's a common one */
|
/* No datatype was passed. Type to figure out if it's a common one */
|
||||||
|
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||||
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
|
|
||||||
type = "int";
|
type = "int";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||||
type = "double";
|
type = "double";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||||
type = "short";
|
type = "short";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||||
type = "long";
|
type = "long";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||||
type = "float";
|
type = "float";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||||
type = "char";
|
type = "char";
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"char_pp")) {
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||||
type = "char *";
|
type = "char *";
|
||||||
} else {
|
} else {
|
||||||
type = "unknown";
|
type = "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
rb_raise(rb_eTypeError,"Unable to set NULL pointer.");
|
rb_raise(rb_eTypeError,"Unable to set NULL pointer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now we have a datatype. Try to figure out what to do about it */
|
/* Now we have a datatype. Try to figure out what to do about it */
|
||||||
if (strcmp(type,"int") == 0) {
|
if (strcmp(type,"int") == 0) {
|
||||||
*(((int *) ptr)+index) = NUM2INT(_RBVALUE);
|
*(((int *) ptr)+index) = (int) NUM2LONG(_RBVALUE);
|
||||||
} else if (strcmp(type,"double") == 0) {
|
} else if (strcmp(type,"double") == 0) {
|
||||||
*(((double *) ptr)+index) = (double) NUM2DBL(_RBVALUE);
|
*(((double *) ptr)+index) = (double) NUM2DBL(_RBVALUE);
|
||||||
} else if (strcmp(type,"short") == 0) {
|
} else if (strcmp(type,"short") == 0) {
|
||||||
*(((short *) ptr)+index) = (short) NUM2INT(_RBVALUE);
|
*(((short *) ptr)+index) = (short) NUM2LONG(_RBVALUE);
|
||||||
} else if (strcmp(type,"long") == 0) {
|
} else if (strcmp(type,"long") == 0) {
|
||||||
*(((long *) ptr)+index) = NUM2LONG(_RBVALUE);
|
*(((long *) ptr)+index) = (long) NUM2LONG(_RBVALUE);
|
||||||
} else if (strcmp(type,"float") == 0) {
|
} else if (strcmp(type,"float") == 0) {
|
||||||
*(((float *) ptr)+index) = (float) NUM2DBL(_RBVALUE);
|
*(((float *) ptr)+index) = (float) NUM2DBL(_RBVALUE);
|
||||||
} else if (strcmp(type,"char") == 0) {
|
} else if (strcmp(type,"char") == 0) {
|
||||||
|
|
@ -360,7 +336,7 @@ static VALUE ptrset(VALUE _PTRVALUE, VALUE _RBVALUE, int index, char *type) {
|
||||||
if (strcmp(c,"NULL") == 0) {
|
if (strcmp(c,"NULL") == 0) {
|
||||||
ca[index] = 0;
|
ca[index] = 0;
|
||||||
} else {
|
} else {
|
||||||
ca[index] = (char *) xmalloc(strlen(c)+1);
|
ca[index] = (char *) malloc(strlen(c)+1);
|
||||||
strcpy(ca[index],c);
|
strcpy(ca[index],c);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -369,7 +345,6 @@ static VALUE ptrset(VALUE _PTRVALUE, VALUE _RBVALUE, int index, char *type) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------
|
/*------------------------------------------------------------------
|
||||||
ptradd(ptr,offset)
|
ptradd(ptr,offset)
|
||||||
|
|
||||||
|
|
@ -379,47 +354,41 @@ static VALUE ptrset(VALUE _PTRVALUE, VALUE _RBVALUE, int index, char *type) {
|
||||||
|
|
||||||
static VALUE ptradd(VALUE _PTRVALUE, int offset) {
|
static VALUE ptradd(VALUE _PTRVALUE, int offset) {
|
||||||
|
|
||||||
char *r,*s;
|
char *r;
|
||||||
void *ptr,*junk;
|
void *ptr,*junk;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
char *type;
|
_swig_type_info *type;
|
||||||
|
|
||||||
|
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||||
|
|
||||||
/* Check to see what kind of object _PTRVALUE is */
|
/* Check to see what kind of object _PTRVALUE is */
|
||||||
|
|
||||||
Check_Type(_PTRVALUE, T_STRING);
|
|
||||||
|
|
||||||
/* Have a potential pointer value now. Try to strip out the value */
|
|
||||||
s = STR2CSTR(_PTRVALUE);
|
|
||||||
|
|
||||||
/* Try to handle a few common datatypes first */
|
/* Try to handle a few common datatypes first */
|
||||||
|
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||||
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
|
|
||||||
ptr = (void *) (((int *) ptr) + offset);
|
ptr = (void *) (((int *) ptr) + offset);
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
|
type = SWIG_POINTER_int_p;
|
||||||
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||||
ptr = (void *) (((double *) ptr) + offset);
|
ptr = (void *) (((double *) ptr) + offset);
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
|
type = SWIG_POINTER_double_p;
|
||||||
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||||
ptr = (void *) (((short *) ptr) + offset);
|
ptr = (void *) (((short *) ptr) + offset);
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
|
type = SWIG_POINTER_short_p;
|
||||||
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||||
ptr = (void *) (((long *) ptr) + offset);
|
ptr = (void *) (((long *) ptr) + offset);
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
|
type = SWIG_POINTER_long_p;
|
||||||
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||||
ptr = (void *) (((float *) ptr) + offset);
|
ptr = (void *) (((float *) ptr) + offset);
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
|
type = SWIG_POINTER_float_p;
|
||||||
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||||
ptr = (void *) (((char *) ptr) + offset);
|
ptr = (void *) (((char *) ptr) + offset);
|
||||||
} else if (!SWIG_GetPtr(s,&ptr,0)) {
|
type = SWIG_POINTER_char_p;
|
||||||
|
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||||
ptr = (void *) (((char *) ptr) + offset);
|
ptr = (void *) (((char *) ptr) + offset);
|
||||||
|
type = SWIG_POINTER_char_pp;
|
||||||
} else {
|
} else {
|
||||||
rb_raise(rb_eTypeError,"Type error in ptradd. Argument is not a valid pointer value.");
|
rb_raise(rb_eTypeError,"Type error in ptradd. Argument is not a valid pointer value.");
|
||||||
}
|
}
|
||||||
type = SWIG_GetPtr(s,&junk,"INVALID POINTER");
|
obj = SWIG_NewPointerObj(ptr, type);
|
||||||
r = (char *) xmalloc(strlen(type)+20);
|
|
||||||
if (ptr) {
|
|
||||||
SWIG_MakePtr(r,ptr,type);
|
|
||||||
} else {
|
|
||||||
sprintf(r,"_0%s",type);
|
|
||||||
}
|
|
||||||
obj = rb_str_new2(r);
|
|
||||||
free(r);
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -428,17 +397,13 @@ static VALUE ptradd(VALUE _PTRVALUE, int offset) {
|
||||||
|
|
||||||
Allows a mapping between type1 and type2. (Like a typedef)
|
Allows a mapping between type1 and type2. (Like a typedef)
|
||||||
------------------------------------------------------------------ */
|
------------------------------------------------------------------ */
|
||||||
|
|
||||||
static void ptrmap(char *type1, char *type2) {
|
static void ptrmap(char *type1, char *type2) {
|
||||||
|
|
||||||
char *typestr1,*typestr2,*c,*r;
|
char *typestr1,*typestr2,*c,*r;
|
||||||
|
|
||||||
/* Produce a "mangled" version of the type string. */
|
/* Produce a "mangled" version of the type string. */
|
||||||
|
typestr1 = (char *) malloc(strlen(type1)+2);
|
||||||
typestr1 = (char *) xmalloc(strlen(type1)+2);
|
|
||||||
|
|
||||||
/* Go through and munge the typestring */
|
/* Go through and munge the typestring */
|
||||||
|
|
||||||
r = typestr1;
|
r = typestr1;
|
||||||
*(r++) = '_';
|
*(r++) = '_';
|
||||||
c = type1;
|
c = type1;
|
||||||
|
|
@ -455,7 +420,7 @@ static void ptrmap(char *type1, char *type2) {
|
||||||
}
|
}
|
||||||
*(r++) = 0;
|
*(r++) = 0;
|
||||||
|
|
||||||
typestr2 = (char *) xmalloc(strlen(type2)+2);
|
typestr2 = (char *) malloc(strlen(type2)+2);
|
||||||
|
|
||||||
/* Go through and munge the typestring */
|
/* Go through and munge the typestring */
|
||||||
|
|
||||||
|
|
@ -474,8 +439,12 @@ static void ptrmap(char *type1, char *type2) {
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
*(r++) = 0;
|
*(r++) = 0;
|
||||||
|
|
||||||
|
/* Currently unsupported */
|
||||||
|
/*
|
||||||
SWIG_RegisterMapping(typestr1,typestr2,0);
|
SWIG_RegisterMapping(typestr1,typestr2,0);
|
||||||
SWIG_RegisterMapping(typestr2,typestr1,0);
|
SWIG_RegisterMapping(typestr2,typestr1,0);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------
|
/*------------------------------------------------------------------
|
||||||
|
|
@ -485,17 +454,12 @@ static void ptrmap(char *type1, char *type2) {
|
||||||
------------------------------------------------------------------ */
|
------------------------------------------------------------------ */
|
||||||
|
|
||||||
VALUE ptrfree(VALUE _PTRVALUE) {
|
VALUE ptrfree(VALUE _PTRVALUE) {
|
||||||
void *ptr, *junk;
|
void *ptr;
|
||||||
char *s;
|
|
||||||
|
|
||||||
Check_Type(_PTRVALUE, T_STRING);
|
|
||||||
s = STR2CSTR(_PTRVALUE);
|
|
||||||
if (SWIG_GetPtr(s,&ptr,0)) {
|
|
||||||
rb_raise(rb_eTypeError,"Type error in ptrfree. Argument is not a valid pointer value.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||||
|
|
||||||
/* Check to see if this pointer is a char ** */
|
/* Check to see if this pointer is a char ** */
|
||||||
if (!SWIG_GetPtr(s,&junk,"char_pp")) {
|
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||||
char **c = (char **) ptr;
|
char **c = (char **) ptr;
|
||||||
if (c) {
|
if (c) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -504,7 +468,7 @@ VALUE ptrfree(VALUE _PTRVALUE) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ptr)
|
if (ptr)
|
||||||
free((char *) ptr);
|
free((char *) ptr);
|
||||||
|
|
||||||
|
|
@ -535,7 +499,7 @@ VALUE ptrcast(VALUE ptr, char *type);
|
||||||
// type may be either the SWIG generated representation of a datatype
|
// type may be either the SWIG generated representation of a datatype
|
||||||
// or the C representation. For example :
|
// or the C representation. For example :
|
||||||
//
|
//
|
||||||
// ptrcast(ptr,"double_p"); # Ruby representation
|
// ptrcast(ptr,"double_p"); # Ruby representation
|
||||||
// ptrcast(ptr,"double *"); # C representation
|
// ptrcast(ptr,"double *"); # C representation
|
||||||
//
|
//
|
||||||
// A new pointer value is returned. ptr may also be an integer
|
// A new pointer value is returned. ptr may also be an integer
|
||||||
|
|
@ -642,5 +606,16 @@ void ptrmap(char *type1, char *type2);
|
||||||
// weird type-handling problems.
|
// weird type-handling problems.
|
||||||
|
|
||||||
|
|
||||||
|
%init %{
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; _swig_pointer_types[i]; i++) {
|
||||||
|
_swig_pointer_types[i] = SWIG_TypeRegister(_swig_pointer_types[i]);
|
||||||
|
SWIG_define_class(_swig_pointer_types[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,27 +18,3 @@
|
||||||
# define VOIDFUNC(f) (f)
|
# define VOIDFUNC(f) (f)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__WIN32__)
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
# if defined(STATIC_LINKED)
|
|
||||||
# define SWIGEXPORT(a) a
|
|
||||||
# else
|
|
||||||
# define SWIGEXPORT(a) __declspec(dllexport) a
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# if defined(__BORLANDC__)
|
|
||||||
# define SWIGEXPORT(a) a _export
|
|
||||||
# else
|
|
||||||
# define SWIGEXPORT(a) a
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
# define SWIGEXPORT(a) a
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SWIG_GLOBAL
|
|
||||||
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
|
|
||||||
#else
|
|
||||||
#define SWIGSTATICRUNTIME(a) static a
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SWIGEXPORT(void) SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *));
|
SWIGEXPORT(void) SWIG_define_class(VALUE, _swig_type_info *)
|
||||||
SWIGEXPORT(void) SWIG_MakePtr(char *_c, const void *_ptr, char *type);
|
SWIGEXPORT(VALUE) SWIG_NewPointerObj(void *, _swig_type_info *);
|
||||||
SWIGEXPORT(char *) SWIG_GetPtr(char *_c, void **ptr, char *_t);
|
SWIGEXPORT(char *) SWIG_MangleStr(VALUE);
|
||||||
SWIGEXPORT(VALUE) SWIG_NewPointerObj(void *ptr, char *type);
|
SWIGEXPORT(void *) SWIG_ConvertPtr(VALUE, _swig_type_info *);
|
||||||
SWIGEXPORT(void *) SWIG_ConvertPtr(VALUE obj, char *type);
|
SWIGEXPORT(int) SWIG_CheckConvert(VALUE, _swig_type_info *);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,293 +3,84 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* SWIG pointer structure */
|
|
||||||
|
|
||||||
typedef struct SwigPtrType {
|
static VALUE _mSWIG = Qnil;
|
||||||
char *name; /* Datatype name */
|
static VALUE _cSWIG_Pointer = Qnil;
|
||||||
int len; /* Length (used for optimization) */
|
|
||||||
void *(*cast)(void *); /* Pointer casting function */
|
|
||||||
struct SwigPtrType *next; /* Linked list pointer */
|
|
||||||
} SwigPtrType;
|
|
||||||
|
|
||||||
/* Pointer cache structure */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int stat; /* Status (valid) bit */
|
|
||||||
SwigPtrType *tp; /* Pointer to type structure */
|
|
||||||
char name[256]; /* Given datatype name */
|
|
||||||
char mapped[256]; /* Equivalent name */
|
|
||||||
} SwigCacheType;
|
|
||||||
|
|
||||||
/* Some variables */
|
|
||||||
|
|
||||||
static int SwigPtrMax = 64; /* Max entries that can be currently held */
|
|
||||||
/* This value may be adjusted dynamically */
|
|
||||||
static int SwigPtrN = 0; /* Current number of entries */
|
|
||||||
static int SwigPtrSort = 0; /* Status flag indicating sort */
|
|
||||||
static int SwigStart[256]; /* Starting positions of types */
|
|
||||||
|
|
||||||
/* Pointer table */
|
|
||||||
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
|
|
||||||
|
|
||||||
/* Cached values */
|
|
||||||
|
|
||||||
#define SWIG_CACHESIZE 8
|
|
||||||
#define SWIG_CACHEMASK 0x7
|
|
||||||
static SwigCacheType SwigCache[SWIG_CACHESIZE];
|
|
||||||
static int SwigCacheIndex = 0;
|
|
||||||
static int SwigLastCache = 0;
|
|
||||||
|
|
||||||
/* Sort comparison function */
|
|
||||||
static int swigsort(const void *data1, const void *data2) {
|
|
||||||
SwigPtrType *d1 = (SwigPtrType *) data1;
|
|
||||||
SwigPtrType *d2 = (SwigPtrType *) data2;
|
|
||||||
return strcmp(d1->name,d2->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Binary Search function */
|
|
||||||
static int swigcmp(const void *key, const void *data) {
|
|
||||||
char *k = (char *) key;
|
|
||||||
SwigPtrType *d = (SwigPtrType *) data;
|
|
||||||
return strncmp(k,d->name,d->len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Register a new datatype with the type-checker */
|
|
||||||
|
|
||||||
|
/* Define ruby class for C type */
|
||||||
SWIGSTATICRUNTIME(void)
|
SWIGSTATICRUNTIME(void)
|
||||||
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
|
SWIG_define_class(_swig_type_info *type)
|
||||||
|
|
||||||
int i;
|
|
||||||
SwigPtrType *t = 0,*t1;
|
|
||||||
|
|
||||||
/* Allocate the pointer table if necessary */
|
|
||||||
|
|
||||||
if (!SwigPtrTable) {
|
|
||||||
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
|
|
||||||
SwigPtrN = 0;
|
|
||||||
}
|
|
||||||
/* Grow the table */
|
|
||||||
if (SwigPtrN >= SwigPtrMax) {
|
|
||||||
SwigPtrMax = 2*SwigPtrMax;
|
|
||||||
SwigPtrTable = (SwigPtrType *) realloc((char *) SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
|
|
||||||
}
|
|
||||||
for (i = 0; i < SwigPtrN; i++)
|
|
||||||
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
|
|
||||||
t = &SwigPtrTable[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!t) {
|
|
||||||
t = &SwigPtrTable[SwigPtrN];
|
|
||||||
t->name = origtype;
|
|
||||||
t->len = strlen(t->name);
|
|
||||||
t->cast = 0;
|
|
||||||
t->next = 0;
|
|
||||||
SwigPtrN++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for existing entry */
|
|
||||||
|
|
||||||
while (t->next) {
|
|
||||||
if ((strcmp(t->name,newtype) == 0)) {
|
|
||||||
if (cast) t->cast = cast;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
t = t->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now place entry (in sorted order) */
|
|
||||||
|
|
||||||
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
|
|
||||||
t1->name = newtype;
|
|
||||||
t1->len = strlen(t1->name);
|
|
||||||
t1->cast = cast;
|
|
||||||
t1->next = 0;
|
|
||||||
t->next = t1;
|
|
||||||
SwigPtrSort = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make a pointer value string */
|
|
||||||
|
|
||||||
SWIGSTATICRUNTIME(void)
|
|
||||||
SWIG_MakePtr(char *_c, const void *_ptr, char *type) {
|
|
||||||
static char _hex[16] =
|
|
||||||
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
||||||
'a', 'b', 'c', 'd', 'e', 'f'};
|
|
||||||
unsigned long _p, _s;
|
|
||||||
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
|
|
||||||
_r = _result;
|
|
||||||
_p = (unsigned long) _ptr;
|
|
||||||
if (_p > 0) {
|
|
||||||
while (_p > 0) {
|
|
||||||
_s = _p & 0xf;
|
|
||||||
*(_r++) = _hex[_s];
|
|
||||||
_p = _p >> 4;
|
|
||||||
}
|
|
||||||
*_r = '_';
|
|
||||||
while (_r >= _result)
|
|
||||||
*(_c++) = *(_r--);
|
|
||||||
} else {
|
|
||||||
strcpy (_c, "NULL");
|
|
||||||
}
|
|
||||||
if (_ptr)
|
|
||||||
strcpy (_c, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Define for backwards compatibility */
|
|
||||||
|
|
||||||
#define _swig_make_hex SWIG_MakePtr
|
|
||||||
|
|
||||||
/* Function for getting a pointer value */
|
|
||||||
|
|
||||||
SWIGSTATICRUNTIME(char *)
|
|
||||||
SWIG_GetPtr(char *_c, void **ptr, char *_t)
|
|
||||||
{
|
{
|
||||||
unsigned long _p;
|
char *klass_name = ALLOCA_N(char, 4 + strlen(type->name) + 1);
|
||||||
char temp_type[256];
|
sprintf(klass_name, "TYPE%s", type->name);
|
||||||
char *name;
|
if (NIL_P(_cSWIG_Pointer)) {
|
||||||
int i, len;
|
_cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
|
||||||
SwigPtrType *sp,*tp;
|
|
||||||
SwigCacheType *cache;
|
|
||||||
int start, end;
|
|
||||||
_p = 0;
|
|
||||||
|
|
||||||
/* Pointer values must start with leading underscore */
|
|
||||||
if (*_c == '_') {
|
|
||||||
_c++;
|
|
||||||
/* Extract hex value from pointer */
|
|
||||||
while (*_c) {
|
|
||||||
if ((*_c >= '0') && (*_c <= '9'))
|
|
||||||
_p = (_p << 4) + (*_c - '0');
|
|
||||||
else if ((*_c >= 'a') && (*_c <= 'f'))
|
|
||||||
_p = (_p << 4) + ((*_c - 'a') + 10);
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
_c++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_t) {
|
|
||||||
if (strcmp(_t,_c)) {
|
|
||||||
if (!SwigPtrSort) {
|
|
||||||
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
|
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
SwigStart[i] = SwigPtrN;
|
|
||||||
}
|
|
||||||
for (i = SwigPtrN-1; i >= 0; i--) {
|
|
||||||
SwigStart[(int) (SwigPtrTable[i].name[1])] = i;
|
|
||||||
}
|
|
||||||
for (i = 255; i >= 1; i--) {
|
|
||||||
if (SwigStart[i-1] > SwigStart[i])
|
|
||||||
SwigStart[i-1] = SwigStart[i];
|
|
||||||
}
|
|
||||||
SwigPtrSort = 1;
|
|
||||||
for (i = 0; i < SWIG_CACHESIZE; i++)
|
|
||||||
SwigCache[i].stat = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* First check cache for matches. Uses last cache value as starting point */
|
|
||||||
cache = &SwigCache[SwigLastCache];
|
|
||||||
for (i = 0; i < SWIG_CACHESIZE; i++) {
|
|
||||||
if (cache->stat) {
|
|
||||||
if (strcmp(_t,cache->name) == 0) {
|
|
||||||
if (strcmp(_c,cache->mapped) == 0) {
|
|
||||||
cache->stat++;
|
|
||||||
*ptr = (void *) _p;
|
|
||||||
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
|
|
||||||
return (char *) 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
|
|
||||||
if (!SwigLastCache) cache = SwigCache;
|
|
||||||
else cache++;
|
|
||||||
}
|
|
||||||
/* We have a type mismatch. Will have to look through our type
|
|
||||||
mapping table to figure out whether or not we can accept this datatype */
|
|
||||||
|
|
||||||
start = SwigStart[(int) _t[1]];
|
|
||||||
end = SwigStart[(int) _t[1]+1];
|
|
||||||
sp = &SwigPtrTable[start];
|
|
||||||
while (start < end) {
|
|
||||||
if (swigcmp(_t,sp) == 0) break;
|
|
||||||
sp++;
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
if (start >= end) sp = 0;
|
|
||||||
/* Try to find a match for this */
|
|
||||||
if (sp) {
|
|
||||||
while (swigcmp(_t,sp) == 0) {
|
|
||||||
name = sp->name;
|
|
||||||
len = sp->len;
|
|
||||||
tp = sp->next;
|
|
||||||
/* Try to find entry for our given datatype */
|
|
||||||
while(tp) {
|
|
||||||
if (tp->len >= 255) {
|
|
||||||
return _c;
|
|
||||||
}
|
|
||||||
strcpy(temp_type,tp->name);
|
|
||||||
strncat(temp_type,_t+len,255-tp->len);
|
|
||||||
if (strcmp(_c,temp_type) == 0) {
|
|
||||||
|
|
||||||
strcpy(SwigCache[SwigCacheIndex].mapped,_c);
|
|
||||||
strcpy(SwigCache[SwigCacheIndex].name,_t);
|
|
||||||
SwigCache[SwigCacheIndex].stat = 1;
|
|
||||||
SwigCache[SwigCacheIndex].tp = tp;
|
|
||||||
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
|
|
||||||
|
|
||||||
/* Get pointer value */
|
|
||||||
*ptr = (void *) _p;
|
|
||||||
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
|
|
||||||
return (char *) 0;
|
|
||||||
}
|
|
||||||
tp = tp->next;
|
|
||||||
}
|
|
||||||
sp++;
|
|
||||||
/* Hmmm. Didn't find it this time */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Didn't find any sort of match for this data.
|
|
||||||
Get the pointer value and return the received type */
|
|
||||||
*ptr = (void *) _p;
|
|
||||||
return _c;
|
|
||||||
} else {
|
|
||||||
/* Found a match on the first try. Return pointer value */
|
|
||||||
*ptr = (void *) _p;
|
|
||||||
return (char *) 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* No type specified. Good luck */
|
|
||||||
*ptr = (void *) _p;
|
|
||||||
return (char *) 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (strcmp (_c, "NULL") == 0) {
|
|
||||||
*ptr = (void *) 0;
|
|
||||||
return (char *) 0;
|
|
||||||
}
|
}
|
||||||
*ptr = (void *) 0;
|
rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
|
||||||
return _c;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create a new pointer object */
|
||||||
SWIGSTATICRUNTIME(VALUE)
|
SWIGSTATICRUNTIME(VALUE)
|
||||||
SWIG_NewPointerObj(void *ptr, char *type)
|
SWIG_NewPointerObj(void *ptr, _swig_type_info *type)
|
||||||
{
|
{
|
||||||
char *temp = ALLOCA_N(char, strlen(type)+22);
|
char *klass_name;
|
||||||
SWIG_MakePtr(temp, ptr, type);
|
VALUE klass;
|
||||||
return rb_str_new2(temp);
|
|
||||||
|
if (!ptr)
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
|
klass_name = ALLOCA_N(char, 4 + strlen(type->name) + 1);
|
||||||
|
sprintf(klass_name, "TYPE%s", type->name);
|
||||||
|
klass = rb_const_get(_mSWIG, rb_intern(klass_name));
|
||||||
|
return Data_Wrap_Struct(klass, 0, 0, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SWIGSTATICRUNTIME(void *)
|
/* Get type mangle from class name */
|
||||||
SWIG_ConvertPtr(VALUE obj, char *type)
|
SWIGSTATICRUNTIME(char *)
|
||||||
|
SWIG_MangleStr(VALUE obj)
|
||||||
{
|
{
|
||||||
|
char *c;
|
||||||
|
|
||||||
|
if (!rb_obj_is_kind_of(obj, _cSWIG_Pointer))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
c = rb_class2name(rb_class_of(obj));
|
||||||
|
c += strlen(c);
|
||||||
|
while (*(--c) != ':');
|
||||||
|
/* skip ":TYPE" */
|
||||||
|
c += 5;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert a pointer value */
|
||||||
|
SWIGSTATICRUNTIME(void *)
|
||||||
|
SWIG_ConvertPtr(VALUE obj, _swig_type_info *ty)
|
||||||
|
{
|
||||||
|
char *c;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
Check_Type(obj, T_STRING);
|
_swig_type_info *tc;
|
||||||
if (SWIG_GetPtr(RSTRING(obj)->ptr, &ptr, type)) {
|
|
||||||
rb_raise(rb_eTypeError, "Expected a %s", type);
|
if ((c = SWIG_MangleStr(obj)) == NULL)
|
||||||
|
rb_raise(rb_eTypeError, "Expected %s", ty->name);
|
||||||
|
Data_Get_Struct(obj, void, ptr);
|
||||||
|
if (ty) {
|
||||||
|
tc = SWIG_TypeCheck(c, ty);
|
||||||
|
if (!tc) rb_raise(rb_eTypeError, "Expected %s", ty->name);
|
||||||
|
ptr = SWIG_TypeCast(tc, ptr);
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check convert */
|
||||||
|
SWIGSTATICRUNTIME(int)
|
||||||
|
SWIG_CheckConvert(VALUE obj, _swig_type_info *ty)
|
||||||
|
{
|
||||||
|
char *c = SWIG_MangleStr(obj);
|
||||||
|
if (!c)
|
||||||
|
return 0;
|
||||||
|
return SWIG_TypeCheck(c,ty) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,17 @@ void RUBY::parse_args(int argc, char *argv[]) {
|
||||||
typemap_lang = (char*)"ruby";
|
typemap_lang = (char*)"ruby";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void insert_file(char *filename, File *file) {
|
||||||
|
if (Swig_insert_file(filename, file) == -1) {
|
||||||
|
Printf(stderr,
|
||||||
|
"SWIG : Fatal error. "
|
||||||
|
"Unable to locate %s. (Possible installation problem).\n",
|
||||||
|
filename);
|
||||||
|
SWIG_exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// RUBY::parse()
|
// RUBY::parse()
|
||||||
//
|
//
|
||||||
|
|
@ -191,6 +202,8 @@ void RUBY::parse() {
|
||||||
klass = 0;
|
klass = 0;
|
||||||
classes = NewHash();
|
classes = NewHash();
|
||||||
special_methods = NewHash();
|
special_methods = NewHash();
|
||||||
|
other_extern = NewString("");
|
||||||
|
other_init = NewString("");
|
||||||
|
|
||||||
// Python style special method name.
|
// Python style special method name.
|
||||||
// Basic
|
// Basic
|
||||||
|
|
@ -226,12 +239,18 @@ void RUBY::parse() {
|
||||||
Setattr(special_methods, "__float__", "to_f");
|
Setattr(special_methods, "__float__", "to_f");
|
||||||
Setattr(special_methods, "__coerce__", "coerce");
|
Setattr(special_methods, "__coerce__", "coerce");
|
||||||
|
|
||||||
printf("Generating wrappers for Ruby\n");
|
Swig_banner(f_header);
|
||||||
|
|
||||||
other_extern = NewString("");
|
Printf(f_header,"/* Implementation : RUBY */\n\n");
|
||||||
other_init = NewString("");
|
Printf(f_header,"#define SWIGRUBY\n");
|
||||||
|
|
||||||
headers();
|
insert_file((char*)"common.swg", f_header);
|
||||||
|
insert_file((char*)"ruby.swg", f_header);
|
||||||
|
if (NoInclude) {
|
||||||
|
insert_file((char*)"rubydec.swg", f_header);
|
||||||
|
} else {
|
||||||
|
insert_file((char*)"rubydef.swg", f_header);
|
||||||
|
}
|
||||||
|
|
||||||
// typedef void *VALUE
|
// typedef void *VALUE
|
||||||
SwigType *value = NewSwigType(T_VOID);
|
SwigType *value = NewSwigType(T_VOID);
|
||||||
|
|
@ -294,33 +313,6 @@ void RUBY::set_module(char *mod_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void insert_file(char *filename, File *file) {
|
|
||||||
if (Swig_insert_file(filename, file) == -1) {
|
|
||||||
Printf(stderr,
|
|
||||||
"SWIG : Fatal error. "
|
|
||||||
"Unable to locate %s. (Possible installation problem).\n",
|
|
||||||
filename);
|
|
||||||
SWIG_exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
// RUBY::headers(void)
|
|
||||||
//
|
|
||||||
// Generate the appropriate header files for RUBY interface.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
void RUBY::headers(void) {
|
|
||||||
Swig_banner(f_header);
|
|
||||||
Printf(f_header,"/* Implementation : RUBY */\n\n");
|
|
||||||
Printf(f_header,"#define SWIGRUBY\n");
|
|
||||||
|
|
||||||
insert_file((char*)"ruby.swg", f_header);
|
|
||||||
if (NoInclude) {
|
|
||||||
insert_file((char*)"rubydec.swg", f_header);
|
|
||||||
} else {
|
|
||||||
insert_file((char*)"rubydef.swg", f_header);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// RUBY::initialize(void)
|
// RUBY::initialize(void)
|
||||||
//
|
//
|
||||||
|
|
@ -345,11 +337,15 @@ void RUBY::initialize() {
|
||||||
"extern \"C\"\n",
|
"extern \"C\"\n",
|
||||||
"#endif\n",
|
"#endif\n",
|
||||||
"void Init_", feature, "(void) {\n",
|
"void Init_", feature, "(void) {\n",
|
||||||
|
"int i;\n",
|
||||||
other_init,
|
other_init,
|
||||||
|
"\n",
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if (!toplevel) {
|
if (!toplevel) {
|
||||||
Printv(f_init, tab4, modvar, " = rb_define_module(\"", module, "\");\n", 0);
|
Printv(f_init, tab4, modvar, " = rb_define_module(\"", module, "\");\n",
|
||||||
|
"_mSWIG = rb_define_module_under(", modvar, ", \"SWIG\");\n",
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
Printf(f_init,"\n");
|
Printf(f_init,"\n");
|
||||||
klass = new RClass();
|
klass = new RClass();
|
||||||
|
|
@ -363,11 +359,15 @@ void RUBY::initialize() {
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
void RUBY::close(void) {
|
void RUBY::close(void) {
|
||||||
// Finish off our init function
|
// Finish off our init function
|
||||||
Printf(f_init, "\n");
|
Printv(f_init,
|
||||||
#ifdef OLD
|
"\n",
|
||||||
emit_ptr_equivalence(f_wrappers,f_init);
|
"for (i = 0; _swig_types_initial[i]; i++) {\n",
|
||||||
#endif
|
"_swig_types[i] = SWIG_TypeRegister(_swig_types_initial[i]);\n",
|
||||||
|
"SWIG_define_class(_swig_types[i]);\n",
|
||||||
|
"}\n",
|
||||||
|
0);
|
||||||
Printf(f_init,"}\n");
|
Printf(f_init,"}\n");
|
||||||
|
SwigType_emit_type_table(f_header,f_wrappers);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
@ -736,7 +736,7 @@ void RUBY::link_variable(char *name, char *iname, SwigType *t) {
|
||||||
SwigType_add_pointer(t);
|
SwigType_add_pointer(t);
|
||||||
SwigType_remember(t);
|
SwigType_remember(t);
|
||||||
Printv(getf->code, tab4, "_val = SWIG_NewPointerObj((void *)&", name,
|
Printv(getf->code, tab4, "_val = SWIG_NewPointerObj((void *)&", name,
|
||||||
", \"", SwigType_manglestr(t), "\");\n", 0);
|
", SWIGTYPE", SwigType_manglestr(t), ");\n", 0);
|
||||||
SwigType_del_pointer(t);
|
SwigType_del_pointer(t);
|
||||||
} else {
|
} else {
|
||||||
Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n",
|
Printf(stderr,"%s: Line %d. Unable to link with variable type %s\n",
|
||||||
|
|
@ -764,10 +764,11 @@ void RUBY::link_variable(char *name, char *iname, SwigType *t) {
|
||||||
Printv(setf->code,s,"\n",0);
|
Printv(setf->code,s,"\n",0);
|
||||||
Delete(s);
|
Delete(s);
|
||||||
} else if (SwigType_type(t) == T_USER) {
|
} else if (SwigType_type(t) == T_USER) {
|
||||||
|
SwigType_remember(t);
|
||||||
SwigType_add_pointer(t);
|
SwigType_add_pointer(t);
|
||||||
Wrapper_add_localv(setf,"temp",SwigType_lstr(t,0), "temp",0);
|
Wrapper_add_localv(setf,"temp",SwigType_lstr(t,0), "temp",0);
|
||||||
Printv(setf->code, tab4, "temp = (", SwigType_lstr(t,0), ")",
|
Printv(setf->code, tab4, "temp = (", SwigType_lstr(t,0), ")",
|
||||||
"SWIG_ConvertPtr(_val, \"", SwigType_manglestr(t), "\");\n",
|
"SWIG_ConvertPtr(_val, SWIGTYPE", SwigType_manglestr(t), ");\n",
|
||||||
0);
|
0);
|
||||||
Printv(setf->code, tab4, name, " = *temp;\n",0);
|
Printv(setf->code, tab4, name, " = *temp;\n",0);
|
||||||
SwigType_del_pointer(t);
|
SwigType_del_pointer(t);
|
||||||
|
|
@ -1006,7 +1007,8 @@ int RUBY::to_VALUE(SwigType *type, char *value, String *str, int raw) {
|
||||||
Printv(str, "rb_str_new2(", value, ")", 0);
|
Printv(str, "rb_str_new2(", value, ")", 0);
|
||||||
break;
|
break;
|
||||||
case T_POINTER: case T_ARRAY: case T_REFERENCE:
|
case T_POINTER: case T_ARRAY: case T_REFERENCE:
|
||||||
Printv(str, "SWIG_NewPointerObj((void *)", value, ", \"", SwigType_manglestr(type), "\")", 0);
|
SwigType_remember(type);
|
||||||
|
Printv(str, "SWIG_NewPointerObj((void *)", value, ", SWIGTYPE", SwigType_manglestr(type), ")", 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -1059,7 +1061,8 @@ int RUBY::from_VALUE(SwigType *type, char *value, String *str) {
|
||||||
Printv(str, "STR2CSTR(", value, ")", 0);
|
Printv(str, "STR2CSTR(", value, ")", 0);
|
||||||
break;
|
break;
|
||||||
case T_POINTER: case T_ARRAY: case T_REFERENCE:
|
case T_POINTER: case T_ARRAY: case T_REFERENCE:
|
||||||
Printv(str, "(", SwigType_lstr(type,0), ")SWIG_ConvertPtr(", value, ", \"", SwigType_manglestr(type), "\")", 0);
|
SwigType_remember(type);
|
||||||
|
Printv(str, "(", SwigType_lstr(type,0), ")SWIG_ConvertPtr(", value, ", SWIGTYPE", SwigType_manglestr(type), ")", 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ class RUBY : public Language {
|
||||||
virtual void link_variable(char *, char *, SwigType *);
|
virtual void link_variable(char *, char *, SwigType *);
|
||||||
virtual void declare_const(char *, char *, SwigType *, char *);
|
virtual void declare_const(char *, char *, SwigType *, char *);
|
||||||
virtual void initialize(void);
|
virtual void initialize(void);
|
||||||
virtual void headers(void);
|
|
||||||
virtual void close(void);
|
virtual void close(void);
|
||||||
virtual void set_module(char *);
|
virtual void set_module(char *);
|
||||||
virtual void add_native(char *, char *, SwigType *, ParmList *);
|
virtual void add_native(char *, char *, SwigType *, ParmList *);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue