[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
patch for compatible syntax with C++
From: |
Cristobal Castillo |
Subject: |
patch for compatible syntax with C++ |
Date: |
Tue, 27 Jul 2004 09:18:40 +0200 |
User-agent: |
Mozilla Thunderbird 0.7.2 (Windows/20040707) |
I am working with Objectice-C and C++, and also working with non-gnu
compilers.
I have a problem with libobjc library, since it does not have compatible
syntax with C++.
Problems found and solved are listed below, a patch is proposed to
consider merging it
with current source code base.
1) Class is a keyword in C++, but it is used as variable name in several
places. I think these
changes have been done already for Objective-C++ GCC frontend.
Example:
- Method_t class_get_instance_method(Class class, SEL aSel);
+ Method_t class_get_instance_method(Class CLASS, SEL aSel);
2) Void pointer arithmetic does not work with some compilers (it has
been substituted by
char pointer arithmetic). Example:
hash_string (cache_ptr cache, const void *key)
while (*(char *) key) {
ret^= *(char *) key++ << ctr;
ctr = (ctr + 1) % sizeof (void *);
}
3) Definition inside definitions in objc_method_list, the redefinition
of objc_method in objc_method_list.
------------------------------------
I'm not subscribed to GCC list, if you respond this mail please cc to
cristobal.castillo@tragnarion.com
Index: objc/hash.h
===================================================================
--- objc/hash.h (revision 223)
+++ objc/hash.h (revision 228)
@@ -173,9 +173,10 @@
unsigned int ret = 0;
unsigned int ctr = 0;
+ char *ptr = (char *)key;
- while (*(char *) key) {
- ret ^= *(char *) key++ << ctr;
+ while (*ptr) {
+ ret ^= *ptr++ << ctr;
ctr = (ctr + 1) % sizeof (void *);
}
@@ -187,7 +188,7 @@
static inline int
compare_ptrs (const void *k1, const void *k2)
{
- return ! (k1 - k2);
+ return ! ((char*)k1 - (char*)k2);
}
@@ -200,7 +201,7 @@
else if (k1 == 0 || k2 == 0)
return 0;
else
- return ! strcmp (k1, k2);
+ return ! strcmp ((char*)k1, (char*)k2);
}
Index: objc/objc-api.h
===================================================================
--- objc/objc-api.h (revision 223)
+++ objc/objc-api.h (revision 228)
@@ -202,7 +202,7 @@
/*
-** The compiler generates one of these structures for a class that has
+** The compiler generates one of these structures for a CLASS that has
** instance variables defined in its specification.
*/
typedef struct objc_ivar* Ivar_t;
@@ -236,15 +236,7 @@
** and categories can break them across modules. To handle this problem is a
** singly linked list of methods.
*/
-typedef struct objc_method Method;
-typedef Method* Method_t;
-typedef struct objc_method_list {
- struct objc_method_list* method_next; /* This variable is used to link
- a method list to another. It
- is a singly linked list. */
- int method_count; /* Number of methods defined in
- this structure. */
- struct objc_method {
+typedef struct objc_method {
SEL method_name; /* This variable is the method's
name. It is a char*.
The unique integer passed to
@@ -256,7 +248,18 @@
debuggers. */
IMP method_imp; /* Address of the method in the
executable. */
- } method_list[1]; /* Variable length
+ } Method;
+
+
+
+typedef Method* Method_t;
+typedef struct objc_method_list {
+ struct objc_method_list* method_next; /* This variable is used to link
+ a method list to another. It
+ is a singly linked list. */
+ int method_count; /* Number of methods defined in
+ this structure. */
+ Method method_list[1]; /* Variable length
structure. */
} MethodList, *MethodList_t;
@@ -343,7 +346,11 @@
typedef struct objc_super {
id self; /* Id of the object sending
the message. */
+#ifndef __cplusplus
Class class; /* Object's super class. */
+#else
+ Class class_super;
+#endif
} Super, *Super_t;
IMP objc_msg_lookup_super(Super_t super, SEL sel);
@@ -366,12 +373,12 @@
** dynamic loader determine the classes that have been loaded when
** an object file is dynamically linked in.
*/
-objc_EXPORT void (*_objc_load_callback)(Class class, Category* category);
+objc_EXPORT void (*_objc_load_callback)(Class CLASS, Category* category);
/*
** Hook functions for allocating, copying and disposing of instances
*/
-objc_EXPORT id (*_objc_object_alloc)(Class class);
+objc_EXPORT id (*_objc_object_alloc)(Class CLASS);
objc_EXPORT id (*_objc_object_copy)(id object);
objc_EXPORT id (*_objc_object_dispose)(id object);
@@ -423,9 +430,9 @@
*/
objc_EXPORT IMP (*__objc_msg_forward)(SEL);
-Method_t class_get_class_method(MetaClass class, SEL aSel);
+Method_t class_get_class_method(MetaClass CLASS, SEL aSel);
-Method_t class_get_instance_method(Class class, SEL aSel);
+Method_t class_get_instance_method(Class CLASS, SEL aSel);
Class class_pose_as(Class impostor, Class superclass);
@@ -454,66 +461,66 @@
BOOL sel_is_mapped (SEL aSel);
-extern id class_create_instance(Class class);
+extern id class_create_instance(Class CLASS);
static inline const char *
-class_get_class_name(Class class)
+class_get_class_name(Class CLASS)
{
- return CLS_ISCLASS(class)?class->name:((class==Nil)?"Nil":0);
+ return CLS_ISCLASS(CLASS)?CLASS->name:((CLASS==Nil)?"Nil":0);
}
static inline long
-class_get_instance_size(Class class)
+class_get_instance_size(Class CLASS)
{
- return CLS_ISCLASS(class)?class->instance_size:0;
+ return CLS_ISCLASS(CLASS)?CLASS->instance_size:0;
}
static inline MetaClass
-class_get_meta_class(Class class)
+class_get_meta_class(Class CLASS)
{
- return CLS_ISCLASS(class)?class->class_pointer:Nil;
+ return CLS_ISCLASS(CLASS)?CLASS->class_pointer:Nil;
}
static inline Class
-class_get_super_class(Class class)
+class_get_super_class(Class CLASS)
{
- return CLS_ISCLASS(class)?class->super_class:Nil;
+ return CLS_ISCLASS(CLASS)?CLASS->super_class:Nil;
}
static inline int
-class_get_version(Class class)
+class_get_version(Class CLASS)
{
- return CLS_ISCLASS(class)?class->version:-1;
+ return CLS_ISCLASS(CLASS)?CLASS->version:-1;
}
static inline BOOL
-class_is_class(Class class)
+class_is_class(Class CLASS)
{
- return CLS_ISCLASS(class);
+ return CLS_ISCLASS(CLASS);
}
static inline BOOL
-class_is_meta_class(Class class)
+class_is_meta_class(Class CLASS)
{
- return CLS_ISMETA(class);
+ return CLS_ISMETA(CLASS);
}
static inline void
-class_set_version(Class class, long version)
+class_set_version(Class CLASS, long version)
{
- if (CLS_ISCLASS(class))
- class->version = version;
+ if (CLS_ISCLASS(CLASS))
+ CLASS->version = version;
}
static inline void *
-class_get_gc_object_type (Class class)
+class_get_gc_object_type (Class CLASS)
{
- return CLS_ISCLASS(class) ? class->gc_object_type : NULL;
+ return CLS_ISCLASS(CLASS) ? CLASS->gc_object_type : NULL;
}
/* Mark the instance variable as innaccessible to the garbage collector */
-extern void class_ivar_set_gcinvisible (Class class,
+extern void class_ivar_set_gcinvisible (Class CLASS,
const char* ivarname,
BOOL gcInvisible);
@@ -523,7 +530,7 @@
return (method!=METHOD_NULL)?method->method_imp:(IMP)0;
}
-IMP get_imp (Class class, SEL sel);
+IMP get_imp (Class CLASS, SEL sel);
/* Redefine on NeXTSTEP so as not to conflict with system function */
#ifdef __NeXT__
@@ -582,7 +589,7 @@
static inline BOOL
object_is_class (id object)
{
- return ((object != nil) && CLS_ISMETA (object->class_pointer));
+ return ((object != nil) && CLS_ISMETA (object->class_pointer) &&
CLS_ISCLASS((Class)object));
}
static inline BOOL
- patch for compatible syntax with C++,
Cristobal Castillo <=