Banished alloca().
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2946 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
Changes towards version 0.7:
|
||||
- Don't use alloca() in uio. - SvdB
|
||||
- Replace PlayerOne/PlayerTwo by PlayerControls[0]/PlayerControls[1] - SvdB
|
||||
- Moved comm resources into starcon.ls2 - Michael
|
||||
- Repackaged static comm/ship data to it all uniquely named - Michael
|
||||
|
||||
@@ -667,6 +667,7 @@ listOneDir(DebugContext *debugContext, const char *arg) {
|
||||
int i;
|
||||
const char *pattern;
|
||||
const char *cpath;
|
||||
char *buf = NULL;
|
||||
|
||||
if (arg[0] == '\0') {
|
||||
cpath = arg;
|
||||
@@ -674,21 +675,21 @@ listOneDir(DebugContext *debugContext, const char *arg) {
|
||||
} else {
|
||||
pattern = strrchr(arg, '/');
|
||||
if (pattern == NULL) {
|
||||
// No directory component in 'arg'.
|
||||
cpath = "";
|
||||
pattern = arg;
|
||||
} else if (pattern[1] == '\0') {
|
||||
// argument ends on /
|
||||
// 'arg' ends on /
|
||||
cpath = arg;
|
||||
pattern = "*";
|
||||
} else {
|
||||
if (pattern == arg) {
|
||||
cpath = "/";
|
||||
} else {
|
||||
char *path;
|
||||
path = uio_alloca(pattern - arg + 1);
|
||||
memcpy(path, arg, pattern - arg);
|
||||
path[pattern - arg] = '\0';
|
||||
cpath = path;
|
||||
buf = uio_malloc(pattern - arg + 1);
|
||||
memcpy(buf, arg, pattern - arg);
|
||||
buf[pattern - arg] = '\0';
|
||||
cpath = buf;
|
||||
}
|
||||
pattern++;
|
||||
}
|
||||
@@ -708,11 +709,15 @@ listOneDir(DebugContext *debugContext, const char *arg) {
|
||||
if (dirList == NULL) {
|
||||
fprintf(debugContext->out, "Error in uio_getDirList(): %s.\n",
|
||||
strerror(errno));
|
||||
if (buf != NULL)
|
||||
uio_free(buf);
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < dirList->numNames; i++)
|
||||
fprintf(debugContext->out, "%s\n", dirList->names[i]);
|
||||
uio_DirList_free(dirList);
|
||||
if (buf != NULL)
|
||||
uio_free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,8 @@ uio_walkGPPath(uio_GPDir *startGPDir, const char *path,
|
||||
int retVal;
|
||||
|
||||
gPDir = startGPDir;
|
||||
tempBuf = uio_alloca(strlen(path) + 1);
|
||||
tempBuf = uio_malloc(strlen(path) + 1);
|
||||
// XXX: Use a dynamically allocated array when moving to C99.
|
||||
pathEnd = path + pathLen;
|
||||
getFirstPathComponent(path, pathEnd, &partStart, &partEnd);
|
||||
while (1) {
|
||||
@@ -247,6 +248,7 @@ uio_walkGPPath(uio_GPDir *startGPDir, const char *path,
|
||||
getNextPathComponent(pathEnd, &partStart, &partEnd);
|
||||
}
|
||||
|
||||
uio_free(tempBuf);
|
||||
*pathRest = partStart;
|
||||
*endGPDir = gPDir;
|
||||
return retVal;
|
||||
|
||||
@@ -71,7 +71,8 @@ uio_walkPhysicalPath(uio_PDirHandle *startPDirHandle, const char *path,
|
||||
|
||||
uio_PDirHandle_ref(startPDirHandle);
|
||||
pDirHandle = startPDirHandle;
|
||||
tempBuf = uio_alloca(strlen(path) + 1);
|
||||
tempBuf = uio_malloc(strlen(path) + 1);
|
||||
// XXX: Use a dynamically allocated array when moving to C99.
|
||||
pathEnd = path + pathLen;
|
||||
getFirstPathComponent(path, pathEnd, &partStart, &partEnd);
|
||||
for (;;) {
|
||||
@@ -97,6 +98,7 @@ uio_walkPhysicalPath(uio_PDirHandle *startPDirHandle, const char *path,
|
||||
getNextPathComponent(pathEnd, &partStart, &partEnd);
|
||||
}
|
||||
|
||||
uio_free(tempBuf);
|
||||
*pathRest = partStart;
|
||||
*endPDirHandle = pDirHandle;
|
||||
return retVal;
|
||||
@@ -132,8 +134,9 @@ uio_makePath(uio_PDirHandle *pDirHandle, const char *path, size_t pathLen,
|
||||
|
||||
pathEnd = path + pathLen;
|
||||
|
||||
buf = uio_alloca(pathLen + 1);
|
||||
buf = uio_malloc(pathLen + 1);
|
||||
// worst case length
|
||||
// XXX: Use a dynamically allocated array when moving to C99.
|
||||
|
||||
uio_walkPhysicalPath(pDirHandle, path, pathLen, &pDirHandle, &rest);
|
||||
// The reference to the original pDirHandle is still kept
|
||||
@@ -152,12 +155,14 @@ uio_makePath(uio_PDirHandle *pDirHandle, const char *path, size_t pathLen,
|
||||
int savedErrno = errno;
|
||||
uio_PDirHandle_unref(pDirHandle);
|
||||
errno = savedErrno;
|
||||
uio_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
uio_PDirHandle_unref(pDirHandle);
|
||||
pDirHandle = newPDirHandle;
|
||||
getNextPathComponent(pathEnd, &start, &end);
|
||||
}
|
||||
uio_free(buf);
|
||||
return pDirHandle;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#define uio_realloc realloc
|
||||
#define uio_free free
|
||||
#define uio_calloc calloc
|
||||
#define uio_alloca alloca
|
||||
|
||||
#ifdef uio_MEM_DEBUG
|
||||
// When uio_strdup is defined to the libc strdup, there's no opportunity
|
||||
|
||||
@@ -145,17 +145,6 @@ typedef unsigned short mode_t;
|
||||
# define S_IFDIR _S_IFDIR
|
||||
#endif
|
||||
|
||||
// Memory related:
|
||||
#ifdef WIN32
|
||||
# ifdef __MINGW32__
|
||||
# include <malloc.h>
|
||||
# elif defined (_MSC_VER)
|
||||
# define alloca _alloca
|
||||
# endif
|
||||
#elif defined(__linux__) || defined(__svr4__)
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
|
||||
// String formatting
|
||||
#ifdef _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
|
||||
Reference in New Issue
Block a user