[EMAIL PROTECTED] wrote:
>
> I'd like to see the code if you're going to wait
> a bit before committig.
>
> I'm curious how you do it all with macros yet
> maintain type-safety. :)
>
> /r$, wishing for templates...
Don't forget that templates are really just a glorified preprocessor
(well, OK, they aren't now but they were at first) :-)
Seriously, you can do a lot of what templates do with a preprocessor if
you try hard enough. Anyway, the interesting stuff all happens here, in
what will be safestack.h:
#define STACK_OF(type) STACK_##type
#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); \
int sk_##type##_num(STACK_OF(type) *sk); \
type *sk_##type##_value(STACK_OF(type) *sk,int n); \
type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v); \
void sk_##type##_zero(STACK_OF(type) *sk); \
int sk_##type##_push(STACK_OF(type) *sk,type *v); \
int sk_##type##_find(STACK_OF(type) *sk,type *v); \
void sk_##type##_delete(STACK_OF(type) *sk,int n); \
void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \
void sk_##type##_set_cmp_func(STACK_OF(type) *sk,int (*cmp)(type **,type
**)); \
STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk); \
void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)); \
type *sk_##type##_shift(STACK_OF(type) *sk);
#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); } \
int sk_##type##_num(STACK_OF(type) *sk) \
{ return sk_num((STACK *)sk); } \
type *sk_##type##_value(STACK_OF(type) *sk,int n) \
{ return (type *)sk_value((STACK *)sk,n); } \
type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v) \
{ return (type *)(sk_value((STACK *)sk,n)=(char *)v); } \
void sk_##type##_zero(STACK_OF(type) *sk) \
{ sk_zero((STACK *)sk); } \
int sk_##type##_push(STACK_OF(type) *sk,type *v) \
{ return sk_push((STACK *)sk,(char *)v); } \
int sk_##type##_find(STACK_OF(type) *sk,type *v) \
{ return sk_find((STACK *)sk,(char *)v); } \
void sk_##type##_delete(STACK_OF(type) *sk,int n) \
{ sk_delete((STACK *)sk,n); } \
void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \
{ sk_delete_ptr((STACK *)sk,(char *)v); } \
void sk_##type##_set_cmp_func(STACK_OF(type) *sk,int (*cmp)(type **,type
**)) \
{ sk_set_cmp_func((STACK *)sk,cmp); } \
STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk) \
{ return (STACK_OF(type) *)sk_dup((STACK *)sk); } \
void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)) \
{ sk_pop_free((STACK *)sk,func); } \
type *sk_##type##_shift(STACK_OF(type) *sk) \
{ return (type *)sk_shift((STACK *)sk); }
Cheers,
Ben.
P.S. I wish we had templates, too...
--
http://www.apache-ssl.org/ben.html
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
- Indira Gandhi
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]