[reSIProcate] Conditional compile should not change object sizes

Dennis Dupont ddupont at intelemedia.com
Wed Apr 13 14:40:56 CDT 2005


I have been hit by this twice now:  
 
There are header files that define classes with different sizes based
upon 
conditional compilation.  The preprocessor macros are set by choices in 
build/Makefile.conf.   In particular for today's svn version, these
include
USE_IPV6 and RESIP_DATA_LOCAL_SIZE.
 
If application code uses the header files without defining the macros 
identically, then instances of the class (and any that are compositions
with
that class) can be of different sizes in the library and application.
The net 
result of this size difference is that the application's calling code
will have its 
memory corrupted since it is not allocating the size the library
expects.
 
An example:
 
class TransportSelector 
{
...
 
private:
...
 
#ifdef USE_IPV6
      struct sockaddr_in6 mUnspecified6;
#endif
}

So now if the application fails to define USE_IPV6, TransportSelector is
28
bytes shorter from the application's perspective than the library's --
and so is
TransportController and SipStack, etc.
 
It appears somebody tried to address this with the ApiCheck and
ApiCheckList
classes.  However, the only way to use them would be to pass each
possibly
affected class and its size to the ApiCheck class, something cumbersome
and
not very robust in terms of keeping up with library changes.
 
I think a longer term solution would be to make TransportSelector an
interface
class (only pure virtual methods), and use a TransportSelectorFactory
that
could be conditionally compiled to instantiate the correct
implementation
class.  This of course has the problem of breaking value semantics
(sigh).
 
 
Dennis Dupont
Senior Systems Architect
Intelemedia Communications, Inc.
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20050413/5f47d7b5/attachment.htm>


More information about the resiprocate-devel mailing list