apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Marr <gr...@alum.wpi.edu>
Subject Re: APR_ARRAY_FOO convenience macros
Date Tue, 16 Aug 2005 20:49:00 GMT
At 12:08 PM 8/16/2005, Garrett Rooney wrote:
>William A. Rowe, Jr. wrote:
>>At 09:24 PM 8/15/2005, Garrett Rooney wrote:
>>
>>>So back in Dec 2003 Sander Striker suggested [1] adding 
>>>Subversion's macros for manipulating apr arrays (APR_ARRAY_IDX, 
>>>which automates the casting needed to access entries in the array, 
>>>and APR_ARRAY_PUSH, which automates the casting needed to add 
>>>entries to the array) to apr_tables.h.  Roy Fielding commented [2] 
>>>that he felt the macros tied the interface to the implementation 
>>>too much, and Greg Stein replied [3] that they had to be done as 
>>>macros, not functions, because of the need to pass a type name for
>>>the cast.
>>
>>IIUC, these are not typesafe?
>>See the apr optional function and hook apis for true typesafe
>>casts.
>
>I must be missing something, but I don't see how these macros could 
>be implemented in a more typesafe way.  Could you elaborate?
>
>The hooks code appears to be a means to store arbitrary functions 
>and then retrieve them later, are you suggesting that separate 
>functions for manipulating each type of array be created dynamically 
>or something?  I guess I'm just failing to see how such a thing 
>would really work in practice, or I'm just misunderstanding what 
>you're suggesting.

True, they're not typesafe, because you can put the wrong type in the 
macro.  The big difference is what was seen in the broken commit, 
doing the casts yourselves hides any errors you might make by 
accessing the wrong element of the array structure.  The macros only 
have to get the casts right once.  Not using the macros means that 
every place in the code needs to get the casts right.


Mime
View raw message