mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-15 03:01:09 +08:00
First cut at ber_set_option(NULL,LBER_OPT_MEMORY_FN, myrealloc) where
myrealloc is pointer to a realloc() wrapper. Must be first library call or else.
This commit is contained in:
parent
193ab59661
commit
2f969f8552
@ -96,9 +96,12 @@ typedef int (*BERTranslateProc) LDAP_P((
|
||||
#define LBER_OPT_BER_DEBUG 0x02
|
||||
|
||||
#define LBER_OPT_DEBUG_LEVEL LBER_OPT_BER_DEBUG
|
||||
|
||||
#define LBER_OPT_LOG_PRINT_FN 0x8001
|
||||
#define LBER_OPT_MEMORY_FN 0x8002
|
||||
|
||||
typedef void (*BER_LOG_PRINT_FN) LDAP_P(( char *buf ));
|
||||
typedef void* (*BER_MEMORY_FN) LDAP_P(( void *p, size_t size ));
|
||||
|
||||
/* LBER Sockbuf options */
|
||||
#define LBER_TO_FILE 0x01 /* to a file referenced by sb_fd */
|
||||
|
@ -750,6 +750,8 @@ ber_bvfree( struct berval *bv )
|
||||
{
|
||||
assert(bv != NULL); /* bv damn better point to something */
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
if ( bv->bv_val != NULL )
|
||||
LBER_FREE( bv->bv_val );
|
||||
LBER_FREE( (char *) bv );
|
||||
@ -762,6 +764,8 @@ ber_bvecfree( struct berval **bv )
|
||||
|
||||
assert(bv != NULL); /* bv damn better point to something */
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
for ( i = 0; bv[i] != NULL; i++ )
|
||||
ber_bvfree( bv[i] );
|
||||
LBER_FREE( (char *) bv );
|
||||
@ -775,6 +779,8 @@ ber_bvdup(
|
||||
|
||||
assert( bv != NULL );
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
if( bv == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -242,6 +242,8 @@ ber_alloc_t( int options )
|
||||
{
|
||||
BerElement *ber;
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
ber = (BerElement *) LBER_CALLOC( 1, sizeof(BerElement) );
|
||||
|
||||
if ( ber == NULLBER )
|
||||
@ -293,6 +295,8 @@ ber_init_w_nullc( BerElement *ber, int options )
|
||||
{
|
||||
assert( ber != NULL );
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
(void) memset( (char *)ber, '\0', sizeof( BerElement ));
|
||||
ber->ber_valid = LBER_VALID_BERELEMENT;
|
||||
ber->ber_tag = LBER_DEFAULT;
|
||||
@ -313,6 +317,8 @@ ber_init( struct berval *bv )
|
||||
|
||||
assert( bv != NULL );
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
if ( bv == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
@ -349,6 +355,8 @@ int ber_flatten(
|
||||
|
||||
assert( bvPtr != NULL );
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
if(bvPtr == NULL) {
|
||||
return( -1 );
|
||||
}
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
LDAP_BEGIN_DECL
|
||||
|
||||
extern BER_MEMORY_FN ber_int_realloc;
|
||||
|
||||
struct lber_options {
|
||||
short lbo_valid;
|
||||
#define LBER_UNINITIALIZED 0x0
|
||||
@ -190,12 +192,34 @@ ber_log_sos_dump LDAP_P((
|
||||
int loglvl,
|
||||
const Seqorset *sos ));
|
||||
|
||||
|
||||
/* memory.c */
|
||||
/* simple macros to realloc for now */
|
||||
#define LBER_MALLOC(s) (realloc(NULL,(s)))
|
||||
#define LBER_CALLOC(n,s) (calloc((n),(s)))
|
||||
#define LBER_REALLOC(p,s) (realloc((p),(s)))
|
||||
#define LBER_FREE(p) (realloc((p),(size_t)0))
|
||||
#define LBER_MALLOC(s) \
|
||||
(ber_int_realloc \
|
||||
? (*ber_int_realloc)(NULL,(s)) \
|
||||
: realloc(NULL,(s)))
|
||||
|
||||
#define LBER_CALLOC(n,s) \
|
||||
(ber_int_realloc \
|
||||
? ber_int_calloc((n),(s)) \
|
||||
: calloc((n),(s)))
|
||||
|
||||
#define LBER_REALLOC(p,s) \
|
||||
(ber_int_realloc \
|
||||
? (*ber_int_realloc)((p),(s)) \
|
||||
: realloc((p),(s)))
|
||||
|
||||
#define LBER_FREE(p) \
|
||||
(ber_int_realloc \
|
||||
? (*ber_int_realloc)((p),(size_t)0) \
|
||||
: realloc((p),(size_t)0))
|
||||
|
||||
LDAP_F( void * )
|
||||
ber_int_calloc LDAP_P((
|
||||
size_t n,
|
||||
size_t size ));
|
||||
|
||||
|
||||
/* sockbuf.c */
|
||||
|
||||
|
@ -11,24 +11,42 @@
|
||||
void
|
||||
ber_memfree( void *p )
|
||||
{
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
LBER_FREE( p );
|
||||
}
|
||||
|
||||
void *
|
||||
ber_memalloc( size_t s )
|
||||
{
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
return LBER_MALLOC( s );
|
||||
}
|
||||
|
||||
void *
|
||||
ber_memcalloc( size_t n, size_t s )
|
||||
{
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
return LBER_CALLOC( n, s );
|
||||
}
|
||||
|
||||
void *
|
||||
ber_memrealloc( void* p, size_t s )
|
||||
{
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
return LBER_REALLOC( p, s );
|
||||
}
|
||||
|
||||
BER_MEMORY_FN ber_int_realloc = NULL;
|
||||
|
||||
void *
|
||||
ber_int_calloc( size_t n, size_t s )
|
||||
{
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
{
|
||||
size_t size = n * s;
|
||||
void *p = (*ber_int_realloc)( NULL, size );
|
||||
return p ? memset( p, 0, size ) : p;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ ber_get_option(
|
||||
BerElement *ber;
|
||||
Sockbuf *sb;
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
if(outvalue == NULL) {
|
||||
/* no place to get to */
|
||||
return LBER_OPT_ERROR;
|
||||
@ -65,6 +67,17 @@ ber_set_option(
|
||||
BerElement *ber;
|
||||
Sockbuf *sb;
|
||||
|
||||
if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
|
||||
&& ( option == LBER_OPT_MEMORY_FN )
|
||||
&& ( invalue != NULL ))
|
||||
{
|
||||
ber_int_realloc = (BER_MEMORY_FN) invalue;
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
return LBER_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
if(invalue == NULL) {
|
||||
/* no place to set from */
|
||||
return LBER_OPT_ERROR;
|
||||
|
@ -330,7 +330,11 @@ sockbuf_copy_out( Sockbuf *sb, char **buf, long len )
|
||||
|
||||
Sockbuf *ber_sockbuf_alloc( void )
|
||||
{
|
||||
Sockbuf *sb = LBER_CALLOC(1, sizeof(Sockbuf));
|
||||
Sockbuf *sb;
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
sb = LBER_CALLOC(1, sizeof(Sockbuf));
|
||||
|
||||
if( sb == NULL ) return NULL;
|
||||
|
||||
@ -694,6 +698,8 @@ int ber_pvt_sb_init( Sockbuf *sb )
|
||||
{
|
||||
assert( sb != NULL);
|
||||
|
||||
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
||||
|
||||
sb->sb_valid=LBER_VALID_SOCKBUF;
|
||||
sb->sb_options = 0;
|
||||
sb->sb_debug = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user