home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / linux / 17462 < prev    next >
Encoding:
Text File  |  1992-11-21  |  2.0 KB  |  67 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!ehsn11.cen.uiuc.edu!jy10033
  3. From: jy10033@ehsn11.cen.uiuc.edu (Joshua M Yelon)
  4. Subject: Re: malloc (0) ( Re: function-->macro bugs.)
  5. Message-ID: <By2x3p.8zu@news.cso.uiuc.edu>
  6. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  7. Organization: University of Illinois at Urbana
  8. Date: Sat, 21 Nov 1992 18:38:12 GMT
  9. Lines: 56
  10.  
  11. Well, recent discussion has revealed that it IS correct (according
  12. to POSIX) to turn malloc into a macro. (I had asserted the opposite).
  13.  
  14. On the other hand, this behavior is clearly breaking a lot of
  15. programs.  Many programmers seem to assume that a function is a
  16. function, not a macro.  According to POSIX, that assumption is
  17. wrong...  but on the other hand, it _is_ a natural assumption, and one
  18. that is supported by other operating systems.  Perhaps we should treat
  19. it as a 'de-facto standard' - not written into POSIX, but something
  20. that programmers frequently and intuitively rely upon, and therefore
  21. worth supporting...
  22.  
  23. On a separate note:
  24.  
  25. Here's another possible solution to the MALLOC problem:
  26.  
  27. #ifdef FIX_MALLOC
  28. static inline void *malloc(n)
  29.     size_t n; /* thanks Lars :-) */
  30.     {
  31.     return __fixed_malloc(n);
  32.     }
  33. #endif
  34.  
  35. Lars says that that's formally incorrect... but in practice, it works fine,
  36. and it doesn't break this:
  37.  
  38.     void *malloc();
  39.  
  40. or this:
  41.  
  42.     void (*allocator)() = malloc;
  43.  
  44. it does break this:
  45.  
  46.     /* my super-fast allocator */
  47.     void *malloc(n)
  48.     ...
  49.  
  50. but only if you explicitly put FIX_MALLOC in the program.
  51.  
  52. So that's a "2 1/2 out of 3" solution... anybody care to go for 3 out of 3?
  53.  
  54. Incidentally, notice that I used
  55.  
  56. #ifdef FIX_MALLOC
  57.  
  58. instead of
  59.  
  60. #ifndef NO_FIX_MALLOC
  61.  
  62. When I was compiling 'emacs', the "fix malloc" code confused it -
  63. but emacs didn't ask for any malloc fixes!  Neither did it need any.
  64. The moral? Since "tricky fixes" like that one are ugly hacks, they
  65. tend to be buggy, and they tend to break.  It's better to leave
  66. them OFF by default until you discover that you really need them.
  67.