I'm trying to define an ASN1 type that has an element which is a stack
of UTF-8 string usins 0.9.4 and I have some problems.

I figured I had to define the type STACK_OF(ASN1_UTF8STRING) with
DECLARE_STACK_OF(ASN1_UTF8STRING), but this bring problems.

I suggest you give up this message now if you're not a guru of C
precompiler.

In non-debug version, we have :
#define ASN1_UTF8STRING  ASN1_STRING

and

#define DECLARE_STACK_OF(type) \
typedef struct stack_st_##type \
    { \
    STACK stack; \
    } STACK_OF(type); \
STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)); \
STACK_OF(type) *sk_##type##_new_null(void); \
void sk_##type##_free(STACK_OF(type) *sk); \

and
#define IMPLEMENT_STACK_OF(type) \
STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)) \
    { return (STACK_OF(type) *)sk_new(cmp); } \
STACK_OF(type) *sk_##type##_new_null() \
    { return (STACK_OF(type) *)sk_new_null(); } \
void sk_##type##_free(STACK_OF(type) *sk) \
    { sk_free((STACK *)sk); } \

and

#define STACK_OF(type) STACK_##type

In DECLARE_STACK_OF, the precompiler makes concatenation first.
Then replaces ASN1_UTF8STRING  with ASN1_STRING everywhere.
Then the sub-macros are handled.
This gives :
typedef struct stack_st_ASN1_UTF8STRING  { STACK stack; }
STACK_ASN1_STRING    ;
STACK_ASN1_STRING     *sk_ASN1_UTF8STRING_new(int (*cmp)( ASN1_STRING
**, ASN1_STRING   **));
STACK_ASN1_STRING     *sk_ASN1_UTF8STRING_new_null(void);
void sk_ASN1_UTF8STRING_free(STACK_ASN1_STRING     *sk);

which sound like what we want.
The names have ASN1_UTF8STRING in them, but the type is actually
ASN1_STRING.

But now when I declare :
STACK_OF(ASN1_UTF8STRING) in my code, the deepness of the call is one so
I get STACK_ASN1_UTF8STRING instead of the STACK_ASN1_STRING I had in
DECLARE_STACK_OF.

Is this solved in 0.9.5 ?

I think the deepness of DECLARE_STACK_OF should be increased by one so
that the behaviour becomes constant:

<#define STACK_OF(type) STACK_##type
>#define INTERNAL_STACK_OF(type) STACK_##type
>#define STACK_OF(type) INTERNAL_STACK_OF(type)

We also have :
#define ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)

But when I call :
    sk_ASN1_UTF8STRING_pop_free(a->extensions,ASN1_UTF8STRING_free);

I don't get the result I want because ASN1_UTF8STRING_free is not
replaced by ASN1_STRING_free as this is not a function call.

We should have :
#define ASN1_UTF8STRING_free ASN1_STRING_free
because anyway a is of type ASN1_STRING.

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to