Re: [pcre-dev] A test for the memory mismatch problem

Page principale
Supprimer ce message
Auteur: Sheri
Date:  
À: pcre-dev
Sujet: Re: [pcre-dev] A test for the memory mismatch problem
Philip Hazel wrote:
> On Thu, 29 Mar 2007, Sheri wrote:
>
>
>> Hey Philip, I see some other notes in the old NON-UNIX USE (haven't
>> looked at the new one yet) about missing function pointers for malloc
>> and free.
>>
>> Should we try adding this bit to pcre.h or pcretest.c?
>>
>> =========================
>> #ifdef _WIN32
>> #include <malloc.h>
>>
>> void* malloc_stub(size_t N)
>> { return malloc(N); }
>> void free_stub(void* p)
>> { free(p); }
>> void *(*pcre_malloc)(size_t) = &malloc_stub;
>> void (*pcre_free)(void *) = &free_stub;
>>
>> #else
>>
>> void *(*pcre_malloc)(size_t) = malloc;
>> void (*pcre_free)(void *) = free;
>>
>> #endif
>> =========================
>>
>
> Yes, that has the right kind of smell about it! But it needs to go right
> at the bottom of pcre_globals.c, replacing the two definitions that are
> there.
>
> Aha! I see that callout is there too, and I seem to remember you had
> callout problems. Perhaps worth trying replacing all 5 of the functions
> you'll find there in the manner suggested above.
>
> Philip
>
>

Hi Philip,

Came up with this, haven't tried it yet. Would appreciate if you review
my additions and tell me what should be there for the callout lines.

#ifdef _WIN32
#include <malloc.h>

void* malloc_stub(size_t N)
{ return malloc(N); }

void free_stub(void* p)
{ free(p); }

void stack_malloc_stub(size_t N)
{ return stack_malloc(N); }

void stack_free_stub(void * p)
{ free(p); }

int callout_stub(?????????????)
{return ?????????}


void *(*pcre_malloc)(size_t) = &malloc_stub;
void (*pcre_free)(void *) = &free_stub;
void *(*pcre_stack_malloc)(size_t) = &stack_malloc_stub;
void (*pcre_stack_free)(void *) = &stack_free_stub;
int (*pcre_callout)(pcre_callout_block *) = &callout_stub;

#else

void *(*pcre_malloc)(size_t) = malloc;
void (*pcre_free)(void *) = free;
void *(*pcre_stack_malloc)(size_t) = malloc;
void (*pcre_stack_free)(void *) = free;
int (*pcre_callout)(pcre_callout_block *) = NULL;

#endif

/* End of pcre_globals.c */


Regards,
Sheri