Adam Nemcek created PROTON-726:
----------------------------------

             Summary: Macros to wrap malloc(), realloc(), free()
                 Key: PROTON-726
                 URL: https://issues.apache.org/jira/browse/PROTON-726
             Project: Qpid Proton
          Issue Type: Wish
          Components: proton-c
    Affects Versions: 0.8
            Reporter: Adam Nemcek
            Priority: Trivial


As we are porting ProtonC across various platforms, we take the trunk code and 
use it in a specific project. I would like to be able to take any newer version 
from SVN and use it, without the need to modify it each every time, to suit the 
target system specifics.
Therefore, I would like to kindly ask for an official support of macros to 
replace the memory allocation functions.

Create a single global header file (or reuse some existing one, like the  
platform.h), and add a three new macros to it.
Having macros in place of general malloc(), realloc() and free() calls, will 
allow to keep the ported version easily update-able when new ProtonC version 
comes out (there won't be no need to manually go through all the files and 
replacing the calls with other calls).

For Linux (or Windows), the macros will directly link to the default functions.
For other OS(es), the developer will be able to just rewrite three lines of 
code and be all set.

Example:
{{pn_buffer_t *buf = (pn_buffer_t *)malloc(sizeof(pn_buffer_t));}}
will get replaced with something like this
{{pn_buffer_t *buf = (pn_buffer_t *)MALLOC_MACRO(sizeof(pn_buffer_t));}}
where (for Linux) it will be:
{{#define MALLOC_MACRO malloc}}
or for other OS it might then be:
{{#define MALLOC_MACRO customMalloc}}

Of course, I do not care about the naming of the macros, or the actual code 
style. 
I will leave all this on the official developers, I just ask to get such a 
functionality in.
This change should have no impact on functionality, code size or speed.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to