[openssl-project] inline functions

Dr Paul Dale paul.dale at oracle.com
Sun Jan 27 22:18:06 UTC 2019


Isn’t this going to run into the same issues?

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).

The DEFINE_ macros need to stay in the header for compatibility.  To handle the external linkage, a new macro that declares the function prototypes should be introduced.  I.e.:

# 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
-- 
Dr Paul Dale | Cryptographer | Network Security & Encryption 
Phone +61 7 3031 7217
Oracle Australia



> On 28 Jan 2019, at 4:56 am, Richard Levitte <levitte at openssl.org> wrote:
> 
> On Sun, 27 Jan 2019 18:51:58 +0100,
> Viktor Dukhovni wrote:
>> 
>>> On Jan 27, 2019, at 5:33 AM, Tim Hudson <tjh at openssl.org> wrote:
>>> 
>>> Tim - I think inline functions in public header files simply shouldn't be present.
>> 
>> I think they have their place, and we should try to make them more portable
>> to less capable toolchains as needed.
> 
> A simple way to handle it is to move the DEFINE_ expansions to another
> header file.  I suggest common_stacks.h and common_lhashes.h
> 
> At the very least for 3.0.0.  For 1.1.1, I have no idea...
> 
> Cheers,
> Richard
> 
> -- 
> Richard Levitte         levitte at openssl.org
> OpenSSL Project         http://www.openssl.org/~levitte/
> _______________________________________________
> openssl-project mailing list
> openssl-project at openssl.org
> https://mta.openssl.org/mailman/listinfo/openssl-project

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mta.openssl.org/pipermail/openssl-project/attachments/20190128/0f5b84cd/attachment.html>


More information about the openssl-project mailing list