From 26102ea9fae6385ec4d8140c0cb07eb191781f3b Mon Sep 17 00:00:00 2001 From: David Held Date: Sat, 14 Jul 2012 17:14:07 -0700 Subject: [PATCH 1/2] Remove dead code in root.*, refactor redundant code: * wchar*() not used * bstr*() not used * Merged TYPEDEFS into port.h * randomx() not used * String.ref not used * String itself only used in FileName * All uses of FileName set ref=0 * FileName(path, name) not used * error_mem() not used --- src/doc.c | 2 +- src/libmscoff.c | 2 +- src/libomf.c | 2 +- src/module.c | 6 +-- src/root/port.h | 10 ++-- src/root/root.c | 107 ++++------------------------------------- src/root/root.h | 41 ++-------------- src/root/stringtable.c | 1 + 8 files changed, 26 insertions(+), 145 deletions(-) diff --git a/src/doc.c b/src/doc.c index e9631c420726..4ffd5b033e85 100644 --- a/src/doc.c +++ b/src/doc.c @@ -233,7 +233,7 @@ void Module::gendocfile() // Override with the ddoc macro files from the command line for (size_t i = 0; i < global.params.ddocfiles->dim; i++) { - FileName f((*global.params.ddocfiles)[i], 0); + FileName f((*global.params.ddocfiles)[i]); File file(&f); file.readv(); // BUG: convert file contents to UTF-8 before use diff --git a/src/libmscoff.c b/src/libmscoff.c index 07df07f8babb..d3a909137a16 100644 --- a/src/libmscoff.c +++ b/src/libmscoff.c @@ -311,7 +311,7 @@ void LibMSCoff::addObject(const char *module_name, void *buf, size_t buflen) int fromfile = 0; if (!buf) { assert(module_name[0]); - FileName f((char *)module_name, 0); + FileName f((char *)module_name); File file(&f); file.readv(); buf = file.buffer; diff --git a/src/libomf.c b/src/libomf.c index 7465befe8cd6..5cd6b7be75e7 100644 --- a/src/libomf.c +++ b/src/libomf.c @@ -422,7 +422,7 @@ void LibOMF::addObject(const char *module_name, void *buf, size_t buflen) #endif if (!buf) { assert(module_name); - FileName f((char *)module_name, 0); + FileName f((char *)module_name); File file(&f); file.readv(); buf = file.buffer; diff --git a/src/module.c b/src/module.c index d7ab58d635b4..923af35879d4 100644 --- a/src/module.c +++ b/src/module.c @@ -150,7 +150,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen #endif if (global.params.objname) - objfilename = new FileName(argobj, 0); + objfilename = new FileName(argobj); else objfilename = FileName::forceExt(argobj, global.obj_ext); @@ -188,7 +188,7 @@ void Module::setDocfile() argdoc = FileName::combine(global.params.docdir, argdoc); } if (global.params.docname) - docfilename = new FileName(argdoc, 0); + docfilename = new FileName(argdoc); else docfilename = FileName::forceExt(argdoc, global.doc_ext); @@ -216,7 +216,7 @@ void Module::setHdrfile() arghdr = FileName::combine(global.params.hdrdir, arghdr); } if (global.params.hdrname) - hdrfilename = new FileName(arghdr, 0); + hdrfilename = new FileName(arghdr); else hdrfilename = FileName::forceExt(arghdr, global.hdr_ext); diff --git a/src/root/port.h b/src/root/port.h index 790a941b9c56..1d09f3eb77c9 100644 --- a/src/root/port.h +++ b/src/root/port.h @@ -15,16 +15,16 @@ #ifndef TYPEDEFS #define TYPEDEFS -#include - #if _MSC_VER -typedef __int64 longlong; -typedef unsigned __int64 ulonglong; - +#include // for _isnan +#include // for alloca // According to VC 8.0 docs, long double is the same as double longdouble strtold(const char *p,char **endp); #define strtof strtod +#define isnan _isnan +typedef __int64 longlong; +typedef unsigned __int64 ulonglong; #else typedef long long longlong; typedef unsigned long long ulonglong; diff --git a/src/root/root.c b/src/root/root.c index 1e8b098e73b3..22f11307e586 100644 --- a/src/root/root.c +++ b/src/root/root.c @@ -56,68 +56,6 @@ extern "C" void __cdecl _assert(void *e, void *f, unsigned line) #endif -/************************************* - * Convert wchar string to ascii string. - */ - -char *wchar2ascii(wchar_t *us) -{ - return wchar2ascii(us, wcslen(us)); -} - -char *wchar2ascii(wchar_t *us, unsigned len) -{ - unsigned i; - char *p; - - p = (char *)mem.malloc(len + 1); - for (i = 0; i <= len; i++) - p[i] = (char) us[i]; - return p; -} - -int wcharIsAscii(wchar_t *us) -{ - return wcharIsAscii(us, wcslen(us)); -} - -int wcharIsAscii(wchar_t *us, unsigned len) -{ - unsigned i; - - for (i = 0; i <= len; i++) - { - if (us[i] & ~0xFF) // if high bits set - return 0; // it's not ascii - } - return 1; -} - - -/*********************************** - * Compare length-prefixed strings (bstr). - */ - -int bstrcmp(unsigned char *b1, unsigned char *b2) -{ - return (*b1 == *b2 && memcmp(b1 + 1, b2 + 1, *b2) == 0) ? 0 : 1; -} - -/*************************************** - * Convert bstr into a malloc'd string. - */ - -char *bstr2str(unsigned char *b) -{ - char *s; - unsigned len; - - len = *b; - s = (char *) mem.malloc(len + 1); - s[len] = 0; - return (char *)memcpy(s,b + 1,len); -} - /************************************** * Print error message and exit. */ @@ -136,11 +74,6 @@ void error(const char *format, ...) exit(EXIT_FAILURE); } -void error_mem() -{ - error("out of memory"); -} - /************************************** * Print warning message. */ @@ -200,10 +133,9 @@ void Object::mark() /****************************** String ********************************/ -String::String(char *str, int ref) +String::String(char *str) + : str(mem.strdup(str)) { - this->str = ref ? str : mem.strdup(str); - this->ref = ref; } String::~String() @@ -291,8 +223,8 @@ void String::print() /****************************** FileName ********************************/ -FileName::FileName(char *str, int ref) - : String(str,ref) +FileName::FileName(char *str) + : String(str) { } @@ -326,11 +258,6 @@ char *FileName::combine(const char *path, const char *name) return f; } -FileName::FileName(char *path, char *name) - : String(combine(path,name),1) -{ -} - // Split a path into an Array of paths Strings *FileName::splitPath(const char *path) { @@ -678,7 +605,7 @@ FileName *FileName::defaultExt(const char *name, const char *ext) e = FileName::ext(name); if (e) // if already has an extension - return new FileName((char *)name, 0); + return new FileName((char *)name); len = strlen(name); extlen = strlen(ext); @@ -686,7 +613,7 @@ FileName *FileName::defaultExt(const char *name, const char *ext) memcpy(s,name,len); s[len] = '.'; memcpy(s + len + 1, ext, extlen + 1); - return new FileName(s, 0); + return new FileName(s); } /*************************** @@ -708,7 +635,7 @@ FileName *FileName::forceExt(const char *name, const char *ext) s = (char *)alloca(len + extlen + 1); memcpy(s,name,len); memcpy(s + len, ext, extlen + 1); - return new FileName(s, 0); + return new FileName(s); } else return defaultExt(name, ext); // doesn't have one @@ -1008,7 +935,7 @@ File::File(char *n) buffer = NULL; len = 0; touchtime = NULL; - name = new FileName(n, 0); + name = new FileName(n); } File::~File() @@ -1418,7 +1345,7 @@ void File::remove() Files *File::match(char *n) { - return match(new FileName(n, 0)); + return match(new FileName(n)); } Files *File::match(FileName *n) @@ -1866,6 +1793,7 @@ char *OutBuffer::toChars() return (char *)data; } +// TODO: Remove (only used by disabled GC) /********************************* Bits ****************************/ Bits::Bits() @@ -1958,18 +1886,3 @@ void Bits::sub(Bits *b) for (u = 0; u < allocdim; u++) data[u] &= ~b->data[u]; } - - - - - - - - - - - - - - - diff --git a/src/root/root.h b/src/root/root.h index 842222e37d1e..bdfc45bc06da 100644 --- a/src/root/root.h +++ b/src/root/root.h @@ -15,6 +15,7 @@ #ifdef DEBUG #include #endif +#include "port.h" #if __DMC__ #pragma once @@ -22,38 +23,6 @@ typedef size_t hash_t; -#include "longdouble.h" - -char *wchar2ascii(wchar_t *); -int wcharIsAscii(wchar_t *); -char *wchar2ascii(wchar_t *, unsigned len); -int wcharIsAscii(wchar_t *, unsigned len); - -int bstrcmp(unsigned char *s1, unsigned char *s2); -char *bstr2str(unsigned char *b); - -#ifndef TYPEDEFS -#define TYPEDEFS - -#if _MSC_VER -#include // for _isnan -#include // for alloca -// According to VC 8.0 docs, long double is the same as double -longdouble strtold(const char *p,char **endp); -#define strtof strtod -#define isnan _isnan - -typedef __int64 longlong; -typedef unsigned __int64 ulonglong; -#else -typedef long long longlong; -typedef unsigned long long ulonglong; -#endif - -#endif - -longlong randomx(); - /* * Root of our class library. */ @@ -107,11 +76,9 @@ struct Object struct String : Object { - int ref; // != 0 if this is a reference to someone else's string char *str; // the string itself - String(char *str, int ref = 1); - + String(char *str); ~String(); static hash_t calcHash(const char *str, size_t len); @@ -127,8 +94,7 @@ struct String : Object struct FileName : String { - FileName(char *str, int ref); - FileName(char *path, char *name); + FileName(char *str); hash_t hashCode(); int equals(Object *obj); static int equals(const char *name1, const char *name2); @@ -378,6 +344,7 @@ struct ArrayBase : Array } }; +// TODO: Remove (only used by disabled GC) struct Bits : Object { unsigned bitdim; diff --git a/src/root/stringtable.c b/src/root/stringtable.c index 58dcd0b68277..3a6191b4ec27 100644 --- a/src/root/stringtable.c +++ b/src/root/stringtable.c @@ -17,6 +17,7 @@ #include "rmem.h" // mem #include "stringtable.h" +// TODO: Merge with root.String hash_t calcHash(const char *str, size_t len) { hash_t hash = 0; From 15d0705cce3bc003cbaf66e4551cbb293d556a2f Mon Sep 17 00:00:00 2001 From: David Held Date: Sat, 14 Jul 2012 22:45:26 -0700 Subject: [PATCH 2/2] Restore to fix build break on Posix. --- src/root/port.c | 10 +++++++--- src/root/port.h | 7 +------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/root/port.c b/src/root/port.c index d2bcf0670957..bfe67ac5731c 100644 --- a/src/root/port.c +++ b/src/root/port.c @@ -1,10 +1,11 @@ -// Copyright (c) 1999-2011 by Digital Mars +// Copyright (c) 1999-2012 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com #include "port.h" + #if __DMC__ #include #include @@ -12,6 +13,7 @@ #include #include #include +#include double Port::nan = NAN; double Port::infinity = INFINITY; @@ -127,6 +129,7 @@ char *Port::strupr(char *s) #include #include #include +#include #include #include // for std::numeric_limits @@ -343,6 +346,7 @@ char *Port::strupr(char *s) #include #include #include +#include #include #include @@ -510,7 +514,7 @@ char *Port::strupr(char *s) #endif -#if __sun&&__SVR4 +#if __sun && __SVR4 #define __C99FEATURES__ 1 // Needed on Solaris for NaN and more #include @@ -520,6 +524,7 @@ char *Port::strupr(char *s) #include #include #include +#include #include #include @@ -648,4 +653,3 @@ char *Port::strupr(char *s) } #endif - diff --git a/src/root/port.h b/src/root/port.h index 1d09f3eb77c9..d18d88e8c758 100644 --- a/src/root/port.h +++ b/src/root/port.h @@ -1,5 +1,5 @@ -// Copyright (c) 1999-2009 by Digital Mars +// Copyright (c) 1999-2012 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com @@ -12,9 +12,6 @@ #include "longdouble.h" -#ifndef TYPEDEFS -#define TYPEDEFS - #if _MSC_VER #include // for _isnan #include // for alloca @@ -30,8 +27,6 @@ typedef long long longlong; typedef unsigned long long ulonglong; #endif -#endif - typedef double d_time; struct Port