[openssl-project] inline functions

Richard Levitte levitte at openssl.org
Mon Jan 28 04:16:18 UTC 2019



Dr Paul Dale <paul.dale at oracle.com> skrev: (27 januari 2019 23:18:06 CET)
>Isn’t this going to run into the same issues?

No. It's the expansion of the macros that causes the problem, not the macros themselves. So if you move the expansions to the .c that actually use stacks / lhashes, they should obviously be linked with libcrypto, problem solved. 

>The DEFINE_ expansions need to be in their own .c file (one file with
>all or one file per, I’m not fussed much but the latter seems nicer).

Not really, since they are static inline. This is by design, that for any file you want to use a safestack in, you just start with a DEFINE_ line. The mistake we did was to leave a few common ones in the safestack header file. (same thing for lhash) 

>The DEFINE_ macros need to stay in the header for compatibility.

Yup. 

>To handle the external linkage, a new macro that declares the function
>prototypes should be introduced.  I.e.:

Again, no need because of the static nature of the resulting inline functions. 

>
># define DECLARE_LHASH_OF(type) \
>LHASH_OF(type) * ln_##type##_new(unsigned long (*)(const type *), int
>(*)(const type *, const type *)); \
>    void lh_##type##_free(LHASH_OF(type) *); \
>>
># define DEFINE_LHASH_OF(type) \
>    DECLARE LHASH_OF(type); \
>LHASH_OF(type) { union lh_##type##_dummy { void* d1; unsigned long d2;
>int d3; } dummy; }; \
>    static ossl_inline LHASH_OF(type) * \
>        lh_##type##_new(unsigned long (*hfn)(const type *), \
>                        int (*cfn)(const type *, const type *)) \
>    { \
>        return (LHASH_OF(type) *) \
>  OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \
>    } \
>    static ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \
>    { \
>        OPENSSL_LH_free((OPENSSL_LHASH *)lh); \
>    } \
>>
>The headers can then use the DECLARE_LHASH_OF macro to prototype the
>functions.  The .c file uses the DEFINE_LHASH_OF macro to create them.
>
>I chose lhash here because it is the simpler of the two, safestack has
>more options and is a bit more convoluted.  I’m willing to make a stab
>at a PR for this.
>
>
>Pauli

-- 
Skickat från min Android-enhet med K-9 Mail. Ursäkta min fåordighet.


More information about the openssl-project mailing list