]> git.sur5r.net Git - openldap/commitdiff
Rework of berbuf allocation:
authorKurt Zeilenga <kurt@openldap.org>
Mon, 13 Oct 2003 18:09:15 +0000 (18:09 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 13 Oct 2003 18:09:15 +0000 (18:09 +0000)
Moved BerElementBuffer to lber_pvt.h
Defined union by macro so it can be easily reused.
Updated client/tools/common.c.

clients/tools/common.c
include/lber.h
include/lber_pvt.h

index ee427460f97be93b7f500694df710b0a0aeb1581..bc74e2845955bb406e798dbbb748a546f9266ff6 100644 (file)
@@ -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=<empty>\n" );
index 3b351c5818d64270f4352a74f0197fa9b6b9657f..a5c996cd9c8eb41a41f6ca0eba4ed505b45f78af 100644 (file)
@@ -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;
index 48817d1b01441e5b5a47a4dc71a1f08bde4e323c..e978f15bc24947013ebd49b430172e9920ca5321 100644 (file)
 
 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;