|
From: Martin R. <ru...@us...> - 2004-08-09 01:47:44
|
Update of /cvsroot/foo/foo/elkfoo/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29000 Modified Files: pointer.m Added Files: types.m Log Message: added missing new types.m, fixed cast warning Index: pointer.m =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/src/pointer.m,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** pointer.m 9 Aug 2004 01:42:05 -0000 1.6 --- pointer.m 9 Aug 2004 01:47:34 -0000 1.7 *************** *** 184,188 **** { SchemeObject result, pointer; ! int offset = 0, items = 1, type, addr, i; GC_Node; --- 184,189 ---- { SchemeObject result, pointer; ! int offset = 0, items = 1, type, i; ! void *addr; GC_Node; *************** *** 192,196 **** GC_Link(pointer); type = POINTER_T(pointer)->type.data; ! addr = (int)POINTER_T(pointer)->pointer; if (argc > 1) --- 193,197 ---- GC_Link(pointer); type = POINTER_T(pointer)->type.data; ! addr = POINTER_T(pointer)->pointer; if (argc > 1) --- NEW FILE: types.m --- /* * types.m * * map ObjC types to elkfoo_types * convert types from SchemeObject to buffer and back * */ /* * foo sound synthesis system * * (C)1993-2004 Gerhard Eckel, Ramon Gonzalez-Arroyo, IRCAM, ZKM * (C)2003-2004 Martin Rumori */ /* * This file is part of foo. * * foo free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * foo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with foo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef NeXT_RUNTIME #import <objc/objc-runtime.h> #elif GNU_RUNTIME #include <objc/objc-api.h> #else #error *** NEITHER NeXT NOR GNU RUNTIME PRESENT *** #endif #define Object SchemeObject /* avoid Obj-C type clash */ #ifdef HAVE_FOOELK_SCHEME_H #include <fooelk/scheme.h> #else #include <elk/scheme.h> #endif #undef Object #include "elkfoo.h" #define SKIP_BODY(p, c) \ while (*p != c) \ { \ if (! *p++) \ { \ Primitive_Error("malformed objC pointer type could not be mapped"); \ break; \ } \ } elkfoo_type_t A_Map_ObjC_Type (const char *objCtype) { while (1) { switch (*objCtype) { /* the Apple runtime seems to use 'r' in order to indicate * the 'const' qualifier */ case 'r' : ++objCtype; continue; case '\0': return C_base; case _C_ID: return C_ID; case _C_CLASS: return C_CLASS; case _C_SEL: return C_SEL; case _C_CHR: return C_char; case _C_UCHR: return C_unsigned_char; case _C_SHT: return C_short; case _C_USHT: return C_unsigned_short; case _C_INT: return C_int; case _C_UINT: return C_unsigned_int; case _C_LNG: return C_long; case _C_ULNG: return C_unsigned_long; case _C_FLT: return C_float; case _C_DBL: return C_double; case _C_VOID: return C_VOID; case _C_UNDEF: return C_undef; case _C_CHARPTR: return C_CHAR; case _C_STRUCT_B: Primitive_Error("objCtype struct could not be mapped"); break; case _C_PTR: ++objCtype; switch (*objCtype) { case '\0': Primitive_Error("malformed objC pointer type could not be mapped"); break; case _C_CHR: return C_CHAR; case _C_UCHR: return C_UNSIGNED_CHAR; case _C_SHT: return C_SHORT; case _C_USHT: return C_UNSIGNED_SHORT; case _C_INT: return C_INT; case _C_UINT: return C_UNSIGNED_INT; case _C_LNG: return C_LONG; case _C_ULNG: return C_UNSIGNED_LONG; case _C_FLT: return C_FLOAT; case _C_DBL: return C_DOUBLE; case _C_VOID: return C_VOID; case _C_UNDEF: return C_UNDEF; case _C_CHARPTR: return C_CHARPTR; case _C_ARY_B: SKIP_BODY(objCtype, _C_ARY_E) return C_ARRAY; case _C_UNION_B: SKIP_BODY(objCtype, _C_UNION_E) return C_UNION; case _C_STRUCT_B: SKIP_BODY(objCtype, _C_STRUCT_E) return C_STRUCT; case _C_ARY_E: case _C_UNION_E: case _C_STRUCT_E: Primitive_Error("malformed objC [array|union|struct] pointer type could not be mapped"); break; default: Primitive_Error("malformed objC pointer type could not be mapped"); } /* NOTREACHED */ case _C_ARY_B: case _C_UNION_B: case _C_ARY_E: case _C_UNION_E: case _C_STRUCT_E: default: Primitive_Error("malformed objC type could not be mapped"); } /* NOTREACHED */ } return 0; /* in order to avoid compiler warning */ } int A_Get_Buffer_From_Object (void *valbuf, SchemeObject arg, elkfoo_type_t etype) { void *ret; switch (etype) { case C_char: { *(char *)valbuf = Get_Integer(arg); break; } case C_short: { *(short *)valbuf = Get_Integer(arg); break; } case C_int: { *(int *)valbuf = Get_Integer(arg); break; } case C_long: { *(long *)valbuf = Get_Integer(arg); break; } case C_unsigned_char: { *(unsigned char *)valbuf = Get_Integer(arg); break; } case C_unsigned_short: { *(unsigned short *)valbuf = Get_Integer(arg); break; } case C_unsigned_int: { *(unsigned int *)valbuf = Get_Integer(arg); break; } case C_unsigned_long: { *(unsigned long *)valbuf = Get_Integer(arg); break; } case C_float: { *(float *)valbuf = Get_Double(arg); break; } case C_double: { *(double *)valbuf = Get_Double(arg); break; } case C_CHAR: { /* attention: here just the pointer is set in valbuf. * when constructing a NSInvocation with more than * 3 string args, we've got a problem */ *(char **)valbuf = Get_String(arg); break; } case C_VOID: case C_SHORT: case C_INT: case C_LONG: case C_UNSIGNED_CHAR: case C_UNSIGNED_SHORT: case C_UNSIGNED_INT: case C_UNSIGNED_LONG: case C_FLOAT: case C_DOUBLE: case C_ID: case C_CLASS: case C_SEL: case C_STRUCT: case C_UNION: case C_ARRAY: case C_CHARPTR: case C_UNDEF: Check_Type(arg, T_Pointer); if (POINTER_T(arg)->pointer != NULL && POINTER_T(arg)->type.data != etype) { return 1; } else { *(void **)valbuf = (void *)(POINTER_T(arg)->pointer); } break; default: return 1; } return 0; } SchemeObject A_Get_Object_From_Buffer (void *arg, elkfoo_type_t etype) { switch (etype) { case C_char: return Make_Integer(*(char *)arg); case C_short: return Make_Integer(*(short *)arg); case C_int: return Make_Integer(*(int *)arg); case C_long: return Make_Integer(*(long *)arg); case C_unsigned_char: return Make_Unsigned(*(char *)arg); case C_unsigned_short: return Make_Unsigned(*(short *)arg); case C_unsigned_int: return Make_Unsigned(*(int *)arg); case C_unsigned_long: return Make_Unsigned(*(long *)arg); case C_float: return Make_Reduced_Flonum(*(float *)arg); case C_double: return Make_Reduced_Flonum(*(double *)arg); case C_undef: return Make_Reduced_Flonum(*(int *)arg); case C_CHAR: if (arg == NULL) { return False; } else { return Make_String(*(char **)arg, strlen(*(char **)arg)); } case C_VOID: case C_SHORT: case C_INT: case C_LONG: case C_UNSIGNED_CHAR: case C_UNSIGNED_SHORT: case C_UNSIGNED_INT: case C_UNSIGNED_LONG: case C_FLOAT: case C_DOUBLE: case C_ID: case C_CLASS: case C_SEL: case C_STRUCT: case C_UNION: case C_ARRAY: case C_CHARPTR: case C_UNDEF: if ((void *)arg == NULL) { return Null_Pointer; } else { return A_Make_Pointer(*(void **)arg, etype); } } return Null; } |