From: Lyle J. <ly...@us...> - 2002-03-28 14:32:35
|
Update of /cvsroot/fxruby/FXRuby/ext/fox In directory usw-pr-cvs1:/tmp/cvs-serv4084 Modified Files: librb.c Log Message: Index: librb.c =================================================================== RCS file: /cvsroot/fxruby/FXRuby/ext/fox/librb.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** librb.c 19 Mar 2002 17:16:27 -0000 1.5 --- librb.c 28 Mar 2002 14:32:31 -0000 1.6 *************** *** 368,371 **** --- 368,449 ---- } + /* Pack binary data into a string */ + SWIGRUNTIME(char *) + SWIG_PackData(char *c, void *ptr, int sz) { + static char hex[17] = "0123456789abcdef"; + int i; + unsigned char *u = (unsigned char *) ptr; + register unsigned char uu; + for (i = 0; i < sz; i++,u++) { + uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; + } + + /* Unpack binary data from a string */ + SWIGRUNTIME(char *) + SWIG_UnpackData(char *c, void *ptr, int sz) { + register unsigned char uu; + register int d; + unsigned char *u = (unsigned char *) ptr; + int i; + for (i = 0; i < sz; i++, u++) { + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu = ((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = ((d - ('a'-10)) << 4); + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (d - ('a'-10)); + *u = uu; + } + return c; + } + + SWIGRUNTIME(VALUE) + SWIG_NewPackedObj(void *ptr, int sz, swig_type_info *type) { + char result[1024]; + char *r = result; + if ((2*sz + 1 + strlen(type->name)) > 1000) return 0; + *(r++) = '_'; + r = SWIG_PackData(r, ptr, sz); + strcpy(r, type->name); + return rb_str_new2(result); + } + + /* Convert a packed value value */ + SWIGRUNTIME(void) + SWIG_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) { + swig_type_info *tc; + char *c; + + if (TYPE(obj) != T_STRING) goto type_error; + c = STR2CSTR(obj); + /* Pointer values must start with leading underscore */ + if (*c != '_') goto type_error; + c++; + c = SWIG_UnpackData(c, ptr, sz); + if (ty) { + tc = SWIG_TypeCheck(c, ty); + if (!tc) goto type_error; + } + return; + + type_error: + + if (flags) { + if (ty) { + rb_raise(rb_eTypeError, "Type error. Expected %s", ty->name); + } else { + rb_raise(rb_eTypeError, "Expected a pointer"); + } + } + } + #ifdef __cplusplus } |