4.3.1 - PUT_FREE causing warnings

Building sucks....Yet is so essential.
Post Reply
Posts: 1
Joined: Thu Feb 16, 2012 7:32 pm

4.3.1 - PUT_FREE causing warnings

Post by caboose » Thu Feb 16, 2012 8:09 pm

I have a modified 4.3.1 codebase that I've been running on an old server for a while. I want to upgrade, which makes a bit of cleaning necessary, as compiling 4.3.1 with newer versions of GCC vomits warnings with impunity.

I've dealt with most of these already, but one is giving me a headache, so I figured I'd put it out there to see if anyone has any ideas. PUT_FREE (defined in lists.h) is a pretty clever little preprocessor macro that's used all over the place:

Code: Select all

#define PUT_FREE(item, freelist) \
do { \
  if ( (item)->is_free ) { \
    bug("PUT_FREE: item is ALREADY FREE! Aborting...", 0); \
    abort(); \
  } \
  (item)->next = (freelist); \
  (item)->is_free = TRUE; /* This sets is_free flag */ \
  (freelist) = (item); \
  if (freelist##_destructor) freelist##_destructor(item); \
} while(0)
The problem is the second to last line which checks to make sure that the function (whatever)_destructor exists. Unfortunately, the compiler kicks out a warning for every time it DOES exist, but if you remove the check you get no warning and the MUD segfaults almost immediately. No, I don't just want to turn off the warning.

I'm afraid that I'm looking at the rather boring task of going through every PUT_FREE reference to check, by hand, whether the function exists or not, and having two versions of the macro, one with the check and the function call, and one without.

Any suggestions?

In case it matters: compiled on xubuntu 11.10 32-bit, gcc version 4.6.1. The specific error is "warning: the address of `note_free_destructor' will always evaluate as `true' [-Waddress]" although "note_free_destructor" could be replaced with any similar destructor function. Should repro with the GCC4-cleaned *chuckle* version of 4.3.1, although if memory serves, there are a few other issues with it as well.

User avatar
Site Admin
Posts: 122
Joined: Mon Oct 18, 2010 9:23 pm
Location: Illinois

Re: 4.3.1 - PUT_FREE causing warnings

Post by Kline » Wed Feb 22, 2012 4:06 pm

Hey sorry for the delayed reply. The freelist crap is actually one of the things I've been working hard at entirely removing. If you check the GitHub you can probably manually diff/patch in to see how (almost) all lists have been converted to the STL.

I'm currently working in the 'Thing' branch with a large overhaul of a lot of systems like that. It's "stable" as of my final commit last night and has I think only one legacy "list" remaining in it. PUT/GET_FREE is a horrible system in a modern world. I'd love to roll up any bug fixes or enhancements you have to either branch if you roll a fork on GitHub and submit a pull request :)

Post Reply