From: Kurt Zeilenga Date: Mon, 13 Oct 2003 18:09:15 +0000 (+0000) Subject: Rework of berbuf allocation: X-Git-Tag: OPENLDAP_REL_ENG_2_1_MP~578 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a2f36ae2d3ef4de8cd75d2c7da5c202e03edb8f0;p=openldap Rework of berbuf allocation: Moved BerElementBuffer to lber_pvt.h Defined union by macro so it can be easily reused. Updated client/tools/common.c. --- diff --git a/clients/tools/common.c b/clients/tools/common.c index ee427460f9..bc74e28459 100644 --- a/clients/tools/common.c +++ b/clients/tools/common.c @@ -20,6 +20,7 @@ #include "lutil_ldap.h" #include "ldap_defaults.h" #include "ldap_pvt.h" +#include "lber_pvt.h" #include "common.h" @@ -762,8 +763,8 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count ) } if ( assertctl ) { - char berbuf[LBER_ELEMENT_SIZEOF]; - BerElement *ber = (BerElement *)berbuf; + BerElementBuffer berbuf; + BerElement *ber = (BerElement *)&berbuf; if( assertion == NULL || *assertion == '\0' ) { fprintf( stderr, "Assertion=\n" ); diff --git a/include/lber.h b/include/lber.h index 3b351c5818..a5c996cd9c 100644 --- a/include/lber.h +++ b/include/lber.h @@ -157,18 +157,6 @@ extern char ber_pvt_opt_on; #define LBER_OPT_SUCCESS (0) #define LBER_OPT_ERROR (-1) -#define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */ -typedef union ber_buffer_u { - char charbuf[LBER_ELEMENT_SIZEOF]; - - /* force alignment */ - int intbuf; - long longbuf; - float floatbuf; - double doublebuf; - char* ptrbuf; -} BerElementBuffer; - typedef struct berelement BerElement; typedef struct sockbuf Sockbuf; typedef struct seqorset Seqorset; diff --git a/include/lber_pvt.h b/include/lber_pvt.h index 48817d1b01..e978f15bc2 100644 --- a/include/lber_pvt.h +++ b/include/lber_pvt.h @@ -21,6 +21,22 @@ LDAP_BEGIN_DECL +/* for allocating aligned buffers (on the stack) */ +#define LBER_ALIGN_BUFFER(uname,size) \ + union LDAP_CONCAT(lber_,uname) { \ + char buffer[size]; \ + \ + /* force alignment */ \ + int ialign; \ + long lalign; \ + float falign; \ + double dalign; \ + char* palign; \ + } + +#define LBER_ELEMENT_SIZEOF (256) /* must be >= sizeof(BerElement) */ +typedef LBER_ALIGN_BUFFER(berelement_u,LBER_ELEMENT_SIZEOF) BerElementBuffer; + typedef struct sockbuf_buf { ber_len_t buf_size; ber_len_t buf_ptr;