logo       

PATCH: add malloc function attribute to rts malloc functions: msg#00048

lang.haskell.glasgow.bugs

Subject: PATCH: add malloc function attribute to rts malloc functions

http://gcc.gnu.org/onlinedocs/gcc-3.3.3/gcc/Function-Attributes.html
The gcc manual says:

malloc
The malloc attribute is used to tell the compiler that a
function may be treated as if it were the malloc function. The
compiler assumes that calls to malloc result in pointers that
cannot alias anything. This will often improve optimization.

Note the malloc attribute has only been around since gcc 3.xx, hence the
extra GNUC3_ATTRIBUTE that tests for gcc version >= 3.

So I guess it can't hurt and might even help. It even compiles! (as is
running make in the rts directory does not fail - I've not done a full
build.)

Index: ghc/rts/RtsUtils.h
===================================================================
RCS file: /cvs/fptools/ghc/rts/RtsUtils.h,v
retrieving revision 1.20
diff -C2 -r1.20 RtsUtils.h
*** ghc/rts/RtsUtils.h 26 Feb 2004 16:36:21 -0000 1.20
--- ghc/rts/RtsUtils.h 22 Mar 2004 17:02:07 -0000
***************
*** 12,18 ****

/* (Checked) dynamic allocation: */
! extern void *stgMallocBytes(int n, char *msg);
extern void *stgReallocBytes(void *p, int n, char *msg);
! extern void *stgCallocBytes(int n, int m, char *msg);
extern void stgFree(void* p);

--- 12,18 ----

/* (Checked) dynamic allocation: */
! extern void *stgMallocBytes(int n, char *msg) GNUC3_ATTRIBUTE(__malloc__);
extern void *stgReallocBytes(void *p, int n, char *msg);
! extern void *stgCallocBytes(int n, int m, char *msg)
GNUC3_ATTRIBUTE(__malloc__);
extern void stgFree(void* p);


Index: ghc/includes/Stg.h
===================================================================
RCS file: /cvs/fptools/ghc/includes/Stg.h,v
retrieving revision 1.61
diff -C2 -r1.61 Stg.h
*** ghc/includes/Stg.h 8 Mar 2004 10:27:22 -0000 1.61
--- ghc/includes/Stg.h 22 Mar 2004 17:01:50 -0000
***************
*** 89,92 ****
--- 89,98 ----
#endif

+ #if __GNUC__ >= 3
+ #define GNUC3_ATTRIBUTE(at) __attribute__((at))
+ #else
+ #define GNUC3_ATTRIBUTE(at)
+ #endif
+
/*
* Empty structures isn't supported by all, so to define


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise