Merge pull request #42 from ccawley2011/rwstrdup
Replace use of strdup with rwstrdup
This commit is contained in:
commit
c493613724
@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <new>
|
||||
|
||||
@ -156,6 +157,15 @@ void *mustrealloc_h(void *p, size_t sz, uint32 hint)
|
||||
return nil;
|
||||
}
|
||||
|
||||
char *strdup_LOC(const char *s, uint32 hint, const char *here) {
|
||||
char *t;
|
||||
size_t sz = strlen(s)+1;
|
||||
t = (char*)malloc_LOC(sz, hint, here);
|
||||
if(t)
|
||||
memcpy(t, s, sz);
|
||||
return t;
|
||||
}
|
||||
|
||||
MemoryFunctions defaultMemfuncs = {
|
||||
malloc_h,
|
||||
realloc_h,
|
||||
|
@ -33,7 +33,7 @@ registerUniform(const char *name)
|
||||
assert(0 && "no space for uniform");
|
||||
return -1;
|
||||
}
|
||||
uniformRegistry.uniformNames[uniformRegistry.numUniforms] = strdup(name);
|
||||
uniformRegistry.uniformNames[uniformRegistry.numUniforms] = rwStrdup(name, MEMDUR_EVENT);
|
||||
return uniformRegistry.numUniforms++;
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ registerBlock(const char *name)
|
||||
// TODO: print error
|
||||
if(uniformRegistry.numBlocks+1 >= MAX_BLOCKS)
|
||||
return -1;
|
||||
uniformRegistry.blockNames[uniformRegistry.numBlocks] = strdup(name);
|
||||
uniformRegistry.blockNames[uniformRegistry.numBlocks] = rwStrdup(name, MEMDUR_EVENT);
|
||||
return uniformRegistry.numBlocks++;
|
||||
}
|
||||
|
||||
|
@ -894,17 +894,6 @@ Image::extractMask(void)
|
||||
return img;
|
||||
}
|
||||
|
||||
static char*
|
||||
rwstrdup(const char *s)
|
||||
{
|
||||
char *t;
|
||||
size_t len = strlen(s)+1;
|
||||
t = (char*)rwMalloc(len, MEMDUR_EVENT);
|
||||
if(t)
|
||||
memcpy(t, s, len);
|
||||
return t;
|
||||
}
|
||||
|
||||
void
|
||||
Image::setSearchPath(const char *path)
|
||||
{
|
||||
@ -913,7 +902,7 @@ Image::setSearchPath(const char *path)
|
||||
rwFree(g->searchPaths);
|
||||
g->numSearchPaths = 0;
|
||||
if(path)
|
||||
g->searchPaths = p = rwstrdup(path);
|
||||
g->searchPaths = p = rwStrdup(path, MEMDUR_EVENT);
|
||||
else{
|
||||
g->searchPaths = nil;
|
||||
return;
|
||||
@ -946,7 +935,7 @@ Image::getFilename(const char *name)
|
||||
char *s, *p = g->searchPaths;
|
||||
size_t len = strlen(name)+1;
|
||||
if(g->numSearchPaths == 0){
|
||||
s = rwstrdup(name);
|
||||
s = rwStrdup(name, MEMDUR_EVENT);
|
||||
makePath(s);
|
||||
f = fopen(s, "rb");
|
||||
if(f){
|
||||
@ -1038,7 +1027,7 @@ Image::registerFileFormat(const char *ext, fileRead read, fileWrite write)
|
||||
ImageGlobals *g = PLUGINOFFSET(ImageGlobals, engine, imageModuleOffset);
|
||||
if(g->numFileFormats >= (int)nelem(g->fileFormats))
|
||||
return 0;
|
||||
g->fileFormats[g->numFileFormats].extension = rwstrdup(ext);
|
||||
g->fileFormats[g->numFileFormats].extension = rwStrdup(ext, MEMDUR_EVENT);
|
||||
g->fileFormats[g->numFileFormats].read = read;
|
||||
g->fileFormats[g->numFileFormats].write = write;
|
||||
g->numFileFormats++;
|
||||
|
@ -12,11 +12,6 @@
|
||||
|
||||
#include "lodepng/lodepng.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
/* srsly? */
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
#define PLUGIN_ID 0
|
||||
|
||||
namespace rw {
|
||||
|
@ -206,6 +206,8 @@ inline void *realloc_LOC(void *p, size_t sz, uint32 hint, const char *here) { al
|
||||
inline void *mustmalloc_LOC(size_t sz, uint32 hint, const char *here) { allocLocation = here; return rw::Engine::memfuncs.rwmustmalloc(sz,hint); }
|
||||
inline void *mustrealloc_LOC(void *p, size_t sz, uint32 hint, const char *here) { allocLocation = here; return rw::Engine::memfuncs.rwmustrealloc(p,sz,hint); }
|
||||
|
||||
char *strdup_LOC(const char *s, uint32 hint, const char *here);
|
||||
|
||||
#define rwMalloc(s, h) rw::malloc_LOC(s,h,RWHERE)
|
||||
#define rwMallocT(t, s, h) (t*)rw::malloc_LOC((s)*sizeof(t),h,RWHERE)
|
||||
#define rwRealloc(p, s, h) rw::realloc_LOC(p,s,h,RWHERE)
|
||||
@ -215,6 +217,7 @@ inline void *mustrealloc_LOC(void *p, size_t sz, uint32 hint, const char *here)
|
||||
#define rwNewT(t, s, h) (t*)rw::mustmalloc_LOC((s)*sizeof(t),h,RWHERE)
|
||||
#define rwResize(p, s, h) rw::mustrealloc_LOC(p,s,h,RWHERE)
|
||||
#define rwResizeT(t, p, s, h) (t*)rw::mustrealloc_LOC(p,(s)*sizeof(t),h,RWHERE)
|
||||
#define rwStrdup(s, h) rw::strdup_LOC(s,h,RWHERE)
|
||||
|
||||
extern MemoryFunctions defaultMemfuncs;
|
||||
extern MemoryFunctions managedMemfuncs;
|
||||
|
Loading…
Reference in New Issue
Block a user