#48039 nunc-stans malloc should be pluggable
Closed: Fixed None Opened 5 years ago by rmeggins.

apps need to be able to pass in malloc, calloc, etc. functions to use. For example, 389 needs nunc-stans to use slapi_ch_malloc, etc.


Sorry - I forgot that the dirsrv signatures for slapi_ch_malloc etc. were non-standard. I think it would be better, more portable, more interoperable if nunc-stans used the standard signatures e.g.
{{{
void malloc(size_t size);
void free(void
ptr);
void calloc(size_t nmemb, size_t size);
void
realloc(void ptr, size_t size);
}}}
Then dirsrv would need to provide functions using these signatures, and cast parameters and return values to size_t and char
.

New patches attached...

{{{
os_malloc(size_t size)
82 {
83 return malloc(size);
}}}
Please use 4 spaces for indentation in nunc-stans.

{{{
1255 static char
1256 nunc_stans_malloc(size_t size)
1257 {
1258 return slapi_ch_malloc((unsigned long)size);
1259 }
}}}
These functions should use the exact same signatures as nunc-stans (and system malloc, etc.) - so something like this:
{{{
static void *
nunc_stans_malloc(size_t size)
{
return (void
)slapi_ch_malloc((unsigned long)size);
}

static void
nunc_stans_calloc(size_t count, size_t size)
{
return (void
)slapi_ch_calloc((unsigned long)count, (unsigned long)size);
}
}}}
etc.

Replying to [comment:5 rmeggins]:

{{{
os_malloc(size_t size)
82 {
83 return malloc(size);
}}}
Please use 4 spaces for indentation in nunc-stans.

Whoops.

{{{
1255 static char
1256 nunc_stans_malloc(size_t size)
1257 {
1258 return slapi_ch_malloc((unsigned long)size);
1259 }
}}}
These functions should use the exact same signatures as nunc-stans (and system malloc, etc.) - so something like this:
{{{
static void *
nunc_stans_malloc(size_t size)
{
return (void
)slapi_ch_malloc((unsigned long)size);
}

static void
nunc_stans_calloc(size_t count, size_t size)
{
return (void
)slapi_ch_calloc((unsigned long)count, (unsigned long)size);
}
}}}
etc.

My C book states that "char ", not "void " is used for the alloc functions. But the linux man page says otherwise. I'll change it...

Replying to [comment:7 rmeggins]:

Not sure what book you have.

http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf - 7.20.3 Memory
management functions

I have "C: A reference manual" 5th edition. It states its C99 compliant, etc. I just bought it not that long ago, err.

Anyway, new patches are attached...

To git+ssh://git.engineering.redhat.com/srv/git/users/mareynol/ds.git
050299e..5ab764a nunc-stans -> nunc-stans
commit 5ab764ab17aa0edf214477b0da7123ba5d923b5e

To git+ssh://git.engineering.redhat.com/srv/git/users/mareynol/nunc-stans.git
5499cd4..c89dcbf mreynolds -> mreynolds
commit c89dcbf94104d2ce92cc86ecee809a89b22dd508

Metadata Update from @mreynolds:
- Issue assigned to mreynolds
- Issue set to the milestone: 1.3.4 backlog

3 years ago

Login to comment on this ticket.

Metadata