Skip to content

Commit

Permalink
Replace raw memsets and memcpys
Browse files Browse the repository at this point in the history
  • Loading branch information
yebblies committed Sep 28, 2015
1 parent dadfbab commit be43591
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 55 deletions.
75 changes: 35 additions & 40 deletions src/dscope.d
Original file line number Diff line number Diff line change
Expand Up @@ -141,42 +141,42 @@ enum SCOPEfree = 0x8000; // is on free list

struct Scope
{
Scope* enclosing = null; // enclosing Scope
Scope* enclosing; // enclosing Scope

Module _module = null; // Root module
ScopeDsymbol scopesym = null; // current symbol
ScopeDsymbol sds = null; // if in static if, and declaring new symbols,
Module _module; // Root module
ScopeDsymbol scopesym; // current symbol
ScopeDsymbol sds; // if in static if, and declaring new symbols,
// sds gets the addMember()
FuncDeclaration func = null; // function we are in
Dsymbol parent = null; // parent to use
LabelStatement slabel = null; // enclosing labelled statement
SwitchStatement sw = null; // enclosing switch statement
TryFinallyStatement tf = null; // enclosing try finally statement
OnScopeStatement os = null; // enclosing scope(xxx) statement
Statement sbreak = null; // enclosing statement that supports "break"
Statement scontinue = null; // enclosing statement that supports "continue"
ForeachStatement fes = null; // if nested function for ForeachStatement, this is it
Scope* callsc = null; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__
int inunion = 0; // we're processing members of a union
int nofree = 0; // set if shouldn't free it
int noctor = 0; // set if constructor calls aren't allowed
int intypeof = 0; // in typeof(exp)
VarDeclaration lastVar = null; // Previous symbol used to prevent goto-skips-init
FuncDeclaration func; // function we are in
Dsymbol parent; // parent to use
LabelStatement slabel; // enclosing labelled statement
SwitchStatement sw; // enclosing switch statement
TryFinallyStatement tf; // enclosing try finally statement
OnScopeStatement os; // enclosing scope(xxx) statement
Statement sbreak; // enclosing statement that supports "break"
Statement scontinue; // enclosing statement that supports "continue"
ForeachStatement fes; // if nested function for ForeachStatement, this is it
Scope* callsc; // used for __FUNCTION__, __PRETTY_FUNCTION__ and __MODULE__
int inunion; // we're processing members of a union
int nofree; // set if shouldn't free it
int noctor; // set if constructor calls aren't allowed
int intypeof; // in typeof(exp)
VarDeclaration lastVar; // Previous symbol used to prevent goto-skips-init

/* If minst && !tinst, it's in definitely non-speculative scope (eg. module member scope).
* If !minst && !tinst, it's in definitely speculative scope (eg. template constraint).
* If minst && tinst, it's in instantiated code scope without speculation.
* If !minst && tinst, it's in instantiated code scope with speculation.
*/
Module minst = null; // root module where the instantiated templates should belong to
TemplateInstance tinst = null; // enclosing template instance
Module minst; // root module where the instantiated templates should belong to
TemplateInstance tinst; // enclosing template instance

// primitive flow analysis for constructors
uint callSuper = 0;
uint callSuper;

// primitive flow analysis for field initializations
uint* fieldinit = null;
size_t fieldinit_dim = 0;
uint* fieldinit;
size_t fieldinit_dim;

// alignment for struct members
structalign_t structalign = STRUCTALIGN_DEFAULT;
Expand All @@ -189,21 +189,21 @@ struct Scope

// protection for class members
Prot protection = Prot(PROTpublic);
int explicitProtection = 0; // set if in an explicit protection attribute
int explicitProtection; // set if in an explicit protection attribute

StorageClass stc = 0; // storage class
char* depmsg = null; // customized deprecation message
StorageClass stc; // storage class
char* depmsg; // customized deprecation message

uint flags = 0;
uint flags;

// user defined attributes
UserAttributeDeclaration userAttribDecl = null;
UserAttributeDeclaration userAttribDecl;

DocComment* lastdc = null; // documentation comment for last symbol at this scope
AA* anchorCounts = null; // lookup duplicate anchor name count
Identifier prevAnchor = null; // qualified symbol name of last doc anchor
DocComment* lastdc; // documentation comment for last symbol at this scope
AA* anchorCounts; // lookup duplicate anchor name count
Identifier prevAnchor; // qualified symbol name of last doc anchor

extern (C++) static __gshared Scope* freelist = null;
extern (C++) static __gshared Scope* freelist;

extern (C++) static Scope* alloc()
{
Expand All @@ -222,13 +222,8 @@ struct Scope
extern (C++) static Scope* createGlobal(Module _module)
{
Scope* sc = Scope.alloc();
memset(sc, 0, Scope.sizeof);
sc.structalign = STRUCTALIGN_DEFAULT;
sc.linkage = LINKd;
sc.inlining = PINLINEdefault;
sc.protection = Prot(PROTpublic);
*sc = Scope.init;
sc._module = _module;
sc.tinst = null;
sc.minst = _module;
sc.scopesym = new ScopeDsymbol();
sc.scopesym.symtab = new DsymbolTable();
Expand All @@ -247,7 +242,7 @@ struct Scope
extern (C++) Scope* copy()
{
Scope* sc = Scope.alloc();
memcpy(sc, &this, Scope.sizeof);
*sc = this;
/* Bugzilla 11777: The copied scope should not inherit fieldinit.
*/
sc.fieldinit = null;
Expand Down
2 changes: 0 additions & 2 deletions src/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,6 @@ public:
{
//printf("FuncDeclaration::overloadModMatch('%s')\n", toChars());
Match m;
memset(&m, 0, m.sizeof);
m.last = MATCHnomatch;
overloadApply(this, (Dsymbol s)
{
Expand Down Expand Up @@ -3928,7 +3927,6 @@ extern (C++) FuncDeclaration resolveFuncCall(Loc loc, Scope* sc, Dsymbol s, Obje
return null;
}
Match m;
memset(&m, 0, m.sizeof);
m.last = MATCHnomatch;
functionResolve(&m, s, loc, sc, tiargs, tthis, fargs);
if (m.last > MATCHnomatch && m.lastf)
Expand Down
9 changes: 4 additions & 5 deletions src/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ struct Param
bool verbose; // verbose compile
bool showColumns; // print character (column) numbers in diagnostics
bool vtls; // identify thread local variables
char vgc; // identify gc usage
bool vgc; // identify gc usage
bool vfield; // identify non-mutable field variables
bool vcomplex; // identify complex/imaginary type usage
char symdebug; // insert debug symbolic information
ubyte symdebug; // insert debug symbolic information
bool alwaysframe; // always emit standard stack frame
bool optimize; // run optimizer
bool map; // generate linker .map file
Expand All @@ -88,7 +88,7 @@ struct Param
// 0: don't allow use of deprecated features
// 1: silently allow use of deprecated features
// 2: warn about the use of deprecated features
char useDeprecated;
byte useDeprecated;
bool useAssert; // generate runtime code for assert()'s
bool useInvariants; // generate class invariant checks
bool useIn; // generate precondition checks
Expand All @@ -103,7 +103,7 @@ struct Param
// 0: disable warnings
// 1: warnings as errors
// 2: informational warnings (no errors)
char warnings;
byte warnings;
bool pic; // generate position-independent-code for shared libs
bool color; // use ANSI colors in console output
bool cov; // generate code coverage data
Expand Down Expand Up @@ -314,7 +314,6 @@ struct Global
compiler.vendor = "Digital Mars D";
stdmsg = stdout;
main_d = "__main.d";
memset(&params, 0, Param.sizeof);
errorLimit = 20;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public:
scanloc = Loc(filename, 1, 1);
//printf("Lexer::Lexer(%p,%d)\n",base,length);
//printf("lexer.filename = %s\n", filename);
memset(&token, 0, token.sizeof);
token = Token.init;
this.base = base;
this.end = base + endoffset;
p = base + begoffset;
Expand Down
4 changes: 0 additions & 4 deletions src/opover.d
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@ extern (C++) Expression op_overload(Expression e, Scope* sc)
expandTuples(&args2);
argsset = 1;
Match m;
memset(&m, 0, m.sizeof);
m.last = MATCHnomatch;
if (s)
{
Expand Down Expand Up @@ -966,7 +965,6 @@ extern (C++) Expression op_overload(Expression e, Scope* sc)
expandTuples(&args2);
}
Match m;
memset(&m, 0, m.sizeof);
m.last = MATCHnomatch;
if (s_r)
{
Expand Down Expand Up @@ -1297,7 +1295,6 @@ extern (C++) Expression op_overload(Expression e, Scope* sc)
args2[0] = e.e2;
expandTuples(&args2);
Match m;
memset(&m, 0, m.sizeof);
m.last = MATCHnomatch;
if (s)
{
Expand Down Expand Up @@ -1404,7 +1401,6 @@ extern (C++) Expression compare_overload(BinExp e, Scope* sc, Identifier id)
args2[0] = e.e2;
expandTuples(&args2);
Match m;
memset(&m, 0, m.sizeof);
m.last = MATCHnomatch;
if (0 && s && s_r)
{
Expand Down
2 changes: 1 addition & 1 deletion src/root/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public:

void zero()
{
memset(data, 0, dim * (data[0]).sizeof);
data[0 .. dim] = T.init;
}

T pop()
Expand Down
2 changes: 1 addition & 1 deletion src/scanmscoff.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern (C++) void scanMSCoffObjModule(void* pctx, void function(void* pctx, char
header_old = cast(IMAGE_FILE_HEADER*)malloc(IMAGE_FILE_HEADER.sizeof);
memcpy(header_old, buf, IMAGE_FILE_HEADER.sizeof);
header = cast(BIGOBJ_HEADER*)malloc(BIGOBJ_HEADER.sizeof);
memset(header, 0, BIGOBJ_HEADER.sizeof);
*header = BIGOBJ_HEADER.init;
header.Machine = header_old.Machine;
header.NumberOfSections = header_old.NumberOfSections;
header.TimeDateStamp = header_old.TimeDateStamp;
Expand Down
1 change: 0 additions & 1 deletion src/target.d
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ struct Target
{
// We support up to 512-bit values.
ubyte[64] buffer;
memset(buffer.ptr, 0, buffer.sizeof);
assert(e.type.size() == type.size());
// Write the expression into the buffer.
switch (e.type.ty)
Expand Down

0 comments on commit be43591

Please sign in to comment.