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
|
||||
//
|
||||
|
|
@ -20,9 +8,37 @@
|
|||
// by the file ../pointer.i
|
||||
|
||||
%{
|
||||
|
||||
#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)
|
||||
|
||||
|
|
@ -41,10 +57,11 @@ static VALUE ptrcast(VALUE _PTRVALUE, char *type) {
|
|||
void *ptr;
|
||||
VALUE obj;
|
||||
char *typestr,*c;
|
||||
_swig_type_info temptype;
|
||||
|
||||
/* 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 */
|
||||
|
||||
|
|
@ -63,47 +80,22 @@ static VALUE ptrcast(VALUE _PTRVALUE, char *type) {
|
|||
c++;
|
||||
}
|
||||
*(r++) = 0;
|
||||
|
||||
/* Check to see what kind of object _PTRVALUE is */
|
||||
|
||||
switch (TYPE(_PTRVALUE)) {
|
||||
case T_FIXNUM:
|
||||
case T_BIGNUM:
|
||||
ptr = (void *) NUM2ULONG(_PTRVALUE);
|
||||
ptr = (void *) NUM2LONG(_PTRVALUE);
|
||||
/* Received a numerical value. Make a pointer out of it */
|
||||
r = (char *) xmalloc(strlen(typestr)+22);
|
||||
if (ptr) {
|
||||
SWIG_MakePtr(r, ptr, typestr);
|
||||
} else {
|
||||
sprintf(r,"_0%s",typestr);
|
||||
}
|
||||
temptype.name = typestr;
|
||||
obj = SWIG_NewPointerObj(ptr,&temptype);
|
||||
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;
|
||||
default:
|
||||
obj = Qnil;
|
||||
break;
|
||||
/* Now extract the pointer value */
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
temptype.name=typestr;
|
||||
obj = SWIG_NewPointerObj(ptr,&temptype);
|
||||
}
|
||||
free(typestr);
|
||||
if (!obj)
|
||||
rb_raise(rb_eTypeError,"Type error in ptrcast. Argument is not a valid pointer value.");
|
||||
return obj;
|
||||
|
|
@ -123,50 +115,41 @@ static VALUE ptrvalue(VALUE _PTRVALUE, int index, char *type) {
|
|||
char *s;
|
||||
VALUE obj;
|
||||
|
||||
Check_Type(_PTRVALUE, T_STRING);
|
||||
s = STR2CSTR(_PTRVALUE);
|
||||
if (SWIG_GetPtr(s,&ptr,0)) {
|
||||
rb_raise(rb_eTypeError,"Type error in ptrvalue. Argument is not a valid pointer value.");
|
||||
}
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* If no datatype was passed, try a few common datatypes first */
|
||||
|
||||
if (!type) {
|
||||
|
||||
/* No datatype was passed. Type to figure out if it's a common one */
|
||||
|
||||
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
|
||||
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||
type = "int";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||
type = "double";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||
type = "short";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||
type = "long";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||
type = "float";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||
type = "char";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"char_pp")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||
type = "char *";
|
||||
} else {
|
||||
type = "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
if (!ptr) {
|
||||
rb_raise(rb_eTypeError,"Unable to dereference NULL pointer.");
|
||||
}
|
||||
|
||||
/* Now we have a datatype. Try to figure out what to do about it */
|
||||
if (strcmp(type,"int") == 0) {
|
||||
obj = INT2NUM(*(((int *) ptr) + index));
|
||||
obj = LONG2NUM((long) *(((int *) ptr) + index));
|
||||
} else if (strcmp(type,"double") == 0) {
|
||||
obj = rb_float_new((double) *(((double *) ptr)+index));
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
obj = INT2NUM(*(((short *) ptr)+index));
|
||||
obj = LONG2NUM((long) *(((short *) ptr)+index));
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
obj = INT2NUM(*(((long *) ptr)+index));
|
||||
obj = LONG2NUM((long) *(((long *) ptr)+index));
|
||||
} else if (strcmp(type,"float") == 0) {
|
||||
obj = rb_float_new((double) *(((float *) ptr)+index));
|
||||
} else if (strcmp(type,"char") == 0) {
|
||||
|
|
@ -192,60 +175,63 @@ static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
|||
void *ptr;
|
||||
VALUE obj;
|
||||
int sz;
|
||||
char *cast;
|
||||
_swig_type_info *cast;
|
||||
char temp[40];
|
||||
|
||||
/* Check the type string against a variety of possibilities */
|
||||
|
||||
if (strcmp(type,"int") == 0) {
|
||||
sz = sizeof(int)*numelements;
|
||||
cast = "_int_p";
|
||||
cast = SWIG_POINTER_int_p;
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
sz = sizeof(short)*numelements;
|
||||
cast = "_short_p";
|
||||
cast = SWIG_POINTER_short_p;
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
sz = sizeof(long)*numelements;
|
||||
cast = "_long_p";
|
||||
cast = SWIG_POINTER_long_p;
|
||||
} else if (strcmp(type,"double") == 0) {
|
||||
sz = sizeof(double)*numelements;
|
||||
cast = "_double_p";
|
||||
cast = SWIG_POINTER_double_p;
|
||||
} else if (strcmp(type,"float") == 0) {
|
||||
sz = sizeof(float)*numelements;
|
||||
cast = "_float_p";
|
||||
cast = SWIG_POINTER_float_p;
|
||||
} else if (strcmp(type,"char") == 0) {
|
||||
sz = sizeof(char)*numelements;
|
||||
cast = "_char_p";
|
||||
cast = SWIG_POINTER_char_p;
|
||||
} else if (strcmp(type,"char *") == 0) {
|
||||
sz = sizeof(char *)*(numelements+1);
|
||||
cast = "char_pp";
|
||||
cast = SWIG_POINTER_char_pp;
|
||||
} else {
|
||||
rb_raise(rb_eTypeError,"Unable to create unknown datatype.");
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
|
||||
if (_RBVALUE) {
|
||||
if (strcmp(type,"int") == 0) {
|
||||
int *ip,i,ivalue;
|
||||
ivalue = NUM2INT(_RBVALUE);
|
||||
ivalue = (int) NUM2LONG(_RBVALUE);
|
||||
ip = (int *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
short *ip,ivalue;
|
||||
int i;
|
||||
ivalue = (short) NUM2INT(_RBVALUE);
|
||||
ivalue = (short) NUM2LONG(_RBVALUE);
|
||||
ip = (short *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
long *ip,ivalue;
|
||||
int i;
|
||||
ivalue = NUM2LONG(_RBVALUE);
|
||||
ivalue = (long) NUM2LONG(_RBVALUE);
|
||||
ip = (long *) ptr;
|
||||
for (i = 0; i < numelements; i++)
|
||||
ip[i] = ivalue;
|
||||
|
|
@ -275,7 +261,7 @@ static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
|||
ip = (char **) ptr;
|
||||
for (i = 0; i < numelements; i++) {
|
||||
if (ivalue) {
|
||||
ip[i] = (char *) xmalloc(strlen(ivalue)+1);
|
||||
ip[i] = (char *) malloc(strlen(ivalue)+1);
|
||||
strcpy(ip[i],ivalue);
|
||||
} else {
|
||||
ip[i] = 0;
|
||||
|
|
@ -286,8 +272,7 @@ static VALUE ptrcreate(char *type, VALUE _RBVALUE, int numelements) {
|
|||
}
|
||||
/* Create the pointer value */
|
||||
|
||||
SWIG_MakePtr(temp,ptr,cast);
|
||||
obj = rb_str_new2(temp);
|
||||
obj = SWIG_NewPointerObj(ptr,cast);
|
||||
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) {
|
||||
void *ptr;
|
||||
char *s;
|
||||
VALUE obj;
|
||||
|
||||
Check_Type(_PTRVALUE, T_STRING);
|
||||
s = STR2CSTR(_PTRVALUE);
|
||||
if (SWIG_GetPtr(s,&ptr,0)) {
|
||||
rb_raise(rb_eTypeError,"Type error in ptrset. Argument is not a valid pointer value.");
|
||||
}
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* If no datatype was passed, try a few common datatypes first */
|
||||
|
||||
if (!type) {
|
||||
|
||||
/* No datatype was passed. Type to figure out if it's a common one */
|
||||
|
||||
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
|
||||
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||
type = "int";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_double_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_double_p)) {
|
||||
type = "double";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_short_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_short_p)) {
|
||||
type = "short";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_long_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_long_p)) {
|
||||
type = "long";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_float_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_float_p)) {
|
||||
type = "float";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"_char_p")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_p)) {
|
||||
type = "char";
|
||||
} else if (!SWIG_GetPtr(s,&ptr,"char_pp")) {
|
||||
} else if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_char_pp)) {
|
||||
type = "char *";
|
||||
} else {
|
||||
type = "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
if (!ptr) {
|
||||
rb_raise(rb_eTypeError,"Unable to set NULL pointer.");
|
||||
}
|
||||
|
||||
/* Now we have a datatype. Try to figure out what to do about it */
|
||||
if (strcmp(type,"int") == 0) {
|
||||
*(((int *) ptr)+index) = NUM2INT(_RBVALUE);
|
||||
*(((int *) ptr)+index) = (int) NUM2LONG(_RBVALUE);
|
||||
} else if (strcmp(type,"double") == 0) {
|
||||
*(((double *) ptr)+index) = (double) NUM2DBL(_RBVALUE);
|
||||
} else if (strcmp(type,"short") == 0) {
|
||||
*(((short *) ptr)+index) = (short) NUM2INT(_RBVALUE);
|
||||
*(((short *) ptr)+index) = (short) NUM2LONG(_RBVALUE);
|
||||
} else if (strcmp(type,"long") == 0) {
|
||||
*(((long *) ptr)+index) = NUM2LONG(_RBVALUE);
|
||||
*(((long *) ptr)+index) = (long) NUM2LONG(_RBVALUE);
|
||||
} else if (strcmp(type,"float") == 0) {
|
||||
*(((float *) ptr)+index) = (float) NUM2DBL(_RBVALUE);
|
||||
} 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) {
|
||||
ca[index] = 0;
|
||||
} else {
|
||||
ca[index] = (char *) xmalloc(strlen(c)+1);
|
||||
ca[index] = (char *) malloc(strlen(c)+1);
|
||||
strcpy(ca[index],c);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -369,7 +345,6 @@ static VALUE ptrset(VALUE _PTRVALUE, VALUE _RBVALUE, int index, char *type) {
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
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) {
|
||||
|
||||
char *r,*s;
|
||||
char *r;
|
||||
void *ptr,*junk;
|
||||
VALUE obj;
|
||||
char *type;
|
||||
_swig_type_info *type;
|
||||
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* 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 */
|
||||
|
||||
if (!SWIG_GetPtr(s,&ptr,"_int_p")) {
|
||||
if (SWIG_CheckConvert(_PTRVALUE,SWIG_POINTER_int_p)) {
|
||||
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);
|
||||
} 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);
|
||||
} 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);
|
||||
} 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);
|
||||
} 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);
|
||||
} 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);
|
||||
type = SWIG_POINTER_char_pp;
|
||||
} else {
|
||||
rb_raise(rb_eTypeError,"Type error in ptradd. Argument is not a valid pointer value.");
|
||||
}
|
||||
type = SWIG_GetPtr(s,&junk,"INVALID POINTER");
|
||||
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);
|
||||
|
||||
obj = SWIG_NewPointerObj(ptr, type);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
@ -428,17 +397,13 @@ static VALUE ptradd(VALUE _PTRVALUE, int offset) {
|
|||
|
||||
Allows a mapping between type1 and type2. (Like a typedef)
|
||||
------------------------------------------------------------------ */
|
||||
|
||||
static void ptrmap(char *type1, char *type2) {
|
||||
|
||||
char *typestr1,*typestr2,*c,*r;
|
||||
|
||||
/* Produce a "mangled" version of the type string. */
|
||||
|
||||
typestr1 = (char *) xmalloc(strlen(type1)+2);
|
||||
typestr1 = (char *) malloc(strlen(type1)+2);
|
||||
|
||||
/* Go through and munge the typestring */
|
||||
|
||||
r = typestr1;
|
||||
*(r++) = '_';
|
||||
c = type1;
|
||||
|
|
@ -455,7 +420,7 @@ static void ptrmap(char *type1, char *type2) {
|
|||
}
|
||||
*(r++) = 0;
|
||||
|
||||
typestr2 = (char *) xmalloc(strlen(type2)+2);
|
||||
typestr2 = (char *) malloc(strlen(type2)+2);
|
||||
|
||||
/* Go through and munge the typestring */
|
||||
|
||||
|
|
@ -474,8 +439,12 @@ static void ptrmap(char *type1, char *type2) {
|
|||
c++;
|
||||
}
|
||||
*(r++) = 0;
|
||||
|
||||
/* Currently unsupported */
|
||||
/*
|
||||
SWIG_RegisterMapping(typestr1,typestr2,0);
|
||||
SWIG_RegisterMapping(typestr2,typestr1,0);
|
||||
*/
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
|
|
@ -485,17 +454,12 @@ static void ptrmap(char *type1, char *type2) {
|
|||
------------------------------------------------------------------ */
|
||||
|
||||
VALUE ptrfree(VALUE _PTRVALUE) {
|
||||
void *ptr, *junk;
|
||||
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.");
|
||||
}
|
||||
void *ptr;
|
||||
|
||||
ptr = SWIG_ConvertPtr(_PTRVALUE,0);
|
||||
|
||||
/* 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;
|
||||
if (c) {
|
||||
int i = 0;
|
||||
|
|
@ -504,7 +468,7 @@ VALUE ptrfree(VALUE _PTRVALUE) {
|
|||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (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
|
||||
// or the C representation. For example :
|
||||
//
|
||||
// ptrcast(ptr,"double_p"); # Ruby representation
|
||||
// ptrcast(ptr,"double_p"); # Ruby representation
|
||||
// ptrcast(ptr,"double *"); # C representation
|
||||
//
|
||||
// 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.
|
||||
|
||||
|
||||
%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)
|
||||
#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" {
|
||||
#endif
|
||||
|
||||
SWIGEXPORT(void) SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *));
|
||||
SWIGEXPORT(void) SWIG_MakePtr(char *_c, const void *_ptr, char *type);
|
||||
SWIGEXPORT(char *) SWIG_GetPtr(char *_c, void **ptr, char *_t);
|
||||
SWIGEXPORT(VALUE) SWIG_NewPointerObj(void *ptr, char *type);
|
||||
SWIGEXPORT(void *) SWIG_ConvertPtr(VALUE obj, char *type);
|
||||
SWIGEXPORT(void) SWIG_define_class(VALUE, _swig_type_info *)
|
||||
SWIGEXPORT(VALUE) SWIG_NewPointerObj(void *, _swig_type_info *);
|
||||
SWIGEXPORT(char *) SWIG_MangleStr(VALUE);
|
||||
SWIGEXPORT(void *) SWIG_ConvertPtr(VALUE, _swig_type_info *);
|
||||
SWIGEXPORT(int) SWIG_CheckConvert(VALUE, _swig_type_info *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,293 +3,84 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* SWIG pointer structure */
|
||||
|
||||
typedef struct SwigPtrType {
|
||||
char *name; /* Datatype name */
|
||||
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 */
|
||||
static VALUE _mSWIG = Qnil;
|
||||
static VALUE _cSWIG_Pointer = Qnil;
|
||||
|
||||
/* Define ruby class for C type */
|
||||
SWIGSTATICRUNTIME(void)
|
||||
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
|
||||
|
||||
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)
|
||||
SWIG_define_class(_swig_type_info *type)
|
||||
{
|
||||
unsigned long _p;
|
||||
char temp_type[256];
|
||||
char *name;
|
||||
int i, len;
|
||||
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;
|
||||
char *klass_name = ALLOCA_N(char, 4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
if (NIL_P(_cSWIG_Pointer)) {
|
||||
_cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
|
||||
}
|
||||
*ptr = (void *) 0;
|
||||
return _c;
|
||||
}
|
||||
rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
|
||||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
SWIGSTATICRUNTIME(VALUE)
|
||||
SWIG_NewPointerObj(void *ptr, char *type)
|
||||
SWIG_NewPointerObj(void *ptr, _swig_type_info *type)
|
||||
{
|
||||
char *temp = ALLOCA_N(char, strlen(type)+22);
|
||||
SWIG_MakePtr(temp, ptr, type);
|
||||
return rb_str_new2(temp);
|
||||
char *klass_name;
|
||||
VALUE klass;
|
||||
|
||||
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 *)
|
||||
SWIG_ConvertPtr(VALUE obj, char *type)
|
||||
/* Get type mangle from class name */
|
||||
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;
|
||||
Check_Type(obj, T_STRING);
|
||||
if (SWIG_GetPtr(RSTRING(obj)->ptr, &ptr, type)) {
|
||||
rb_raise(rb_eTypeError, "Expected a %s", type);
|
||||
_swig_type_info *tc;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue