[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gap-dev-discuss] Cythiune : fix badly written macros causing nasty
From: |
Philippe Roussel |
Subject: |
Re: [Gap-dev-discuss] Cythiune : fix badly written macros causing nasty crashes |
Date: |
Thu, 17 May 2012 15:09:53 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 |
Le 17/05/2012 15:04, Philippe Roussel a écrit :
> Le 17/05/2012 14:51, Riccardo Mottola a écrit :
>> Hi,
>>
>> I think there is no problem releasing a nil object (small speed penalty
>> which, seen the size of Cynthiune is unimportant.
>>
>> I don't like these macros, but I don0't see whileyou rewrite them in
>> such a funny way.
>>
>> Stuff like that is written in base is:
>>
>> #define TEST_RELEASE(object) ({\
>> id __object = (object); if (__object != nil) [__object release]; })
>> #endif
>>
>> #define ASSIGN(object,value) ({\
>> id __object = object; \
>> object = [(value) retain]; \
>> [__object release]; \
>> })
>> #endif
>
> And yes, this version is better because the macro argument is only
> evaluated once.
Simplest patch :
Index: Frameworks/Cynthiune/utils.h
===================================================================
RCS file:
/sources/gap/gap/user-apps/Cynthiune/Frameworks/Cynthiune/utils.h,v
retrieving revision 1.2
diff -u -r1.2 utils.h
--- Frameworks/Cynthiune/utils.h 30 Apr 2012 15:54:30 -0000 1.2
+++ Frameworks/Cynthiune/utils.h 17 May 2012 13:09:06 -0000
@@ -30,8 +30,8 @@
@class NSArray;
-#define SET(X,Y) if (X) [X release]; X = Y; if (X) [X retain]
-#define RELEASEIFSET(X) if (X) [X release]
+#define SET(X,Y) ASSIGN(X,Y)
+#define RELEASEIFSET(X) RELEASE(X)
#define RETURNSTRING(X) return ((X) ? [NSString stringWithString: X] : @"")
#ifdef __MACOSX__