Tue 28 Jul 2009 01:46:28 PM UTC, comment #5:
#define mem_realloc(x,y) (x) does work.
The code actually used this but was changed in response to issue #23254, which wanted the mem_ macros to reference function pointers rather than function-like macros. This was apparently to allow the function pointers to be passed around in messages.
If a pointer to mem_realloc needs to be passed in messages, a dummy function that does nothing but return the pointer given should be implemented. But lwIP itself doesn't do this. The only place mem_realloc is used is when it's called by pbuf_realloc.
I have to strongly disagree with the statement that not making the change is low risk. I only discovered this bug it happened to me. And our compiler's library is from Dinkumware, whose libraries are widely used.
Moving the payload pointer won't work because with RAM pbuf types, the pbuf and the payload are one. This is the whole reason that the code can't use realloc. When the memory is reallocated, the pbuf pointer moves, but pbuf_realloc does not return a pointer to the new pbuf.
I think the cleanest solution would be to have pbuf_realloc return a pointer to the new pbuf.
But for 1.3.1, I think the best idea is to roll back to the pre-#23254 definition since it works. The change was made as a convenience, but isn't required by lwIP.
|