Merge 1.072

This commit is contained in:
kai
2012-02-02 03:13:27 +01:00
parent 81082996e1
commit f9201e8352
72 changed files with 7739 additions and 3484 deletions

View File

@@ -190,7 +190,8 @@ char *Array::toChars()
char *str;
char *p;
buf = (char **)alloca(dim * sizeof(char *));
buf = (char **)malloc(dim * sizeof(char *));
assert(buf);
len = 2;
for (u = 0; u < dim; u++)
{
@@ -211,6 +212,7 @@ char *Array::toChars()
}
*p++ = ']';
*p = 0;
free(buf);
return str;
}

View File

@@ -12,7 +12,6 @@
#include <process.h>
#include "root.h"
#include "rmem.h"
static unsigned __stdcall startthread(void *p);
@@ -41,7 +40,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
AsyncRead *aw = (AsyncRead *)calloc(1, sizeof(AsyncRead) +
(nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
@@ -92,7 +91,7 @@ int AsyncRead::read(size_t i)
void AsyncRead::dispose(AsyncRead *aw)
{
delete aw;
free(aw);
}
@@ -119,7 +118,6 @@ unsigned __stdcall startthread(void *p)
#include <time.h>
#include "root.h"
#include "rmem.h"
void *startthread(void *arg);
@@ -155,7 +153,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
AsyncRead *aw = (AsyncRead *)calloc(1, sizeof(AsyncRead) +
(nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
@@ -228,7 +226,7 @@ void AsyncRead::dispose(AsyncRead *aw)
if (status != 0)
err_abort(status, "mutex destroy");
}
delete aw;
free(aw);
}
@@ -265,7 +263,6 @@ void *startthread(void *p)
#include <errno.h>
#include "root.h"
#include "rmem.h"
struct FileData
{
@@ -292,7 +289,7 @@ struct AsyncRead
AsyncRead *AsyncRead::create(size_t nfiles)
{
AsyncRead *aw = (AsyncRead *)mem.calloc(1, sizeof(AsyncRead) +
AsyncRead *aw = (AsyncRead *)calloc(1, sizeof(AsyncRead) +
(nfiles - 1) * sizeof(FileData));
aw->filesmax = nfiles;
return aw;
@@ -322,7 +319,7 @@ int AsyncRead::read(size_t i)
void AsyncRead::dispose(AsyncRead *aw)
{
delete aw;
free(aw);
}
#endif

View File

@@ -327,7 +327,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 2:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint16_t *)str;
#else
hash += str[0] * 256 + str[1];
@@ -336,7 +336,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 3:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += (*(const uint16_t *)str << 8) +
((const uint8_t *)str)[2];
#else
@@ -346,7 +346,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
default:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint32_t *)str;
#else
hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
@@ -379,7 +379,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 2:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint16_t *)str;
#else
hash += str[0] * 256 + str[1];
@@ -388,7 +388,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
case 3:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += (*(const uint16_t *)str << 8) +
((const uint8_t *)str)[2];
#else
@@ -398,7 +398,7 @@ hash_t Dchar::calcHash(const dchar *str, size_t len)
default:
hash *= 37;
#if __I86__
#if LITTLE_ENDIAN
hash += *(const uint32_t *)str;
#else
hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2006 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// www.digitalmars.com
@@ -161,14 +161,14 @@ struct Dchar
static int memcmp(const dchar *s1, const dchar *s2, int nchars) { return ::memcmp(s1, s2, nchars); }
static int isDigit(dchar c) { return '0' <= c && c <= '9'; }
#ifndef GCC_SAFE_DMD
static int isAlpha(dchar c) { return isalpha(c); }
static int isUpper(dchar c) { return isupper(c); }
static int isLower(dchar c) { return islower(c); }
static int isLocaleUpper(dchar c) { return isupper(c); }
static int isLocaleLower(dchar c) { return islower(c); }
static int toLower(dchar c) { return isupper(c) ? tolower(c) : c; }
static int isAlpha(dchar c) { return isalpha((unsigned char)c); }
static int isUpper(dchar c) { return isupper((unsigned char)c); }
static int isLower(dchar c) { return islower((unsigned char)c); }
static int isLocaleUpper(dchar c) { return isupper((unsigned char)c); }
static int isLocaleLower(dchar c) { return islower((unsigned char)c); }
static int toLower(dchar c) { return isupper((unsigned char)c) ? tolower(c) : c; }
static int toLower(dchar *p) { return toLower(*p); }
static int toUpper(dchar c) { return islower(c) ? toupper(c) : c; }
static int toUpper(dchar c) { return islower((unsigned char)c) ? toupper(c) : c; }
static dchar *dup(dchar *p) { return ::strdup(p); } // BUG: out of memory?
#endif
static dchar *chr(dchar *p, int c) { return strchr(p, c); }

View File

@@ -26,7 +26,7 @@ void browse(const char *url)
#endif
#if linux || __FreeBSD__ || __sun&&__SVR4
#if linux || __FreeBSD__ || __OpenBSD__ || __sun&&__SVR4
#include <sys/types.h>
#include <sys/wait.h>

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2009 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -70,6 +70,11 @@ double Port::pow(double x, double y)
return ::pow(x, y);
}
long double Port::fmodl(long double x, long double y)
{
return ::fmodl(x, y);
}
unsigned long long Port::strtoull(const char *p, char **pend, int base)
{
return ::strtoull(p, pend, base);
@@ -201,14 +206,21 @@ double Port::pow(double x, double y)
return ::pow(x, y);
}
long double Port::fmodl(long double x, long double y)
{
return ::fmodl(x, y);
}
unsigned _int64 Port::strtoull(const char *p, char **pend, int base)
{
unsigned _int64 number = 0;
int c;
int error;
#ifndef ULLONG_MAX
#define ULLONG_MAX ((unsigned _int64)~0I64)
#endif
while (isspace(*p)) /* skip leading white space */
while (isspace((unsigned char)*p)) /* skip leading white space */
p++;
if (*p == '+')
p++;
@@ -315,7 +327,7 @@ char *Port::strupr(char *s)
#endif
#if linux || __APPLE__ || __FreeBSD__ || __MINGW32__ || __HAIKU__
#if linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __MINGW32__ || __HAIKU__
#include <math.h>
#if linux
@@ -332,6 +344,7 @@ char *Port::strupr(char *s)
#include <stdlib.h>
#include <ctype.h>
#include <float.h>
#include <assert.h>
static double zero = 0;
double Port::nan = NAN;
@@ -368,18 +381,14 @@ PortInitializer::PortInitializer()
#endif
}
#if !defined __MINGW32__ && !defined __HAIKU__
#undef isnan
#endif
int Port::isNan(double r)
{
#if __APPLE__
return __inline_isnan(r);
#elif defined __MINGW32__
return isnan(r);
#elif defined __HAIKU__
#elif __OpenBSD__ || __MINGW32__ || __HAIKU__
return isnan(r);
#else
#undef isnan
return ::isnan(r);
#endif
}
@@ -388,11 +397,10 @@ int Port::isNan(long double r)
{
#if __APPLE__
return __inline_isnan(r);
#elif defined __MINGW32__
return isnan(r);
#elif defined __HAIKU__
#elif __OpenBSD__ || __MINGW32__ || __HAIKU__
return isnan(r);
#else
#undef isnan
return ::isnan(r);
#endif
}
@@ -419,18 +427,14 @@ int Port::isFinite(double r)
return ::finite(r);
}
#if !defined __MINGW32__ && !defined __HAIKU__
#undef isinf
#endif
int Port::isInfinity(double r)
{
#if __APPLE__
return fpclassify(r) == FP_INFINITE;
#elif defined __MINGW32__
return isinf(r);
#elif defined __HAIKU__
#elif __OpenBSD__ || __MINGW32__ || __HAIKU__
return isinf(r);
#else
#undef isinf
return ::isinf(r);
#endif
}
@@ -453,6 +457,15 @@ double Port::pow(double x, double y)
return ::pow(x, y);
}
long double Port::fmodl(long double x, long double y)
{
#if __FreeBSD__ || __OpenBSD__
return ::fmod(x, y); // hack for now, fix later
#else
return ::fmodl(x, y);
#endif
}
unsigned long long Port::strtoull(const char *p, char **pend, int base)
{
return ::strtoull(p, pend, base);
@@ -466,10 +479,14 @@ char *Port::ull_to_string(char *buffer, ulonglong ull)
wchar_t *Port::ull_to_string(wchar_t *buffer, ulonglong ull)
{
#if __OpenBSD__
assert(0);
#else
#ifndef __MINGW32__
swprintf(buffer, sizeof(ulonglong) * 3 + 1, L"%llu", ull);
#else
_snwprintf(buffer, sizeof(ulonglong) * 3 + 1, L"%llu", ull);
#endif
#endif
return buffer;
}

View File

@@ -40,7 +40,8 @@ struct Port
static double dbl_min;
static long double ldbl_max;
#if __GNUC__ && !defined __HAIKU__
#if __OpenBSD__
#elif __GNUC__ && !defined __HAIKU__
// These conflict with macros in math.h, should rename them
#undef isnan
#undef isfinite
@@ -60,6 +61,8 @@ struct Port
static double floor(double);
static double pow(double x, double y);
static long double fmodl(long double x, long double y);
static ulonglong strtoull(const char *p, char **pend, int base);
static char *ull_to_string(char *buffer, ulonglong ull);

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -8,7 +8,7 @@
// See the included readme.txt for details.
#ifndef POSIX
#define POSIX (linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4)
#define POSIX (linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun&&__SVR4)
#endif
#include <stdio.h>
@@ -364,21 +364,21 @@ FileName::FileName(char *path, char *name)
}
// Split a path into an Array of paths
Array *FileName::splitPath(const char *path)
Strings *FileName::splitPath(const char *path)
{
char c = 0; // unnecessary initializer is for VC /W4
const char *p;
OutBuffer buf;
Array *array;
Strings *array;
array = new Array();
array = new Strings();
if (path)
{
p = path;
do
{ char instring = 0;
while (isspace(*p)) // skip leading whitespace
while (isspace((unsigned char)*p)) // skip leading whitespace
p++;
buf.reserve(strlen(p) + 1); // guess size of path
// LDC remember first character
@@ -799,7 +799,7 @@ void FileName::CopyTo(FileName *to)
* cwd if !=0, search current directory before searching path
*/
char *FileName::searchPath(Array *path, const char *name, int cwd)
char *FileName::searchPath(Strings *path, const char *name, int cwd)
{
if (absolute(name))
{
@@ -815,7 +815,7 @@ char *FileName::searchPath(Array *path, const char *name, int cwd)
for (i = 0; i < path->dim; i++)
{
char *p = (char *)path->data[i];
char *p = path->tdata()[i];
char *n = combine(p, name);
if (exists(n))
@@ -839,7 +839,7 @@ char *FileName::searchPath(Array *path, const char *name, int cwd)
* !=NULL mem.malloc'd file name
*/
char *FileName::safeSearchPath(Array *path, const char *name)
char *FileName::safeSearchPath(Strings *path, const char *name)
{
#if _WIN32
/* Disallow % / \ : and .. in name characters
@@ -876,7 +876,7 @@ char *FileName::safeSearchPath(Array *path, const char *name)
for (i = 0; i < path->dim; i++)
{
char *cname = NULL;
char *cpath = canonicalName((char *)path->data[i]);
char *cpath = canonicalName(path->tdata()[i]);
//printf("FileName::safeSearchPath(): name=%s; path=%s; cpath=%s\n",
// name, (char *)path->data[i], cpath);
if (cpath == NULL)
@@ -966,7 +966,7 @@ void FileName::ensurePathExists(const char *path)
{
//printf("mkdir(%s)\n", path);
#if _WIN32
if (mkdir(path))
if (_mkdir(path))
#endif
#if POSIX
if (mkdir(path, 0777))
@@ -1088,13 +1088,13 @@ int File::read()
//printf("File::read('%s')\n",name);
fd = open(name, O_RDONLY);
if (fd == -1)
{ result = errno;
{
//printf("\topen error, errno = %d\n",errno);
goto err1;
}
if (!ref)
mem.free(buffer);
::free(buffer);
ref = 0; // we own the buffer now
//printf("\tfile opened\n");
@@ -1104,7 +1104,7 @@ int File::read()
goto err2;
}
size = buf.st_size;
buffer = (unsigned char *) mem.malloc(size + 2);
buffer = (unsigned char *) ::malloc(size + 2);
if (!buffer)
{
printf("\tmalloc error, errno = %d\n",errno);
@@ -1137,7 +1137,7 @@ int File::read()
err2:
close(fd);
err:
mem.free(buffer);
::free(buffer);
buffer = NULL;
len = 0;
@@ -1158,11 +1158,11 @@ err1:
goto err1;
if (!ref)
mem.free(buffer);
::free(buffer);
ref = 0;
size = GetFileSize(h,NULL);
buffer = (unsigned char *) mem.malloc(size + 2);
buffer = (unsigned char *) ::malloc(size + 2);
if (!buffer)
goto err2;
@@ -1191,7 +1191,7 @@ err1:
err2:
CloseHandle(h);
err:
mem.free(buffer);
::free(buffer);
buffer = NULL;
len = 0;
@@ -1454,23 +1454,23 @@ void File::remove()
#endif
}
Array *File::match(char *n)
Files *File::match(char *n)
{
return match(new FileName(n, 0));
}
Array *File::match(FileName *n)
Files *File::match(FileName *n)
{
#if POSIX
return NULL;
#elif _WIN32
HANDLE h;
WIN32_FIND_DATAA fileinfo;
Array *a;
Files *a;
char *c;
char *name;
a = new Array();
a = new Files();
c = n->toChars();
name = n->name();
h = FindFirstFileA(c,&fileinfo);
@@ -1563,11 +1563,11 @@ OutBuffer::~OutBuffer()
mem.free(data);
}
void *OutBuffer::extractData()
char *OutBuffer::extractData()
{
void *p;
char *p;
p = (void *)data;
p = (char *)data;
data = NULL;
offset = 0;
size = 0;

View File

@@ -1,6 +1,6 @@
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -13,6 +13,9 @@
#include <stdlib.h>
#include <stdarg.h>
#ifdef DEBUG
#include <assert.h>
#endif
#if __DMC__
#pragma once
@@ -68,7 +71,12 @@ longlong randomx();
*/
struct OutBuffer;
struct Array;
// Can't include arraytypes.h here, need to declare these directly.
template <typename TYPE> struct ArrayBase;
typedef ArrayBase<struct File> Files;
typedef ArrayBase<char> Strings;
struct Object
{
@@ -149,14 +157,14 @@ struct FileName : String
static const char *replaceName(const char *path, const char *name);
static char *combine(const char *path, const char *name);
static Array *splitPath(const char *path);
static Strings *splitPath(const char *path);
static FileName *defaultExt(const char *name, const char *ext);
static FileName *forceExt(const char *name, const char *ext);
int equalsExt(const char *ext);
void CopyTo(FileName *to);
static char *searchPath(Array *path, const char *name, int cwd);
static char *safeSearchPath(Array *path, const char *name);
static char *searchPath(Strings *path, const char *name, int cwd);
static char *safeSearchPath(Strings *path, const char *name);
static int exists(const char *name);
static void ensurePathExists(const char *path);
static char *canonicalName(const char *name);
@@ -241,8 +249,8 @@ struct File : Object
* matching File's.
*/
static Array *match(char *);
static Array *match(FileName *);
static Files *match(char *);
static Files *match(FileName *);
// Compare file times.
// Return <0 this < f
@@ -275,7 +283,7 @@ struct OutBuffer : Object
OutBuffer();
~OutBuffer();
void *extractData();
char *extractData();
void mark();
void reserve(unsigned nbytes);
@@ -348,6 +356,48 @@ struct Array : Object
Array *copy();
};
template <typename TYPE>
struct ArrayBase : Array
{
TYPE **tdata()
{
return (TYPE **)data;
}
TYPE*& operator[] (size_t index)
{
#ifdef DEBUG
assert(index < dim);
#endif
return ((TYPE **)data)[index];
}
void insert(size_t index, TYPE *v)
{
Array::insert(index, (void *)v);
}
void insert(size_t index, ArrayBase *a)
{
Array::insert(index, (Array *)a);
}
void append(ArrayBase *a)
{
Array::append((Array *)a);
}
void push(TYPE *a)
{
Array::push((void *)a);
}
ArrayBase *copy()
{
return (ArrayBase *)Array::copy();
}
};
struct Bits : Object
{
unsigned bitdim;

View File

@@ -1,5 +1,5 @@
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -18,7 +18,7 @@
#include "lstring.h"
#include "stringtable.h"
StringTable::StringTable(unsigned size)
void StringTable::init(unsigned size)
{
table = (void **)mem.calloc(size, sizeof(void *));
tabledim = size;

View File

@@ -1,4 +1,4 @@
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
@@ -28,13 +28,13 @@ struct StringValue
Lstring lstring;
};
struct StringTable : Object
struct StringTable
{
void **table;
unsigned count;
unsigned tabledim;
StringTable(unsigned size = 37);
void init(unsigned size = 37);
~StringTable();
StringValue *lookup(const dchar *s, unsigned len);