diff --git a/internal/aApply.d b/internal/aApply.d index 27391402a..e13fc2761 100644 --- a/internal/aApply.d +++ b/internal/aApply.d @@ -32,7 +32,7 @@ extern (C) int _aApplycd1(char[] aa, dg_t dg) d = std.utf.decode(aa, i); else i++; - result = dg((void *)&d); + result = dg(cast(void *)&d); if (result) break; } @@ -53,7 +53,7 @@ extern (C) int _aApplywd1(wchar[] aa, dg_t dg) d = std.utf.decode(aa, i); else i++; - result = dg((void *)&d); + result = dg(cast(void *)&d); if (result) break; } @@ -78,7 +78,7 @@ extern (C) int _aApplycw1(char[] aa, dg_t dg) else { w = (((d - 0x10000) >> 10) & 0x3FF) + 0xD800; - result = dg((void *)&w); + result = dg(cast(void *)&w); if (result) break; w = ((d - 0x10000) & 0x3FF) + 0xDC00; @@ -86,7 +86,7 @@ extern (C) int _aApplycw1(char[] aa, dg_t dg) } else i++; - result = dg((void *)&w); + result = dg(cast(void *)&w); if (result) break; } @@ -114,7 +114,7 @@ extern (C) int _aApplywc1(wchar[] aa, dg_t dg) b = std.utf.toUTF8(buf, d); foreach (char c; b) { - result = dg((void *)&c); + result = dg(cast(void *)&c); if (result) return result; } @@ -124,7 +124,7 @@ extern (C) int _aApplywc1(wchar[] aa, dg_t dg) { c = cast(char)w; i++; } - result = dg((void *)&c); + result = dg(cast(void *)&c); if (result) break; } @@ -147,7 +147,7 @@ extern (C) int _aApplydc1(dchar[] aa, dg_t dg) b = std.utf.toUTF8(buf, d); foreach (char c; b) { - result = dg((void *)&c); + result = dg(cast(void *)&c); if (result) return result; } @@ -157,7 +157,7 @@ extern (C) int _aApplydc1(dchar[] aa, dg_t dg) { c = cast(char)d; } - result = dg((void *)&c); + result = dg(cast(void *)&c); if (result) break; } @@ -177,12 +177,12 @@ extern (C) int _aApplydw1(dchar[] aa, dg_t dg) else { w = (((d - 0x10000) >> 10) & 0x3FF) + 0xD800; - result = dg((void *)&w); + result = dg(cast(void *)&w); if (result) break; w = ((d - 0x10000) & 0x3FF) + 0xDC00; } - result = dg((void *)&w); + result = dg(cast(void *)&w); if (result) break; } @@ -214,7 +214,7 @@ extern (C) int _aApplycd2(char[] aa, dg2_t dg) } else n = 1; - result = dg(&i, (void *)&d); + result = dg(&i, cast(void *)&d); if (result) break; } @@ -240,7 +240,7 @@ extern (C) int _aApplywd2(wchar[] aa, dg2_t dg) } else n = 1; - result = dg(&i, (void *)&d); + result = dg(&i, cast(void *)&d); if (result) break; } @@ -268,7 +268,7 @@ extern (C) int _aApplycw2(char[] aa, dg2_t dg) else { w = (((d - 0x10000) >> 10) & 0x3FF) + 0xD800; - result = dg(&i, (void *)&w); + result = dg(&i, cast(void *)&w); if (result) break; w = ((d - 0x10000) & 0x3FF) + 0xDC00; @@ -276,7 +276,7 @@ extern (C) int _aApplycw2(char[] aa, dg2_t dg) } else n = 1; - result = dg(&i, (void *)&w); + result = dg(&i, cast(void *)&w); if (result) break; } @@ -307,7 +307,7 @@ extern (C) int _aApplywc2(wchar[] aa, dg2_t dg) b = std.utf.toUTF8(buf, d); foreach (char c; b) { - result = dg(&i, (void *)&c); + result = dg(&i, cast(void *)&c); if (result) return result; } @@ -317,7 +317,7 @@ extern (C) int _aApplywc2(wchar[] aa, dg2_t dg) { c = cast(char)w; n = 1; } - result = dg(&i, (void *)&c); + result = dg(&i, cast(void *)&c); if (result) break; } @@ -343,7 +343,7 @@ extern (C) int _aApplydc2(dchar[] aa, dg2_t dg) b = std.utf.toUTF8(buf, d); foreach (char c; b) { - result = dg(&i, (void *)&c); + result = dg(&i, cast(void *)&c); if (result) return result; } @@ -352,7 +352,7 @@ extern (C) int _aApplydc2(dchar[] aa, dg2_t dg) else { c = cast(char)d; } - result = dg(&i, (void *)&c); + result = dg(&i, cast(void *)&c); if (result) break; } @@ -372,12 +372,12 @@ extern (C) int _aApplydw2(dchar[] aa, dg2_t dg) else { w = (((d - 0x10000) >> 10) & 0x3FF) + 0xD800; - result = dg(&i, (void *)&w); + result = dg(&i, cast(void *)&w); if (result) break; w = ((d - 0x10000) & 0x3FF) + 0xDC00; } - result = dg(&i, (void *)&w); + result = dg(&i, cast(void *)&w); if (result) break; } diff --git a/internal/aaA.d b/internal/aaA.d index bb23c2cc1..e96c585bd 100644 --- a/internal/aaA.d +++ b/internal/aaA.d @@ -160,7 +160,7 @@ void *_aaGet(aaA*[] *aa, TypeInfo keyti, int valuesize, ...) } body { - void *pkey = (void *)(&valuesize + 1); + void *pkey = cast(void *)(&valuesize + 1); uint key_hash; uint i; aaA *e; @@ -197,12 +197,12 @@ void *_aaGet(aaA*[] *aa, TypeInfo keyti, int valuesize, ...) // Not found, create new elem //printf("create new one\n"); - e = (aaA *) (void*) new byte[aaA.size + keysize + valuesize]; + e = cast(aaA *) cast(void*) new byte[aaA.size + keysize + valuesize]; memcpy(e + 1, pkey, keysize); e.hash = key_hash; *pe = e; Lret: - return (void *)(e + 1) + keysize; + return cast(void *)(e + 1) + keysize; } /************************************************* @@ -222,7 +222,7 @@ int _aaIn(aaA*[] aa, TypeInfo keyti, ...) } body { - void *pkey = (void *)(&keyti + 1); + void *pkey = cast(void *)(&keyti + 1); uint key_hash; uint i; aaA *e; @@ -262,7 +262,7 @@ int _aaIn(aaA*[] aa, TypeInfo keyti, ...) void _aaDel(aaA*[] aa, TypeInfo keyti, ...) { - void *pkey = (void *)(&keyti + 1); + void *pkey = cast(void *)(&keyti + 1); uint key_hash; uint i; aaA *e; @@ -347,7 +347,7 @@ void _aaValues_x(aaA *e, void *ptr, inout uint resi, uint k, uint v) { do { - memcpy(ptr + resi * v, (byte*)e + aaA.size + k, v); + memcpy(ptr + resi * v, cast(byte*)e + aaA.size + k, v); resi++; if (e.left) _aaValues_x(e.left, ptr, resi, k, v); @@ -510,7 +510,7 @@ int _aaApply(aaA*[] aa, int keysize, dg_t dg) do { //printf("treewalker(e = %p, dg = x%llx)\n", e, dg); - result = dg((void *)(e + 1) + keysize); + result = dg(cast(void *)(e + 1) + keysize); if (result) break; if (e.right) @@ -550,7 +550,7 @@ int _aaApply2(aaA*[] aa, int keysize, dg2_t dg) do { //printf("treewalker(e = %p, dg = x%llx)\n", e, dg); - result = dg((void *)(e + 1), (void *)(e + 1) + keysize); + result = dg(cast(void *)(e + 1), cast(void *)(e + 1) + keysize); if (result) break; if (e.right) diff --git a/internal/adi.d b/internal/adi.d index 7130474bc..e2e549710 100644 --- a/internal/adi.d +++ b/internal/adi.d @@ -44,7 +44,7 @@ extern (C) Array _adReverse(Array a, int szelem) if (szelem > 16) { //version (Win32) - tmp = (byte*) alloca(szelem); + tmp = cast(byte*) alloca(szelem); //else //tmp = new byte[szelem]; } @@ -168,7 +168,7 @@ extern (C) Array _adDup(Array a, int szelem) int size; size = a.length * szelem; - r.ptr = (void *) new byte[size]; + r.ptr = cast(void *) new byte[size]; r.length = a.length; memcpy(r.ptr, a.ptr, size); return r; @@ -205,7 +205,7 @@ extern (C) Array _adDupBit(Array a) int size; size = (a.length + 31) / 32; - r.ptr = (void *) new uint[size]; + r.ptr = cast(void *) new uint[size]; r.length = a.length; memcpy(r.ptr, a.ptr, size); return r; @@ -470,7 +470,7 @@ else len = a1.length; if (a2.length < len) len = a2.length; - c = string.memcmp((char *)a1.ptr, (char *)a2.ptr, len); + c = string.memcmp(cast(char *)a1.ptr, cast(char *)a2.ptr, len); if (!c) c = cast(int)a1.length - cast(int)a2.length; return c; @@ -518,7 +518,7 @@ extern (C) int _adCmpBit(Array a1, Array a2) { ubyte mask = 1 << j; int c; - c = (int)(p1[i] & mask) - (int)(p2[i] & mask); + c = cast(int)(p1[i] & mask) - cast(int)(p2[i] & mask); if (c) return c; } diff --git a/internal/arraycast.d b/internal/arraycast.d index bdca09f8e..ba58e1029 100644 --- a/internal/arraycast.d +++ b/internal/arraycast.d @@ -20,7 +20,7 @@ void[] _d_arraycast(uint tsize, uint fsize, void[] a) throw new Error("array cast misalignment"); } length = nbytes / tsize; - *(uint *)&a = length; // jam new length + *cast(uint *)&a = length; // jam new length return a; } @@ -58,7 +58,7 @@ void[] _d_arraycast_frombit(uint tsize, void[] a) throw new Error("bit[] array cast misalignment"); } length /= 8 * tsize; - *(uint *)&a = length; // jam new length + *cast(uint *)&a = length; // jam new length return a; } diff --git a/internal/arraycat.d b/internal/arraycat.d index 384067d6b..1477d568c 100644 --- a/internal/arraycat.d +++ b/internal/arraycat.d @@ -19,7 +19,7 @@ byte[] _d_arraycat(byte[] x, byte[] y, uint size) memcpy(a, x, x.length * size); //a[0 .. x.length * size] = x[]; memcpy(&a[x.length * size], y, y.length * size); - *(int *)&a = length; // jam length + *cast(int *)&a = length; // jam length //a.length = length; return a; } @@ -55,7 +55,7 @@ byte[] _d_arraycatn(uint size, uint n, ...) } } - *(int *)&a = length; // jam length + *cast(int *)&a = length; // jam length //a.length = length; return a; } @@ -68,10 +68,10 @@ byte[] _d_arraycopy(uint size, byte[] from, byte[] to) { throw new Error("lengths don't match for array copy"); } - else if ((byte *)to + to.length * size <= (byte *)from || - (byte *)from + from.length * size <= (byte *)to) + else if (cast(byte *)to + to.length * size <= cast(byte *)from || + cast(byte *)from + from.length * size <= cast(byte *)to) { - memcpy((byte *)to, (byte *)from, to.length * size); + memcpy(cast(byte *)to, cast(byte *)from, to.length * size); } else { @@ -92,10 +92,10 @@ bit[] _d_arraycopybit(bit[] from, bit[] to) else { nbytes = (to.length + 7) / 8; - if ((void *)to + nbytes <= (void *)from || - (void *)from + nbytes <= (void *)to) + if (cast(void *)to + nbytes <= cast(void *)from || + cast(void *)from + nbytes <= cast(void *)to) { - memcpy((void *)to, (void *)from, nbytes); + memcpy(cast(void *)to, cast(void *)from, nbytes); } else { diff --git a/internal/cast.d b/internal/cast.d index 397d02413..caa1d41b2 100644 --- a/internal/cast.d +++ b/internal/cast.d @@ -14,7 +14,7 @@ Object _d_interface_cast(void* p, ClassInfo c) if (p) { - Interface *pi = **(Interface ***)p; + Interface *pi = **cast(Interface ***)p; o = cast(Object)(p - pi.offset); return _d_dynamic_cast(o, c); @@ -106,7 +106,7 @@ void *_d_interface_vtbl(ClassInfo ic, Object o) oic = oc.interfaces[i].classinfo; if (oic === ic) { - return (void *)oc.interfaces[i].vtbl; + return cast(void *)oc.interfaces[i].vtbl; } } assert(0); diff --git a/internal/critical.c b/internal/critical.c index ea584a1c8..096dca46b 100644 --- a/internal/critical.c +++ b/internal/critical.c @@ -1,4 +1,4 @@ -// Copyright (C) 2000-2003 by Digital Mars, www.digitalmars.com +// Copyright (C) 2000-2004 by Digital Mars, www.digitalmars.com // All Rights Reserved // Written by Walter Bright @@ -94,6 +94,7 @@ typedef struct D_CRITICAL_SECTION static D_CRITICAL_SECTION *dcs_list; static D_CRITICAL_SECTION critical_section; +static pthread_mutexattr_t _criticals_attr; static volatile int inited; void _d_criticalenter(D_CRITICAL_SECTION *dcs) @@ -105,7 +106,7 @@ void _d_criticalenter(D_CRITICAL_SECTION *dcs) { dcs->next = dcs_list; dcs_list = dcs; - pthread_mutex_init(&dcs->cs, 0); + pthread_mutex_init(&dcs->cs, &_criticals_attr); } pthread_mutex_unlock(&critical_section.cs); } @@ -120,7 +121,11 @@ void _d_criticalexit(D_CRITICAL_SECTION *dcs) void _STI_critical_init() { if (!inited) - { pthread_mutex_init(&critical_section.cs, 0); + { pthread_mutexattr_init(&_criticals_attr); + pthread_mutexattr_settype(&_criticals_attr, PTHREAD_MUTEX_RECURSIVE_NP); + + // The global critical section doesn't need to be recursive + pthread_mutex_init(&critical_section.cs, 0); inited = 1; } } diff --git a/internal/deh2.d b/internal/deh2.d index be0d4bd2c..ab5df8ab0 100644 --- a/internal/deh2.d +++ b/internal/deh2.d @@ -77,15 +77,15 @@ DHandlerTable *__eh_finddata(void *address) // debug printf("__eh_finddata(address = x%x)\n", address); // debug printf("_deh_beg = x%x, _deh_end = x%x\n", &_deh_beg, &_deh_end); - for (ft = (FuncTable *)&_deh_beg; - ft < (FuncTable *)&_deh_end; + for (ft = cast(FuncTable *)&_deh_beg; + ft < cast(FuncTable *)&_deh_end; ft++) { // debug printf("\tfptr = x%x, fsize = x%03x, handlertable = x%x\n", // ft.fptr, ft.fsize, ft.handlertable); if (ft.fptr <= address && - address < (void *)((char *)ft.fptr + ft.fsize)) + address < cast(void *)(cast(char *)ft.fptr + ft.fsize)) { // debug printf("\tfound handler table\n"); return ft.handlertable; @@ -109,7 +109,7 @@ DHandlerTable *__eh_finddata(void *address) uint __eh_find_caller(uint regbp, uint *pretaddr) { - uint bp = *(uint *)regbp; + uint bp = *cast(uint *)regbp; if (bp) // if not end of call chain { @@ -119,7 +119,7 @@ uint __eh_find_caller(uint regbp, uint *pretaddr) // stack should grow to smaller values terminate(); - *pretaddr = *(uint *)(regbp + int.size); + *pretaddr = *cast(uint *)(regbp + int.size); } return bp; } @@ -135,7 +135,7 @@ extern (Windows) void _d_throw(Object *h) debug { printf("_d_throw(h = %p, &h = %p)\n", h, &h); - printf("\tvptr = %p\n", *(void **)h); + printf("\tvptr = %p\n", *cast(void **)h); } asm @@ -170,19 +170,19 @@ extern (Windows) void _d_throw(Object *h) debug printf("found caller, EBP = x%x, retaddr = x%x\n", regebp, retaddr); //if (++count == 12) *(char*)0=0; - handler_table = __eh_finddata((void *)retaddr); // find static data associated with function + handler_table = __eh_finddata(cast(void *)retaddr); // find static data associated with function if (!handler_table) // if no static data { debug printf("no handler table\n"); continue; } - funcoffset = (uint)handler_table.fptr; + funcoffset = cast(uint)handler_table.fptr; spoff = handler_table.espoffset; retoffset = handler_table.retoffset; debug { - printf("retaddr = x%x\n",(uint)retaddr); + printf("retaddr = x%x\n",cast(uint)retaddr); printf("regebp=x%04x, funcoffset=x%04x, spoff=x%x, retoffset=x%x\n", regebp,funcoffset,spoff,retoffset); } @@ -226,12 +226,12 @@ extern (Windows) void _d_throw(Object *h) int ncatches; int i; - pci = (DCatchInfo *)((char *)handler_table + phi.cioffset); + pci = cast(DCatchInfo *)(cast(char *)handler_table + phi.cioffset); ncatches = pci.ncatches; for (i = 0; i < ncatches; i++) { DCatchBlock *pcb; - ClassInfo ci = **(ClassInfo **)h; + ClassInfo ci = **cast(ClassInfo **)h; pcb = &pci.catch_block[i]; @@ -239,14 +239,14 @@ extern (Windows) void _d_throw(Object *h) { // Matched the catch type, so we've found the handler. // Initialize catch variable - *(void **)(regebp + (pcb.bpoffset)) = h; + *cast(void **)(regebp + (pcb.bpoffset)) = h; // Jump to catch block. Does not return. { uint catch_esp; fp_t catch_addr; - catch_addr = (fp_t)(pcb.code); + catch_addr = cast(fp_t)(pcb.code); catch_esp = regebp - handler_table.espoffset - fp_t.size; asm { diff --git a/internal/dmain2.d b/internal/dmain2.d index 54e58904c..ff56ae8fa 100644 --- a/internal/dmain2.d +++ b/internal/dmain2.d @@ -40,7 +40,7 @@ extern (C) int main(int argc, char **argv) _STI_monitor_staticctor(); _STI_critical_init(); gc_init(); - am = (char[] *) malloc(argc * (char[]).size); + am = cast(char[] *) malloc(argc * (char[]).size); // BUG: alloca() conflicts with try-catch-finally stack unwinding //am = (char[] *) alloca(argc * (char[]).size); } @@ -48,7 +48,7 @@ extern (C) int main(int argc, char **argv) { gc_init(); _minit(); - am = (char[] *) alloca(argc * (char[]).size); + am = cast(char[] *) alloca(argc * (char[]).size); } try diff --git a/internal/gc/gc.d b/internal/gc/gc.d index 1b698de5f..d86d691aa 100644 --- a/internal/gc/gc.d +++ b/internal/gc/gc.d @@ -35,9 +35,12 @@ void getStats(out GCStats stats) { _gc.getStats(stats); } extern (C) { +void _d_monitorrelease(Object h); + + void gc_init() { - _gc = (GC *) std.c.stdlib.calloc(1, GC.size); + _gc = cast(GC *) std.c.stdlib.calloc(1, GC.size); _gc.initialize(); //_gc.setStackBottom(_atopsp); _gc.scanStaticData(); @@ -55,7 +58,7 @@ Object _d_newclass(ClassInfo ci) debug(PRINTF) printf("_d_newclass(ci = %p)\n", ci); if (ci.flags & 1) // if COM object { - p = (Object)std.c.stdlib.malloc(ci.init.length); + p = cast(Object)std.c.stdlib.malloc(ci.init.length); if (!p) _d_OutOfMemory(); } @@ -70,22 +73,22 @@ Object _d_newclass(ClassInfo ci) { printf("p = %p\n", p); printf("ci = %p, ci.init = %p, len = %d\n", ci, ci.init, ci.init.length); - printf("vptr = %p\n", *(void **)ci.init); - printf("vtbl[0] = %p\n", (*(void ***)ci.init)[0]); - printf("vtbl[1] = %p\n", (*(void ***)ci.init)[1]); - printf("init[0] = %x\n", ((uint *)ci.init)[0]); - printf("init[1] = %x\n", ((uint *)ci.init)[1]); - printf("init[2] = %x\n", ((uint *)ci.init)[2]); - printf("init[3] = %x\n", ((uint *)ci.init)[3]); - printf("init[4] = %x\n", ((uint *)ci.init)[4]); + printf("vptr = %p\n", *cast(void **)ci.init); + printf("vtbl[0] = %p\n", (*cast(void ***)ci.init)[0]); + printf("vtbl[1] = %p\n", (*cast(void ***)ci.init)[1]); + printf("init[0] = %x\n", (cast(uint *)ci.init)[0]); + printf("init[1] = %x\n", (cast(uint *)ci.init)[1]); + printf("init[2] = %x\n", (cast(uint *)ci.init)[2]); + printf("init[3] = %x\n", (cast(uint *)ci.init)[3]); + printf("init[4] = %x\n", (cast(uint *)ci.init)[4]); } // Initialize it - ((byte*)p)[0 .. ci.init.length] = ci.init[]; + (cast(byte*)p)[0 .. ci.init.length] = ci.init[]; //printf("initialization done\n"); - return (Object)p; + return cast(Object)p; } extern (D) alias void (*fp_t)(Object); // generic function pointer @@ -94,7 +97,7 @@ void _d_delinterface(void** p) { if (*p) { - Interface *pi = **(Interface ***)*p; + Interface *pi = **cast(Interface ***)*p; Object o; o = cast(Object)(*p - pi.offset); @@ -110,21 +113,16 @@ void _d_delclass(Object *p) debug (PRINTF) printf("_d_delclass(%p)\n", *p); version(0) { - ClassInfo **pc = (ClassInfo **)*p; + ClassInfo **pc = cast(ClassInfo **)*p; if (*pc) { ClassInfo c = **pc; if (c.deallocator) { - if (c.destructor) - { - fp_t fp = (fp_t)c.destructor; - (*fp)(*p); // call destructor - } - fp_t fp = (fp_t)c.deallocator; + _d_callfinalizer(*p); + fp_t fp = cast(fp_t)c.deallocator; (*fp)(*p); // call deallocator - *pc = null; // zero vptr *p = null; return; } @@ -148,7 +146,7 @@ ulong _d_new(uint length, uint size) p = _gc.malloc(length * size); debug(PRINTF) printf(" p = %p\n", p); memset(p, 0, length * size); - result = (ulong)length + ((ulong)(uint)p << 32); + result = cast(ulong)length + (cast(ulong)cast(uint)p << 32); } return result; } @@ -174,7 +172,7 @@ ulong _d_newarrayi(uint length, uint size, ...) memcpy(p + u * size, q, size); } } - result = (ulong)length + ((ulong)(uint)p << 32); + result = cast(ulong)length + (cast(ulong)cast(uint)p << 32); } return result; } @@ -194,7 +192,7 @@ ulong _d_newbitarray(uint length, bit value) p = _gc.malloc(size); debug(PRINTF) printf(" p = %p\n", p); memset(p, fill, size); - result = (ulong)length + ((ulong)(uint)p << 32); + result = cast(ulong)length + (cast(ulong)cast(uint)p << 32); } return result; } @@ -221,11 +219,12 @@ void _d_delarray(Array *p) } -void _d_delmemory(void* p) +void _d_delmemory(void* *p) { - if (p) + if (*p) { - _gc.free(p); + _gc.free(*p); + *p = null; } } @@ -244,7 +243,7 @@ void _d_callfinalizer(void *p) //printf("_d_callfinalizer(p = %p)\n", p); if (p) // not necessary if called from gc { - ClassInfo **pc = (ClassInfo **)p; + ClassInfo **pc = cast(ClassInfo **)p; if (*pc) { ClassInfo c = **pc; @@ -253,11 +252,13 @@ void _d_callfinalizer(void *p) { if (c.destructor) { - fp_t fp = (fp_t)c.destructor; - (*fp)((Object)p); // call destructor + fp_t fp = cast(fp_t)c.destructor; + (*fp)(cast(Object)p); // call destructor } c = c.base; } while (c); + if ((cast(void**)p)[1]) // if monitor is not null + _d_monitorrelease(cast(Object)p); *pc = null; // zero vptr } } @@ -297,7 +298,7 @@ byte[] _d_arraysetlength(uint newlength, uint sizeelem, Array *p) uint cap = _gc.capacity(p.data); if (cap < newsize) { - newdata = (byte *)_gc.malloc(newsize); + newdata = cast(byte *)_gc.malloc(newsize); newdata[0 .. size] = p.data[0 .. size]; } newdata[size .. newsize] = 0; @@ -305,7 +306,7 @@ byte[] _d_arraysetlength(uint newlength, uint sizeelem, Array *p) } else { - newdata = (byte *)_gc.calloc(newsize, 1); + newdata = cast(byte *)_gc.calloc(newsize, 1); } } else @@ -344,7 +345,7 @@ bit[] _d_arraysetlengthb(uint newlength, Array *p) uint cap = _gc.capacity(p.data); if (cap < newsize) { - newdata = (byte *)_gc.malloc(newsize); + newdata = cast(byte *)_gc.malloc(newsize); newdata[0 .. size] = p.data[0 .. size]; } newdata[size .. newsize] = 0; @@ -352,7 +353,7 @@ bit[] _d_arraysetlengthb(uint newlength, Array *p) } else { - newdata = (byte *)_gc.calloc(newsize, 1); + newdata = cast(byte *)_gc.calloc(newsize, 1); } } else @@ -362,7 +363,7 @@ bit[] _d_arraysetlengthb(uint newlength, Array *p) p.data = newdata; p.length = newlength; - return ((bit *)newdata)[0 .. newlength]; + return (cast(bit *)newdata)[0 .. newlength]; } /**************************************** @@ -380,7 +381,7 @@ Array _d_arrayappend(Array *px, byte[] y, uint size) if (newlength * size > cap) { byte* newdata; - newdata = (byte *)_gc.malloc(newlength * size); + newdata = cast(byte *)_gc.malloc(newlength * size); memcpy(newdata, px.data, length * size); px.data = newdata; } @@ -399,14 +400,14 @@ byte[] _d_arrayappendc(inout byte[] x, in uint size, ...) if (newlength * size > cap) { byte* newdata; - newdata = (byte *)_gc.malloc(newlength * size); + newdata = cast(byte *)_gc.malloc(newlength * size); memcpy(newdata, x, length * size); - ((void **)(&x))[1] = newdata; + (cast(void **)(&x))[1] = newdata; } - byte *argp = (byte *)(&size + 1); + byte *argp = cast(byte *)(&size + 1); - *(int *)&x = newlength; - ((byte *)x)[length * size .. newlength * size] = argp[0 .. size]; + *cast(int *)&x = newlength; + (cast(byte *)x)[length * size .. newlength * size] = argp[0 .. size]; return x; /+ @@ -419,11 +420,11 @@ byte[] _d_arrayappendc(inout byte[] x, in uint size, ...) a = new byte[length * size]; memcpy(a, x, x.length * size); argp = &size + 1; - //printf("*argp = %llx\n", *(long *)argp); + //printf("*argp = %llx\n", *cast(long *)argp); memcpy(&a[x.length * size], argp, size); - //printf("a[0] = %llx\n", *(long *)&a[0]); - *(int *)&a = length; // jam length - //printf("a[0] = %llx\n", *(long *)&a[0]); + //printf("a[0] = %llx\n", *cast(long *)&a[0]); + *cast(int *)&a = length; // jam length + //printf("a[0] = %llx\n", *cast(long *)&a[0]); x = a; return a; +/ diff --git a/internal/gc/gclinux.d b/internal/gc/gclinux.d index 1caac6520..05bdbf8cc 100644 --- a/internal/gc/gclinux.d +++ b/internal/gc/gclinux.d @@ -10,7 +10,7 @@ extern (C) // from void* mmap(void* addr, uint len, int prot, int flags, int fd, uint offset); int munmap(void* addr, uint len); - const void* MAP_FAILED = (void*)-1; + const void* MAP_FAILED = cast(void*)-1; // from enum { PROT_NONE = 0, PROT_READ = 1, PROT_WRITE = 2, PROT_EXEC = 4 } @@ -84,6 +84,6 @@ void *os_query_stackBottom() void os_query_staticdataseg(void **base, uint *nbytes) { - *base = (void *)&__data_start; - *nbytes = (byte *)&_end - (byte *)&__data_start; + *base = cast(void *)&__data_start; + *nbytes = cast(byte *)&_end - cast(byte *)&__data_start; } diff --git a/internal/gc/gcx.d b/internal/gc/gcx.d index 59cefbebe..f09a94b2e 100644 --- a/internal/gc/gcx.d +++ b/internal/gc/gcx.d @@ -1,5 +1,5 @@ // -// Copyright (C) 2001-2003 by Digital Mars +// Copyright (C) 2001-2004 by Digital Mars // All Rights Reserved // Written by Walter Bright // www.digitalmars.com @@ -98,12 +98,12 @@ debug (LOGGING) assert(dim + nentries <= allocdim); if (!data) { - data = (Log *)std.c.stdlib.malloc(allocdim * Log.size); + data = cast(Log *)std.c.stdlib.malloc(allocdim * Log.size); } else { Log *newdata; - newdata = (Log *)std.c.stdlib.malloc(allocdim * Log.size); + newdata = cast(Log *)std.c.stdlib.malloc(allocdim * Log.size); assert(newdata); memcpy(newdata, data, dim * Log.size); std.c.stdlib.free(data); @@ -167,7 +167,7 @@ struct GC void initialize() { gcLock = GCLock.classinfo; - gcx = (Gcx *)std.c.stdlib.calloc(1, Gcx.size); + gcx = cast(Gcx *)std.c.stdlib.calloc(1, Gcx.size); gcx.initialize(); version (Win32) { @@ -242,7 +242,7 @@ struct GC } // Return next item from free list - gcx.bucket[bin] = ((List *)p).next; + gcx.bucket[bin] = (cast(List *)p).next; memset(p + size, 0, binsize[bin] - size); //debug(PRINTF) printf("\tmalloc => %x\n", p); debug (MEMSTOMP) memset(p, 0xF0, size); @@ -350,14 +350,14 @@ struct GC { if (pool.finals.nbits && gcx.finalizer) { - biti = (uint)(p - pool.baseAddr) / 16; + biti = cast(uint)(p - pool.baseAddr) / 16; if (pool.finals.testClear(biti)) { (*gcx.finalizer)(sentinel_add(p), null); } } - bin = (Bins)pool.pagetable[pagenum]; + bin = cast(Bins)pool.pagetable[pagenum]; if (bin == B_PAGE) // if large alloc { int npages; uint n; @@ -372,7 +372,7 @@ struct GC } else { // Add to free list - List *list = (List *)p; + List *list = cast(List *)p; debug (MEMSTOMP) memset(p, 0xF2, binsize[bin]); @@ -401,7 +401,7 @@ struct GC // This depends on: // 1) size is a power of 2 for less than PAGESIZE values // 2) base of memory pool is aligned on PAGESIZE boundary - if ((uint)p & (size - 1) & (PAGESIZE - 1)) + if (cast(uint)p & (size - 1) & (PAGESIZE - 1)) size = 0; return size ? size - SENTINAL_EXTRA : 0; } @@ -416,7 +416,7 @@ struct GC // This depends on: // 1) size is a power of 2 for less than PAGESIZE values // 2) base of memory pool is aligned on PAGESIZE boundary - if ((uint)p & (size - 1) & (PAGESIZE - 1)) + if (cast(uint)p & (size - 1) & (PAGESIZE - 1)) size = 0; else { @@ -454,10 +454,10 @@ struct GC pool = gcx.findPool(p); assert(pool); pagenum = (p - pool.baseAddr) / PAGESIZE; - bin = (Bins)pool.pagetable[pagenum]; + bin = cast(Bins)pool.pagetable[pagenum]; assert(bin <= B_PAGE); size = binsize[bin]; - assert(((uint)p & (size - 1)) == 0); + assert((cast(uint)p & (size - 1)) == 0); debug (PTRCHECK2) { @@ -468,7 +468,7 @@ struct GC for (list = gcx.bucket[bin]; list; list = list.next) { - assert((void *)list != p); + assert(cast(void *)list != p); } } } @@ -495,7 +495,7 @@ struct GC if (p < gcx.stackBottom) { //debug(PRINTF) printf("setStackBottom(%x)\n", p); - gcx.stackBottom = (char *)p; + gcx.stackBottom = cast(char *)p; } } } @@ -639,7 +639,7 @@ struct GC psize += pool.ncommitted * PAGESIZE; for (uint j = 0; j < pool.ncommitted; j++) { - Bins bin = (Bins)pool.pagetable[j]; + Bins bin = cast(Bins)pool.pagetable[j]; if (bin == B_FREE) stats.freeblocks++; else if (bin == B_PAGE) @@ -764,8 +764,8 @@ struct Gcx void initialize() { int dummy; - ((byte *)this)[0 .. Gcx.size] = 0; - stackBottom = (char *)&dummy; + (cast(byte *)this)[0 .. Gcx.size] = 0; + stackBottom = cast(char *)&dummy; log_init(); debug (THREADINVARIANT) self = pthread_self(); @@ -862,7 +862,7 @@ struct Gcx uint newdim = rootdim * 2 + 16; void **newroots; - newroots = (void **)std.c.stdlib.malloc(newdim * newroots[0].size); + newroots = cast(void **)std.c.stdlib.malloc(newdim * newroots[0].size); assert(newroots); if (roots) { memcpy(newroots, roots, nroots * newroots[0].size); @@ -903,7 +903,7 @@ struct Gcx uint newdim = rangedim * 2 + 16; Range *newranges; - newranges = (Range *)std.c.stdlib.malloc(newdim * newranges[0].size); + newranges = cast(Range *)std.c.stdlib.malloc(newdim * newranges[0].size); assert(newranges); if (ranges) { memcpy(newranges, ranges, nranges * newranges[0].size); @@ -985,8 +985,8 @@ struct Gcx uint pagenum; Bins bin; - pagenum = ((uint)(p - pool.baseAddr)) / PAGESIZE; - bin = (Bins)pool.pagetable[pagenum]; + pagenum = (cast(uint)(p - pool.baseAddr)) / PAGESIZE; + bin = cast(Bins)pool.pagetable[pagenum]; size = binsize[bin]; if (bin == B_PAGE) { uint npages = pool.ncommitted; @@ -1118,7 +1118,7 @@ struct Gcx if (npages > 1) memset(&pool.pagetable[pn + 1], B_PAGEPLUS, npages - 1); p = pool.baseAddr + pn * PAGESIZE; - memset((char *)p + size, 0, npages * PAGESIZE - size); + memset(cast(char *)p + size, 0, npages * PAGESIZE - size); debug (MEMSTOMP) memset(p, 0xF1, size); //debug(PRINTF) printf("\tp = %x\n", p); return p; @@ -1163,7 +1163,7 @@ struct Gcx npages = n; } - pool = (Pool *)std.c.stdlib.calloc(1, Pool.size); + pool = cast(Pool *)std.c.stdlib.calloc(1, Pool.size); if (pool) { pool.initialize(npages); @@ -1171,7 +1171,7 @@ struct Gcx goto Lerr; newnpools = npools + 1; - newpooltable = (Pool **)std.c.stdlib.realloc(pooltable, newnpools * (Pool *).size); + newpooltable = cast(Pool **)std.c.stdlib.realloc(pooltable, newnpools * (Pool *).size); if (!newpooltable) goto Lerr; @@ -1224,7 +1224,7 @@ struct Gcx return 0; // failed L1: - pool.pagetable[pn] = (ubyte)bin; + pool.pagetable[pn] = cast(ubyte)bin; // Convert page to free list uint size = binsize[bin]; @@ -1234,8 +1234,8 @@ struct Gcx ptop = p + PAGESIZE; for (; p < ptop; p += size) { - ((List *)p).next = *b; - *b = (List *)p; + (cast(List *)p).next = *b; + *b = cast(List *)p; } return 1; } @@ -1247,15 +1247,15 @@ struct Gcx void mark(void *pbot, void *ptop) { - void **p1 = (void **)pbot; - void **p2 = (void **)ptop; + void **p1 = cast(void **)pbot; + void **p2 = cast(void **)ptop; uint changes = 0; //if (log) debug(PRINTF) printf("Gcx::mark(%x .. %x)\n", pbot, ptop); for (; p1 < p2; p1++) { Pool *pool; - byte *p = (byte *)(*p1); + byte *p = cast(byte *)(*p1); //if (log) debug(PRINTF) printf("\tmark %x\n", p); if (p >= minAddr) @@ -1263,10 +1263,10 @@ struct Gcx pool = findPool(p); if (pool) { - uint offset = (uint)(p - pool.baseAddr); + uint offset = cast(uint)(p - pool.baseAddr); uint biti; uint pn = offset / PAGESIZE; - Bins bin = (Bins)pool.pagetable[pn]; + Bins bin = cast(Bins)pool.pagetable[pn]; //debug(PRINTF) printf("\t\tfound pool %x, base=%x, pn = %d, bin = %d, biti = x%x\n", pool, pool.baseAddr, pn, bin, biti); @@ -1280,7 +1280,7 @@ struct Gcx { do { --pn; - } while ((Bins)pool.pagetable[pn] == B_PAGEPLUS); + } while (cast(Bins)pool.pagetable[pn] == B_PAGEPLUS); biti = pn * (PAGESIZE / 16); } else @@ -1355,7 +1355,7 @@ struct Gcx { pool = findPool(list); assert(pool); - pool.freebits.set((uint)((byte *)list - pool.baseAddr) / 16); + pool.freebits.set(cast(uint)(cast(byte *)list - pool.baseAddr) / 16); } } @@ -1388,7 +1388,7 @@ struct Gcx assert(0); } debug (PRINTF) printf("mt scan stack bot = %x, top = %x\n", context.Esp, t.stackBottom); - mark((void *)context.Esp, t.stackBottom); + mark(cast(void *)context.Esp, t.stackBottom); mark(&context.Edi, &context.Eip); } version (linux) @@ -1473,7 +1473,7 @@ struct Gcx continue; pn = (o - pool.baseAddr) / PAGESIZE; - bin = (Bins)pool.pagetable[pn]; + bin = cast(Bins)pool.pagetable[pn]; if (bin < B_PAGE) { mark(o, o + binsize[bin]); @@ -1509,7 +1509,7 @@ struct Gcx ncommitted = pool.ncommitted; for (pn = 0; pn < ncommitted; pn++, bbase += PAGESIZE / (32 * 16)) { - Bins bin = (Bins)pool.pagetable[pn]; + Bins bin = cast(Bins)pool.pagetable[pn]; if (bin < B_PAGE) { byte *p; @@ -1534,10 +1534,10 @@ struct Gcx if (finalizer && pool.finals.nbits && pool.finals.testClear(biti)) { - (*finalizer)((List *)sentinel_add(p), null); + (*finalizer)(cast(List *)sentinel_add(p), null); } - List *list = (List *)p; + List *list = cast(List *)p; //debug(PRINTF) printf("\tcollecting %x\n", list); log_free(sentinel_add(list)); @@ -1559,10 +1559,10 @@ struct Gcx if (finalizer && pool.finals.nbits && pool.finals.testClear(biti)) { - (*finalizer)((List *)sentinel_add(p), null); + (*finalizer)(cast(List *)sentinel_add(p), null); } - List *list = (List *)p; + List *list = cast(List *)p; debug(PRINTF) printf("\tcollecting %x\n", list); log_free(sentinel_add(list)); @@ -1620,7 +1620,7 @@ struct Gcx ncommitted = pool.ncommitted; for (pn = 0; pn < ncommitted; pn++) { - Bins bin = (Bins)pool.pagetable[pn]; + Bins bin = cast(Bins)pool.pagetable[pn]; uint biti; uint u; @@ -1648,7 +1648,7 @@ struct Gcx if (pool.freebits.test(biti)) { List *list; - list = (List *)(p + u); + list = cast(List *)(p + u); if (list.next != bucket[bin]) // avoid unnecessary writes list.next = bucket[bin]; bucket[bin] = list; @@ -1786,10 +1786,10 @@ struct Gcx Pool *pool; pool = findPool(p); assert(pool); - uint offset = (uint)(p - pool.baseAddr); + uint offset = cast(uint)(p - pool.baseAddr); uint biti; uint pn = offset / PAGESIZE; - Bins bin = (Bins)pool.pagetable[pn]; + Bins bin = cast(Bins)pool.pagetable[pn]; biti = (offset & notbinsize[bin]); debug(PRINTF) printf("\tbin = %d, offset = x%x, biti = x%x\n", bin, offset, biti); } @@ -1833,10 +1833,10 @@ struct Pool //debug(PRINTF) printf("Pool::Pool(%u)\n", npages); poolsize = npages * PAGESIZE; assert(poolsize >= POOLSIZE); - baseAddr = (byte *)os_mem_map(poolsize); + baseAddr = cast(byte *)os_mem_map(poolsize); // Some of the code depends on page alignment of memory pools - assert(((uint)baseAddr & (PAGESIZE - 1)) == 0); + assert((cast(uint)baseAddr & (PAGESIZE - 1)) == 0); if (!baseAddr) { @@ -1853,7 +1853,7 @@ struct Pool scan.alloc(poolsize / 16); freebits.alloc(poolsize / 16); - pagetable = (ubyte*)std.c.stdlib.malloc(npages); + pagetable = cast(ubyte*)std.c.stdlib.malloc(npages); memset(pagetable, B_UNCOMMITTED, npages); this.npages = npages; @@ -1910,7 +1910,7 @@ struct Pool } for (uint i = 0; i < npages; i++) - { Bins bin = (Bins)pagetable[i]; + { Bins bin = cast(Bins)pagetable[i]; assert(bin < B_MAX); } @@ -1995,9 +1995,9 @@ version (SENTINEL) const ubyte SENTINEL_POST = 0xF5; // 8 bits const uint SENTINEL_EXTRA = 2 * uint.size + 1; - uint* sentinel_size(void *p) { return &((uint *)p)[-2]; } - uint* sentinel_pre(void *p) { return &((uint *)p)[-1]; } - ubyte* sentinel_post(void *p) { return &((ubyte *)p)[sentinel_size(p)]; } + uint* sentinel_size(void *p) { return &(cast(uint *)p)[-2]; } + uint* sentinel_pre(void *p) { return &(cast(uint *)p)[-1]; } + ubyte* sentinel_post(void *p) { return &(cast(ubyte *)p)[sentinel_size(p)]; } void sentinel_init(void *p, uint size) { diff --git a/internal/gc/testgc.d b/internal/gc/testgc.d index bdc85d8bd..32b262b09 100644 --- a/internal/gc/testgc.d +++ b/internal/gc/testgc.d @@ -32,24 +32,24 @@ uint PERMUTE(uint key) void fill(void *p, uint key, uint size) { uint i; - byte *q = (byte *)p; + byte *q = cast(byte *)p; for (i = 0; i < size; i++) { key = PERMUTE(key); - q[i] = (byte)key; + q[i] = cast(byte)key; } } void verify(void *p, uint key, uint size) { uint i; - byte *q = (byte *)p; + byte *q = cast(byte *)p; for (i = 0; i < size; i++) { key = PERMUTE(key); - assert(q[i] == (byte)key); + assert(q[i] == cast(byte)key); } } @@ -77,7 +77,7 @@ printf("smoke.2\n"); gc = newGC(); gc.initialize(); - char *p = (char *)gc.malloc(10); + char *p = cast(char *)gc.malloc(10); assert(p); strcpy(p, "Hello!"); // char *p2 = gc.strdup(p); @@ -116,10 +116,10 @@ void smoke2() for (i = 0; i < SMOKE2_SIZE; i++) { - p = (int *)gc.calloc(i + 1, 500); + p = cast(int *)gc.calloc(i + 1, 500); p[0] = i * 3; foo[i] = p; - gc.setFinalizer((void *)p, &finalizer); + gc.setFinalizer(cast(void *)p, &finalizer); } for (i = 0; i < SMOKE2_SIZE; i += 2) @@ -160,11 +160,11 @@ void smoke3() for (i = 0; i < 1000; i++) { uint size = std.random.rand() % 2048; - p = (int *)gc.malloc(size); + p = cast(int *)gc.malloc(size); memset(p, i, size); size = std.random.rand() % 2048; - p = (int *)gc.realloc(p, size); + p = cast(int *)gc.realloc(p, size); memset(p, i + 1, size); } @@ -192,12 +192,12 @@ void smoke4() for (i = 0; i < 80000; i++) { uint size = i; - p = (int *)gc.malloc(size); + p = cast(int *)gc.malloc(size); memset(p, i, size); size = std.random.rand() % 2048; gc.check(p); - p = (int *)gc.realloc(p, size); + p = cast(int *)gc.realloc(p, size); memset(p, i + 1, size); } @@ -233,7 +233,7 @@ void smoke5(GC *gc) //printf("index = %d, size = %d\n", index, size); p = array[index] - offset[index]; - p = (byte *)gc.realloc(p, size); + p = cast(byte *)gc.realloc(p, size); if (array[index]) { uint s; @@ -301,7 +301,7 @@ printf("gc = %p\n", gc); GC *newGC() { - return (GC *)std.c.stdlib.calloc(1, GC.size); + return cast(GC *)std.c.stdlib.calloc(1, GC.size); } void deleteGC(GC *gc) diff --git a/internal/gc/win32.d b/internal/gc/win32.d index 58f98b680..ef6239399 100644 --- a/internal/gc/win32.d +++ b/internal/gc/win32.d @@ -65,7 +65,7 @@ int os_mem_unmap(void *base, uint nbytes) pthread_t pthread_self() { //printf("pthread_self() = %x\n", GetCurrentThreadId()); - return (pthread_t) GetCurrentThreadId(); + return cast(pthread_t) GetCurrentThreadId(); } /********************************************** @@ -95,8 +95,8 @@ extern (C) void os_query_staticdataseg(void **base, uint *nbytes) { - *base = (void *)&_xi_a; - *nbytes = (uint)((char *)&_end - (char *)&_xi_a); + *base = cast(void *)&_xi_a; + *nbytes = cast(uint)(cast(char *)&_end - cast(char *)&_xi_a); } /++++ diff --git a/internal/memset.d b/internal/memset.d index 8c0def106..b41cae3b4 100644 --- a/internal/memset.d +++ b/internal/memset.d @@ -70,7 +70,7 @@ void *_memsetn(void *p, void *value, int count, int sizelem) for (i = 0; i < count; i++) { memcpy(p, value, sizelem); - p = (void *)((char *)p + sizelem); + p = cast(void *)(cast(char *)p + sizelem); } return pstart; } diff --git a/internal/monitor.c b/internal/monitor.c index 2a394624e..98ed04e6c 100644 --- a/internal/monitor.c +++ b/internal/monitor.c @@ -1,6 +1,4 @@ - - -// Copyright (c) 2000-2003 by Digital Mars +// Copyright (c) 2000-2004 by Digital Mars // All Rights Reserved // written by Walter Bright // www.digitalmars.com @@ -91,17 +89,23 @@ void _d_monitorrelease(Object *h) #if linux +// Includes attribute fixes from David Friedman's GDC port + #include #include "mars.h" static pthread_mutex_t _monitor_critsec; +static pthread_mutexattr_t _monitors_attr; static volatile int inited; void _STI_monitor_staticctor() { if (!inited) - { pthread_mutex_init(&_monitor_critsec, 0); + { + pthread_mutexattr_init(&_monitors_attr); + pthread_mutexattr_settype(&_monitors_attr, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_init(&_monitor_critsec, 0); inited = 1; } } @@ -111,6 +115,7 @@ void _STD_monitor_staticdtor() if (inited) { inited = 0; pthread_mutex_destroy(&_monitor_critsec); + pthread_mutexattr_destroy(&_monitors_attr); } } @@ -126,7 +131,7 @@ void _d_monitorenter(Object *h) if (!h->monitor) // if, in the meantime, another thread didn't set it { h->monitor = (unsigned)cs; - pthread_mutex_init(cs, 0); + pthread_mutex_init(cs, & _monitors_attr); cs = NULL; } pthread_mutex_unlock(&_monitor_critsec); diff --git a/internal/qsort.d b/internal/qsort.d index 4e38d1c78..006a9ff0f 100644 --- a/internal/qsort.d +++ b/internal/qsort.d @@ -52,7 +52,7 @@ extern (C) Array _adSort(Array a, TypeInfo ti) uint thresh; // size of _maxspan elements in bytes uint width = ti.tsize(); - base = (byte *)a.ptr; + base = cast(byte *)a.ptr; thresh = _maxspan * width; // init threshold sp = stack; // init stack pointer limit = base + a.length * width; // pointer past end of array @@ -61,8 +61,8 @@ extern (C) Array _adSort(Array a, TypeInfo ti) while (limit - base > thresh) // if more than _maxspan elements { //swap middle, base - ti.swap(((uint)(limit - base) >> 1) - - ((((uint)(limit - base) >> 1)) % width) + base, base); + ti.swap((cast(uint)(limit - base) >> 1) - + (((cast(uint)(limit - base) >> 1)) % width) + base, base); i = base + width; // i scans from left to right j = limit - width; // j scans from right to left @@ -100,7 +100,7 @@ extern (C) Array _adSort(Array a, TypeInfo ti) limit = j; // sort the left subarray } sp += 2; // increment stack pointer - assert(sp < (byte**)stack + stack.length); + assert(sp < cast(byte**)stack + stack.length); } // Insertion sort on remaining subarray diff --git a/internal/switch.d b/internal/switch.d index 7ec0becc4..9827b88ab 100644 --- a/internal/switch.d +++ b/internal/switch.d @@ -113,7 +113,7 @@ int _d_switch_string(char[][] table, char[] ca) c = ca.length - pca.length; if (c == 0) { - c = (byte)c1 - (byte)pca[0]; + c = cast(byte)c1 - cast(byte)pca[0]; if (c == 0) { c = memcmp(ca, pca, ca.length); @@ -140,7 +140,7 @@ int _d_switch_string(char[][] table, char[] ca) unittest { - switch ((char []) "c") + switch (cast(char []) "c") { case "coo": default: @@ -264,7 +264,7 @@ int _d_switch_ustring(wchar[][] table, wchar[] ca) unittest { - switch ((wchar []) "c") + switch (cast(wchar []) "c") { case "coo": default: diff --git a/linux.mak b/linux.mak index 2adafa67d..5d5941d82 100644 --- a/linux.mak +++ b/linux.mak @@ -55,7 +55,7 @@ OBJS= asserterror.o deh2.o switch.o complex.o gcstats.o \ qsort.o thread.o obj.o utf.o uri.o \ crc32.o conv.o arraycast.o errno.o alloca.o cmath2.o \ process.o syserror.o \ - socket.o socketstream.o \ + socket.o socketstream.o stdarg.o \ ti_wchar.o ti_uint.o ti_short.o ti_ushort.o \ ti_byte.o ti_ubyte.o ti_long.o ti_ulong.o ti_ptr.o \ ti_float.o ti_double.o ti_real.o ti_delegate.o \ @@ -96,7 +96,8 @@ SRC_STD= std/zlib.d std/zip.d std/stdint.d std/conv.d std/utf.d std/uri.d \ std/regexp.d std/random.d std/stream.d std/process.d std/recls.d \ std/socket.d std/socketstream.d -SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d std/c/math.d +SRC_STD_C= std/c/process.d std/c/stdlib.d std/c/time.d std/c/stdio.d \ + std/c/math.d std/c/stdarg.d SRC_TI= \ std/typeinfo/ti_wchar.d std/typeinfo/ti_uint.d \ @@ -439,6 +440,11 @@ Dzlib.o : std/zlib.d zip.o : std/zip.d $(DMD) -c $(DFLAGS) std/zip.d +### std/c + +stdarg.o : std/c/stdarg.d + $(DMD) -c $(DFLAGS) std/c/stdarg.d + ### std/c/linux linux.o : std/c/linux/linux.d diff --git a/object.d b/object.d index 324660d6a..26ecefada 100644 --- a/object.d +++ b/object.d @@ -29,12 +29,12 @@ class Object uint toHash() { - return (uint)(void *)this; + return cast(uint)cast(void *)this; } int opCmp(Object o) { - return (int)(void *)this - (int)(void *)o; + return cast(int)cast(void *)this - cast(int)cast(void *)o; } int opEquals(Object o) @@ -66,7 +66,7 @@ class ClassInfo : Object class TypeInfo { - uint getHash(void *p) { return (uint)p; } + uint getHash(void *p) { return cast(uint)p; } int equals(void *p1, void *p2) { return p1 == p2; } int compare(void *p1, void *p2) { return 0; } int tsize() { return 0; } @@ -77,9 +77,9 @@ class TypeInfo for (i = 0; i < n; i++) { byte t; - t = ((byte *)p1)[i]; - ((byte *)p1)[i] = ((byte *)p2)[i]; - ((byte *)p2)[i] = t; + t = (cast(byte *)p1)[i]; + (cast(byte *)p1)[i] = (cast(byte *)p2)[i]; + (cast(byte *)p2)[i] = t; } } } diff --git a/std/asserterror.d b/std/asserterror.d index d34018475..b6419217c 100644 --- a/std/asserterror.d +++ b/std/asserterror.d @@ -23,7 +23,7 @@ class AssertError : Object void print() { - printf("AssertError Failure %s(%u)\n", (char *)filename, linnum); + printf("AssertError Failure %s(%u)\n", cast(char *)filename, linnum); } } diff --git a/std/c/stdarg.d b/std/c/stdarg.d new file mode 100644 index 000000000..cce88dcc9 --- /dev/null +++ b/std/c/stdarg.d @@ -0,0 +1,31 @@ + +/* + * Placed in public domain. + * Written by Hauke Duden and Walter Bright + */ + +module std.c.stdarg; + +typedef void* va_list; + +template va_start(T) +{ + void va_start(out va_list ap, inout T parmn) + { + ap = cast(va_list)(cast(void*)&parmn + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1))); + } +} + +template va_arg(T) +{ + T va_arg(inout va_list ap) + { + T arg = *cast(T*)ap; + ap = cast(va_list)(cast(void*)ap + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1))); + return arg; + } +} + +void va_end(va_list ap) +{ +} diff --git a/std/c/windows/com.d b/std/c/windows/com.d index 0f310f2ad..1fd199637 100644 --- a/std/c/windows/com.d +++ b/std/c/windows/com.d @@ -208,7 +208,7 @@ extern (Windows): { if (*riid == IID_IUnknown) { - *ppv = (IUnknown)this; + *ppv = cast(IUnknown)this; AddRef(); return S_OK; } @@ -237,7 +237,7 @@ extern (Windows): return 0; } - return (ULONG)lRef; + return cast(ULONG)lRef; } LONG count = 0; // object reference count diff --git a/std/c/windows/windows.d b/std/c/windows/windows.d index 4b054f1e7..1b72ade66 100644 --- a/std/c/windows/windows.d +++ b/std/c/windows/windows.d @@ -118,8 +118,8 @@ alias FARPROC PROPENUMPROCEXW; alias FARPROC DRAWSTATEPROC; -WORD HIWORD(int l) { return (WORD)((l >> 16) & 0xFFFF); } -WORD LOWORD(int l) { return (WORD)l; } +WORD HIWORD(int l) { return cast(WORD)((l >> 16) & 0xFFFF); } +WORD LOWORD(int l) { return cast(WORD)l; } int FAILED(int status) { return status < 0; } int SUCCEEDED(int Status) { return Status >= 0; } @@ -222,8 +222,8 @@ enum FILE_VOLUME_IS_COMPRESSED = 0x00008000, } -const DWORD MAILSLOT_NO_MESSAGE = (DWORD)-1; -const DWORD MAILSLOT_WAIT_FOREVER = (DWORD)-1; +const DWORD MAILSLOT_NO_MESSAGE = cast(DWORD)-1; +const DWORD MAILSLOT_WAIT_FOREVER = cast(DWORD)-1; enum : uint { @@ -246,8 +246,8 @@ enum TRUNCATE_EXISTING = 5, } -const HANDLE INVALID_HANDLE_VALUE = (HANDLE)-1; -const DWORD INVALID_FILE_SIZE = (DWORD)0xFFFFFFFF; +const HANDLE INVALID_HANDLE_VALUE = cast(HANDLE)-1; +const DWORD INVALID_FILE_SIZE = cast(DWORD)0xFFFFFFFF; struct OVERLAPPED { DWORD Internal; @@ -1470,7 +1470,7 @@ enum FS_WANSUNG = 0x00080000L, FS_CHINESETRAD = 0x00100000L, FS_JOHAB = 0x00200000L, - FS_SYMBOL = (int)0x80000000L, + FS_SYMBOL = cast(int)0x80000000L, /* Font Families */ @@ -1714,7 +1714,7 @@ alias WNDCLASSA WNDCLASS; enum { WS_OVERLAPPED = 0x00000000, - WS_POPUP = (int)0x80000000, + WS_POPUP = cast(int)0x80000000, WS_CHILD = 0x40000000, WS_MINIMIZE = 0x20000000, WS_VISIBLE = 0x10000000, @@ -1834,11 +1834,11 @@ enum COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT, } -const int CW_USEDEFAULT = (int)0x80000000; +const int CW_USEDEFAULT = cast(int)0x80000000; /* * Special value for CreateWindow, et al. */ -const HWND HWND_DESKTOP = ((HWND)0); +const HWND HWND_DESKTOP = (cast(HWND)0); export ATOM RegisterClassA(WNDCLASSA *lpWndClass); @@ -2273,7 +2273,7 @@ export HMENU GetSubMenu(HMENU hMenu, int nPos); export HBITMAP LoadBitmapA(HINSTANCE hInstance, LPCSTR lpBitmapName); export HBITMAP LoadBitmapW(HINSTANCE hInstance, LPCWSTR lpBitmapName); -LPSTR MAKEINTRESOURCEA(int i) { return (LPSTR)((DWORD)((WORD)(i))); } +LPSTR MAKEINTRESOURCEA(int i) { return cast(LPSTR)(cast(DWORD)(cast(WORD)(i))); } export HFONT CreateFontIndirectA(LOGFONTA *); @@ -2333,21 +2333,21 @@ export int DialogBoxIndirectParamA(HINSTANCE hInstance, enum : DWORD { - SRCCOPY = (DWORD)0x00CC0020, /* dest = source */ - SRCPAINT = (DWORD)0x00EE0086, /* dest = source OR dest */ - SRCAND = (DWORD)0x008800C6, /* dest = source AND dest */ - SRCINVERT = (DWORD)0x00660046, /* dest = source XOR dest */ - SRCERASE = (DWORD)0x00440328, /* dest = source AND (NOT dest) */ - NOTSRCCOPY = (DWORD)0x00330008, /* dest = (NOT source) */ - NOTSRCERASE = (DWORD)0x001100A6, /* dest = (NOT src) AND (NOT dest) */ - MERGECOPY = (DWORD)0x00C000CA, /* dest = (source AND pattern) */ - MERGEPAINT = (DWORD)0x00BB0226, /* dest = (NOT source) OR dest */ - PATCOPY = (DWORD)0x00F00021, /* dest = pattern */ - PATPAINT = (DWORD)0x00FB0A09, /* dest = DPSnoo */ - PATINVERT = (DWORD)0x005A0049, /* dest = pattern XOR dest */ - DSTINVERT = (DWORD)0x00550009, /* dest = (NOT dest) */ - BLACKNESS = (DWORD)0x00000042, /* dest = BLACK */ - WHITENESS = (DWORD)0x00FF0062, /* dest = WHITE */ + SRCCOPY = cast(DWORD)0x00CC0020, /* dest = source */ + SRCPAINT = cast(DWORD)0x00EE0086, /* dest = source OR dest */ + SRCAND = cast(DWORD)0x008800C6, /* dest = source AND dest */ + SRCINVERT = cast(DWORD)0x00660046, /* dest = source XOR dest */ + SRCERASE = cast(DWORD)0x00440328, /* dest = source AND (NOT dest) */ + NOTSRCCOPY = cast(DWORD)0x00330008, /* dest = (NOT source) */ + NOTSRCERASE = cast(DWORD)0x001100A6, /* dest = (NOT src) AND (NOT dest) */ + MERGECOPY = cast(DWORD)0x00C000CA, /* dest = (source AND pattern) */ + MERGEPAINT = cast(DWORD)0x00BB0226, /* dest = (NOT source) OR dest */ + PATCOPY = cast(DWORD)0x00F00021, /* dest = pattern */ + PATPAINT = cast(DWORD)0x00FB0A09, /* dest = DPSnoo */ + PATINVERT = cast(DWORD)0x005A0049, /* dest = pattern XOR dest */ + DSTINVERT = cast(DWORD)0x00550009, /* dest = (NOT dest) */ + BLACKNESS = cast(DWORD)0x00000042, /* dest = BLACK */ + WHITENESS = cast(DWORD)0x00FF0062, /* dest = WHITE */ } enum diff --git a/std/date.d b/std/date.d index a49d52b76..87c01fbdd 100644 --- a/std/date.d +++ b/std/date.d @@ -171,7 +171,7 @@ int Day(d_time t) { if (t < 0) t -= msPerDay; // use this if t is not floating point - return (int)floor(t / msPerDay); + return cast(int)floor(t / msPerDay); } int LeapYear(int y) @@ -187,7 +187,7 @@ int DaysInYear(int y) int DayFromYear(int y) { - return (int) (365 * (y - 1970) + + return cast(int) (365 * (y - 1970) + floor((y - 1969.0) / 4) - floor((y - 1901.0) / 100) + floor((y - 1601.0) / 400)); @@ -195,14 +195,14 @@ int DayFromYear(int y) d_time TimeFromYear(int y) { - return (d_time)msPerDay * DayFromYear(y); + return cast(d_time)msPerDay * DayFromYear(y); } int YearFromTime(d_time t) { int y; // Hazard a guess - y = 1970 + (int) (t / (365.2425 * msPerDay)); + y = 1970 + cast(int) (t / (365.2425 * msPerDay)); if (TimeFromYear(y) <= t) { @@ -318,7 +318,7 @@ int DateFromTime(d_time t) int WeekDay(d_time t) { int w; - w = ((int)Day(t) + 4) % 7; + w = (cast(int)Day(t) + 4) % 7; if (w < 0) w += 7; return w; @@ -379,11 +379,11 @@ d_time MakeDay(d_time year, d_time month, d_time date) month = toInteger(month); date = toInteger(date); - y = (int)(year + floor(month / 12)); - m = (int)dmod(month, 12); + y = cast(int)(year + floor(month / 12)); + m = cast(int)dmod(month, 12); leap = LeapYear(y); - t = TimeFromYear(y) + (d_time)mdays[m] * msPerDay; + t = TimeFromYear(y) + cast(d_time)mdays[m] * msPerDay; if (leap && month >= 2) t += msPerDay; @@ -445,7 +445,7 @@ char[] toString(d_time time) offset = -(LocalTZA + dst); } - mn = (int)(offset / msPerMinute); + mn = cast(int)(offset / msPerMinute); hr = mn / 60; mn %= 60; @@ -455,9 +455,9 @@ char[] toString(d_time time) &daystr[WeekDay(t) * 3], &monstr[MonthFromTime(t) * 3], DateFromTime(t), - (int)HourFromTime(t), (int)MinFromTime(t), (int)SecFromTime(t), + cast(int)HourFromTime(t), cast(int)MinFromTime(t), cast(int)SecFromTime(t), sign, hr, mn, - (long)YearFromTime(t)); + cast(long)YearFromTime(t)); // Ensure no buggy buffer overflows //printf("len = %d, buffer.length = %d\n", len, buffer.length); @@ -490,7 +490,7 @@ char[] toDateString(d_time time) &daystr[WeekDay(t) * 3], &monstr[MonthFromTime(t) * 3], DateFromTime(t), - (long)YearFromTime(t)); + cast(long)YearFromTime(t)); // Ensure no buggy buffer overflows assert(len < buffer.length); @@ -526,14 +526,14 @@ char[] toTimeString(d_time time) offset = -(LocalTZA + dst); } - mn = (int)(offset / msPerMinute); + mn = cast(int)(offset / msPerMinute); hr = mn / 60; mn %= 60; //printf("hr = %d, offset = %g, LocalTZA = %g, dst = %g, + = %g\n", hr, offset, LocalTZA, dst, LocalTZA + dst); len = sprintf(buffer, "%02d:%02d:%02d GMT%c%02d%02d", - (int)HourFromTime(t), (int)MinFromTime(t), (int)SecFromTime(t), + cast(int)HourFromTime(t), cast(int)MinFromTime(t), cast(int)SecFromTime(t), sign, hr, mn); // Ensure no buggy buffer overflows @@ -562,7 +562,7 @@ d_time parse(char[] s) if (dp.tzcorrection == Date.tzcorrection.init) time -= LocalTZA; else - time += (d_time)dp.tzcorrection * msPerHour; + time += cast(d_time)dp.tzcorrection * msPerHour; day = MakeDay(dp.year, dp.month - 1, dp.day); n = MakeDate(day,time); n = TimeClip(n); @@ -651,7 +651,7 @@ version (Win32) //printf("bias = %d\n", tzi.Bias); //printf("standardbias = %d\n", tzi.StandardBias); //printf("daylightbias = %d\n", tzi.DaylightBias); - t = -(tzi.Bias + tzi.StandardBias) * (d_time)(60 * TicksPerSecond); + t = -(tzi.Bias + tzi.StandardBias) * cast(d_time)(60 * TicksPerSecond); break; default: @@ -744,7 +744,7 @@ version (linux) tm *tmp; int t; - t = (int) (dt / TicksPerSecond); // BUG: need range check + t = cast(int) (dt / TicksPerSecond); // BUG: need range check tmp = localtime(&t); if (tmp.tm_isdst > 0) // BUG: Assume daylight savings time is plus one hour. diff --git a/std/dateparse.d b/std/dateparse.d index 33e52b06b..da00dafd3 100644 --- a/std/dateparse.d +++ b/std/dateparse.d @@ -30,7 +30,7 @@ struct DateParse *this = DateParse.init; //version (Win32) - buffer = ((char *)alloca(s.length))[0 .. s.length]; + buffer = (cast(char *)alloca(s.length))[0 .. s.length]; //else //buffer = new char[s.length]; @@ -227,7 +227,7 @@ private: while (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') { if (c < 'a') // if upper case - c += (uint)'a' - (uint)'A'; // to lower case + c += cast(uint)'a' - cast(uint)'A'; // to lower case buffer[bi] = c; bi++; do diff --git a/std/file.d b/std/file.d index 0d88a9687..33f5de55f 100644 --- a/std/file.d +++ b/std/file.d @@ -72,13 +72,13 @@ void[] read(char[] name) { wchar* namez = std.utf.toUTF16z(name); h = CreateFileW(namez,GENERIC_READ,FILE_SHARE_READ,null,OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,(HANDLE)null); + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); } else { char* namez = toMBSz(name); h = CreateFileA(namez,GENERIC_READ,FILE_SHARE_READ,null,OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,(HANDLE)null); + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); } if (h == INVALID_HANDLE_VALUE) @@ -124,13 +124,13 @@ void write(char[] name, void[] buffer) { wchar* namez = std.utf.toUTF16z(name); h = CreateFileW(namez,GENERIC_WRITE,0,null,CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,(HANDLE)null); + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); } else { char* namez = toMBSz(name); h = CreateFileA(namez,GENERIC_WRITE,0,null,CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,(HANDLE)null); + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); } if (h == INVALID_HANDLE_VALUE) goto err; @@ -165,13 +165,13 @@ void append(char[] name, void[] buffer) { wchar* namez = std.utf.toUTF16z(name); h = CreateFileW(namez,GENERIC_WRITE,0,null,OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,(HANDLE)null); + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); } else { char* namez = toMBSz(name); h = CreateFileA(namez,GENERIC_WRITE,0,null,OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,(HANDLE)null); + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,cast(HANDLE)null); } if (h == INVALID_HANDLE_VALUE) goto err; @@ -256,12 +256,12 @@ ulong getSize(char[] name) resultl = filefindbuf.nFileSizeLow; } - if (findhndl == (HANDLE)-1) + if (findhndl == cast(HANDLE)-1) { throw new FileException(name, GetLastError()); } FindClose(findhndl); - return ((ulong)resulth << 32) + resultl; + return (cast(ulong)resulth << 32) + resultl; } @@ -526,7 +526,7 @@ void[] read(char[] name) size = statbuf.st_size; buf = new byte[size]; - numread = std.c.linux.linux.read(fd, (char*)buf, size); + numread = std.c.linux.linux.read(fd, cast(char*)buf, size); if (numread != size) { //printf("\tread error, errno = %d\n",getErrno()); diff --git a/std/loader.d b/std/loader.d index 9f9288056..a00d6ba43 100644 --- a/std/loader.d +++ b/std/loader.d @@ -212,7 +212,7 @@ version(Windows) } body { - HXModule hmod = (HXModule)LoadLibraryA(toStringz(moduleName)); + HXModule hmod = cast(HXModule)LoadLibraryA(toStringz(moduleName)); if(null === hmod) { @@ -239,7 +239,7 @@ version(Windows) } body { - if(!FreeLibrary((HModule_)hModule)) + if(!FreeLibrary(cast(HModule_)hModule)) { record_error_(); } @@ -253,7 +253,7 @@ version(Windows) } body { - void *symbol = GetProcAddress((HModule_)hModule, toStringz(symbolName)); + void *symbol = GetProcAddress(cast(HModule_)hModule, toStringz(symbolName)); if(null === symbol) { @@ -273,7 +273,7 @@ version(Windows) char szFileName[260]; // Need to use a constant here // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getmodulefilename.asp - uint cch = GetModuleFileNameA((HModule_)hModule, szFileName, szFileName.length); + uint cch = GetModuleFileNameA(cast(HModule_)hModule, szFileName, szFileName.length); if (cch == 0) { @@ -338,7 +338,7 @@ else version(Linux) if(null !== mi) { - return (++mi.m_cRefs, (HXModule)mi); + return (++mi.m_cRefs, cast(HXModule)mi); } else { @@ -356,7 +356,7 @@ else version(Linux) s_modules[moduleName] = mi; - return (HXModule)mi; + return cast(HXModule)mi; } } } @@ -366,7 +366,7 @@ else version(Linux) { assert(null !== hModule); - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; assert(0 < mi.m_cRefs); assert(null !== mi.m_hmod); @@ -376,7 +376,7 @@ else version(Linux) } body { - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; if(null !== mi) { @@ -393,7 +393,7 @@ else version(Linux) { assert(null !== hModule); - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; assert(0 < mi.m_cRefs); assert(null !== mi.m_hmod); @@ -403,7 +403,7 @@ else version(Linux) } body { - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; if(0 == --mi.m_cRefs) { @@ -425,7 +425,7 @@ else version(Linux) { assert(null !== hModule); - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; assert(0 < mi.m_cRefs); assert(null !== mi.m_hmod); @@ -435,7 +435,7 @@ else version(Linux) } body { - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; void *symbol = dlsym(mi.m_hmod, toStringz(symbolName)); if(null == symbol) @@ -456,7 +456,7 @@ else version(Linux) { assert(null !== hModule); - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; assert(0 < mi.m_cRefs); assert(null !== mi.m_hmod); @@ -466,7 +466,7 @@ else version(Linux) } body { - ExeModuleInfo mi = (ExeModuleInfo)hModule; + ExeModuleInfo mi = cast(ExeModuleInfo)hModule; return mi.m_name; } @@ -601,7 +601,7 @@ public: { version (Windows) { - void *symbol = GetProcAddress((HModule_)m_hModule, toStringz(symbolName)); + void *symbol = GetProcAddress(cast(HModule_)m_hModule, toStringz(symbolName)); if(null === symbol) { throw new ExeModuleException(GetLastError()); diff --git a/std/math.d b/std/math.d index 1536bd75d..8706f1cb9 100644 --- a/std/math.d +++ b/std/math.d @@ -90,8 +90,8 @@ const real SQRT1_2 = 0.70710678118654752440; int isnan(real e) { - ushort* pe = (ushort *)&e; - ulong* ps = (ulong *)&e; + ushort* pe = cast(ushort *)&e; + ulong* ps = cast(ulong *)&e; return (pe[4] & 0x7FFF) == 0x7FFF && *ps & 0x7FFFFFFFFFFFFFFF; @@ -113,7 +113,7 @@ unittest int isfinite(real e) { - ushort* pe = (ushort *)&e; + ushort* pe = cast(ushort *)&e; return (pe[4] & 0x7FFF) != 0x7FFF; } @@ -134,7 +134,7 @@ unittest int isnormal(float f) { - uint *p = (uint *)&f; + uint *p = cast(uint *)&f; uint e; e = *p & 0x7F800000; @@ -144,7 +144,7 @@ int isnormal(float f) int isnormal(double d) { - uint *p = (uint *)&d; + uint *p = cast(uint *)&d; uint e; e = p[1] & 0x7FF00000; @@ -153,8 +153,8 @@ int isnormal(double d) int isnormal(real e) { - ushort* pe = (ushort *)&e; - long* ps = (long *)&e; + ushort* pe = cast(ushort *)&e; + long* ps = cast(long *)&e; return (pe[4] & 0x7FFF) != 0x7FFF && *ps < 0; } @@ -179,7 +179,7 @@ unittest int issubnormal(float f) { - uint *p = (uint *)&f; + uint *p = cast(uint *)&f; //printf("*p = x%x\n", *p); return (*p & 0x7F800000) == 0 && *p & 0x007FFFFF; @@ -195,7 +195,7 @@ unittest int issubnormal(double d) { - uint *p = (uint *)&d; + uint *p = cast(uint *)&d; return (p[1] & 0x7FF00000) == 0 && (p[0] || p[1] & 0x000FFFFF); } @@ -210,8 +210,8 @@ unittest int issubnormal(real e) { - ushort* pe = (ushort *)&e; - long* ps = (long *)&e; + ushort* pe = cast(ushort *)&e; + long* ps = cast(long *)&e; return (pe[4] & 0x7FFF) == 0 && *ps > 0; } @@ -230,8 +230,8 @@ unittest int isinf(real e) { - ushort* pe = (ushort *)&e; - ulong* ps = (ulong *)&e; + ushort* pe = cast(ushort *)&e; + ulong* ps = cast(ulong *)&e; return (pe[4] & 0x7FFF) == 0x7FFF && *ps == 0x8000000000000000; @@ -253,7 +253,7 @@ unittest int signbit(real e) { - ubyte* pe = (ubyte *)&e; + ubyte* pe = cast(ubyte *)&e; //printf("e = %Lg\n", e); return (pe[9] & 0x80) != 0; @@ -276,8 +276,8 @@ unittest real copysign(real to, real from) { - ubyte* pto = (ubyte *)&to; - ubyte* pfrom = (ubyte *)&from; + ubyte* pto = cast(ubyte *)&to; + ubyte* pfrom = cast(ubyte *)&from; pto[9] &= 0x7F; pto[9] |= pfrom[9] & 0x80; @@ -518,8 +518,8 @@ unittest real frexp(real value, out int eptr) { - ushort* vu = (ushort*)&value; - long* vl = (long*)&value; + ushort* vu = cast(ushort*)&value; + long* vl = cast(long*)&value; uint exp; // If exponent is non-zero @@ -597,7 +597,7 @@ unittest { real x = vals[i][0]; real e = vals[i][1]; - int exp = (int)vals[i][2]; + int exp = cast(int)vals[i][2]; int eptr; real v = frexp(x, eptr); diff --git a/std/md5.d b/std/md5.d index f8b5409b4..1f823bd8c 100644 --- a/std/md5.d +++ b/std/md5.d @@ -166,7 +166,7 @@ struct MD5_CTX Encode (bits, cnt, 8); /* Pad out to 56 mod 64. */ - index = ((uint)count >> 3) & (64 - 1); + index = (cast(uint)count >> 3) & (64 - 1); padLen = (index < 56) ? (56 - index) : (120 - index); update (PADDING[0 .. padLen]); @@ -327,8 +327,8 @@ struct MD5_CTX } else { - output[i] = ((uint)input[j]) | (((uint)input[j+1]) << 8) | - (((uint)input[j+2]) << 16) | (((uint)input[j+3]) << 24); + output[i] = (cast(uint)input[j]) | ((cast(uint)input[j+1]) << 8) | + ((cast(uint)input[j+2]) << 16) | ((cast(uint)input[j+3]) << 24); } } } diff --git a/std/outbuffer.d b/std/outbuffer.d index 368959be3..18c6fbc23 100644 --- a/std/outbuffer.d +++ b/std/outbuffer.d @@ -81,7 +81,7 @@ class OutBuffer void write(ushort w) { reserve(ushort.size); - *(ushort *)&data[offset] = w; + *cast(ushort *)&data[offset] = w; offset += ushort.size; } @@ -90,14 +90,14 @@ class OutBuffer void write(wchar c) { reserve(wchar.size); - *(wchar *)&data[offset] = c; + *cast(wchar *)&data[offset] = c; offset += wchar.size; } void write(uint w) { reserve(uint.size); - *(uint *)&data[offset] = w; + *cast(uint *)&data[offset] = w; offset += uint.size; } @@ -106,7 +106,7 @@ class OutBuffer void write(ulong l) { reserve(ulong.size); - *(ulong *)&data[offset] = l; + *cast(ulong *)&data[offset] = l; offset += ulong.size; } @@ -115,21 +115,21 @@ class OutBuffer void write(float f) { reserve(float.size); - *(float *)&data[offset] = f; + *cast(float *)&data[offset] = f; offset += float.size; } void write(double f) { reserve(double.size); - *(double *)&data[offset] = f; + *cast(double *)&data[offset] = f; offset += double.size; } void write(real f) { reserve(real.size); - *(real *)&data[offset] = f; + *cast(real *)&data[offset] = f; offset += real.size; } @@ -196,7 +196,7 @@ class OutBuffer char[] toString() { //printf("OutBuffer.toString()\n"); - return (char[])data[0 .. offset]; + return cast(char[])data[0 .. offset]; } /***************************************** @@ -222,7 +222,7 @@ class OutBuffer if (count != -1) break; psize *= 2; - p = (char *) alloca(psize); // buffer too small, try again with larger size + p = cast(char *) alloca(psize); // buffer too small, try again with larger size } version(linux) { @@ -238,7 +238,7 @@ class OutBuffer c.stdlib.free(p); p = (char *) c.stdlib.malloc(psize); // buffer too small, try again with larger size +/ - p = (char *) alloca(psize); // buffer too small, try again with larger size + p = cast(char *) alloca(psize); // buffer too small, try again with larger size } } write(p[0 .. count]); diff --git a/std/outofmemory.d b/std/outofmemory.d index 4e2d1d0c4..33cbb3a85 100644 --- a/std/outofmemory.d +++ b/std/outofmemory.d @@ -11,6 +11,6 @@ class OutOfMemory : Object extern (C) void _d_OutOfMemory() { - throw (OutOfMemory)(void *)OutOfMemory.classinfo.init; + throw cast(OutOfMemory)cast(void *)OutOfMemory.classinfo.init; } diff --git a/std/random.d b/std/random.d index 47b0e6c44..4f3e74bee 100644 --- a/std/random.d +++ b/std/random.d @@ -89,10 +89,10 @@ static this() } else { - s = ((long)tv.tv_sec << 32) + tv.tv_usec; + s = (cast(long)tv.tv_sec << 32) + tv.tv_usec; } } - rand_seed((uint) s, (uint)(s >> 32)); + rand_seed(cast(uint) s, cast(uint)(s >> 32)); } diff --git a/std/recls.d b/std/recls.d index 057e280ae..44141371d 100644 --- a/std/recls.d +++ b/std/recls.d @@ -122,23 +122,23 @@ public typedef recls_sint32_t recls_rc_t; /// Returns non-zero if the given return code represents a failure condition. public recls_bool_t RECLS_FAILED(recls_rc_t rc) { - return (recls_bool_t)(rc < 0); + return cast(recls_bool_t)(rc < 0); } /// Returns non-zero if the given return code represents a success condition. public recls_bool_t RECLS_SUCCEEDED(recls_rc_t rc) { - return (recls_bool_t)!RECLS_FAILED(rc); + return cast(recls_bool_t)!RECLS_FAILED(rc); } //////////////////////////////////////////////////////////////////////////////// // Values /** General success code */ -public const recls_rc_t RECLS_RC_OK = (recls_rc_t)(0); +public const recls_rc_t RECLS_RC_OK = cast(recls_rc_t)(0); /** Return code that indicates that there is no more data available from an otherwise valid search. */ -public const recls_rc_t RECLS_RC_NO_MORE_DATA = (recls_rc_t)(-1004); +public const recls_rc_t RECLS_RC_NO_MORE_DATA = cast(recls_rc_t)(-1004); /// The flags used to moderate the recls search behaviour public enum RECLS_FLAG diff --git a/std/regexp.d b/std/regexp.d index 3b87ab6f0..8f7419027 100644 --- a/std/regexp.d +++ b/std/regexp.d @@ -642,12 +642,12 @@ void printProgram(ubyte[] prog) break; case REwchar: - printf("\tREwchar '%c'\n", *(wchar *)&prog[pc + 1]); + printf("\tREwchar '%c'\n", *cast(wchar *)&prog[pc + 1]); pc += 1 + wchar.size; break; case REiwchar: - printf("\tREiwchar '%c'\n", *(wchar *)&prog[pc + 1]); + printf("\tREiwchar '%c'\n", *cast(wchar *)&prog[pc + 1]); pc += 1 + wchar.size; break; @@ -657,28 +657,28 @@ void printProgram(ubyte[] prog) break; case REstring: - len = *(uint *)&prog[pc + 1]; + len = *cast(uint *)&prog[pc + 1]; printf("\tREstring x%x, '%.*s'\n", len, (&prog[pc + 1 + uint.size])[0 .. len]); pc += 1 + uint.size + len * tchar.size; break; case REistring: - len = *(uint *)&prog[pc + 1]; + len = *cast(uint *)&prog[pc + 1]; printf("\tREistring x%x, '%.*s'\n", len, (&prog[pc + 1 + uint.size])[0 .. len]); pc += 1 + uint.size + len * tchar.size; break; case REtestbit: - pu = (ushort *)&prog[pc + 1]; + pu = cast(ushort *)&prog[pc + 1]; printf("\tREtestbit %d, %d\n", pu[0], pu[1]); len = pu[1]; pc += 1 + 2 * ushort.size + len; break; case REbit: - pu = (ushort *)&prog[pc + 1]; + pu = cast(ushort *)&prog[pc + 1]; len = pu[1]; printf("\tREbit cmax=%02x, len=%d:", pu[0], len); for (n = 0; n < len; n++) @@ -688,21 +688,21 @@ void printProgram(ubyte[] prog) break; case REnotbit: - pu = (ushort *)&prog[pc + 1]; + pu = cast(ushort *)&prog[pc + 1]; printf("\tREnotbit %d, %d\n", pu[0], pu[1]); len = pu[1]; pc += 1 + 2 * ushort.size + len; break; case RErange: - len = *(uint *)&prog[pc + 1]; + len = *cast(uint *)&prog[pc + 1]; printf("\tRErange %d\n", len); // BUG: REAignoreCase? pc += 1 + uint.size + len; break; case REnotrange: - len = *(uint *)&prog[pc + 1]; + len = *cast(uint *)&prog[pc + 1]; printf("\tREnotrange %d\n", len); // BUG: REAignoreCase? pc += 1 + uint.size + len; @@ -719,13 +719,13 @@ void printProgram(ubyte[] prog) break; case REor: - len = *(uint *)&prog[pc + 1]; + len = *cast(uint *)&prog[pc + 1]; printf("\tREor %d, pc=>%d\n", len, pc + 1 + uint.size + len); pc += 1 + uint.size; break; case REgoto: - len = *(uint *)&prog[pc + 1]; + len = *cast(uint *)&prog[pc + 1]; printf("\tREgoto %d, pc=>%d\n", len, pc + 1 + uint.size + len); pc += 1 + uint.size; break; @@ -738,7 +738,7 @@ void printProgram(ubyte[] prog) case REnm: case REnmq: // len, n, m, () - puint = (uint *)&prog[pc + 1]; + puint = cast(uint *)&prog[pc + 1]; len = puint[0]; n = puint[1]; m = puint[2]; @@ -750,7 +750,7 @@ void printProgram(ubyte[] prog) case REparen: // len, n, () - puint = (uint *)&prog[pc + 1]; + puint = cast(uint *)&prog[pc + 1]; len = puint[0]; n = puint[1]; printf("\tREparen len=%d n=%d, pc=>%d\n", len, n, pc + 1 + uint.size * 2 + len); @@ -868,8 +868,8 @@ int trymatch(int pc, int pcend) c2 = input[src]; if (c1 != c2) { - if (islower((tchar)c2)) - c2 = std.ctype.toupper((tchar)c2); + if (islower(cast(tchar)c2)) + c2 = std.ctype.toupper(cast(tchar)c2); else goto Lnomatch; if (c1 != c2) @@ -880,20 +880,20 @@ int trymatch(int pc, int pcend) break; case REwchar: - debug(regexp) printf("\tREwchar '%c', src = '%c'\n", *((wchar *)&program[pc + 1]), input[src]); + debug(regexp) printf("\tREwchar '%c', src = '%c'\n", *(cast(wchar *)&program[pc + 1]), input[src]); if (src == input.length) goto Lnomatch; - if (*((wchar *)&program[pc + 1]) != input[src]) + if (*(cast(wchar *)&program[pc + 1]) != input[src]) goto Lnomatch; src++; pc += 1 + wchar.size; break; case REiwchar: - debug(regexp) printf("\tREiwchar '%c', src = '%c'\n", *((wchar *)&program[pc + 1]), input[src]); + debug(regexp) printf("\tREiwchar '%c', src = '%c'\n", *(cast(wchar *)&program[pc + 1]), input[src]); if (src == input.length) goto Lnomatch; - c1 = *((wchar *)&program[pc + 1]); + c1 = *(cast(wchar *)&program[pc + 1]); c2 = input[src]; if (c1 != c2) { @@ -912,14 +912,14 @@ int trymatch(int pc, int pcend) debug(regexp) printf("\tREanychar\n"); if (src == input.length) goto Lnomatch; - if (!(attributes & REA.dotmatchlf) && input[src] == (tchar)'\n') + if (!(attributes & REA.dotmatchlf) && input[src] == cast(tchar)'\n') goto Lnomatch; src++; pc++; break; case REstring: - len = *(uint *)&program[pc + 1]; + len = *cast(uint *)&program[pc + 1]; debug(regexp) printf("\tREstring x%x, '%.*s'\n", len, (&program[pc + 1 + uint.size])[0 .. len]); if (src + len > input.length) @@ -931,7 +931,7 @@ int trymatch(int pc, int pcend) break; case REistring: - len = *(uint *)&program[pc + 1]; + len = *cast(uint *)&program[pc + 1]; debug(regexp) printf("\tREistring x%x, '%.*s'\n", len, (&program[pc + 1 + uint.size])[0 .. len]); if (src + len > input.length) @@ -952,7 +952,7 @@ int trymatch(int pc, int pcend) break; case REtestbit: - pu = ((ushort *)&program[pc + 1]); + pu = (cast(ushort *)&program[pc + 1]); debug(regexp) printf("\tREtestbit %d, %d, '%c', x%02x\n", pu[0], pu[1], input[src], input[src]); if (src == input.length) @@ -967,7 +967,7 @@ int trymatch(int pc, int pcend) break; case REbit: - pu = ((ushort *)&program[pc + 1]); + pu = (cast(ushort *)&program[pc + 1]); debug(regexp) printf("\tREbit %d, %d, '%c'\n", pu[0], pu[1], input[src]); if (src == input.length) @@ -983,7 +983,7 @@ int trymatch(int pc, int pcend) break; case REnotbit: - pu = ((ushort *)&program[pc + 1]); + pu = (cast(ushort *)&program[pc + 1]); debug(regexp) printf("\tREnotbit %d, %d, '%c'\n", pu[0], pu[1], input[src]); if (src == input.length) @@ -998,24 +998,24 @@ int trymatch(int pc, int pcend) break; case RErange: - len = *(uint *)&program[pc + 1]; + len = *cast(uint *)&program[pc + 1]; debug(regexp) printf("\tRErange %d\n", len); if (src == input.length) goto Lnomatch; // BUG: REA.ignoreCase? - if (memchr((char*)&program[pc + 1 + uint.size], input[src], len) == null) + if (memchr(cast(char*)&program[pc + 1 + uint.size], input[src], len) == null) goto Lnomatch; src++; pc += 1 + uint.size + len; break; case REnotrange: - len = *(uint *)&program[pc + 1]; + len = *cast(uint *)&program[pc + 1]; debug(regexp) printf("\tREnotrange %d\n", len); if (src == input.length) goto Lnomatch; // BUG: REA.ignoreCase? - if (memchr((char*)&program[pc + 1 + uint.size], input[src], len) != null) + if (memchr(cast(char*)&program[pc + 1 + uint.size], input[src], len) != null) goto Lnomatch; src++; pc += 1 + uint.size + len; @@ -1049,7 +1049,7 @@ int trymatch(int pc, int pcend) break; case REor: - len = ((uint *)&program[pc + 1])[0]; + len = (cast(uint *)&program[pc + 1])[0]; debug(regexp) printf("\tREor %d\n", len); pop = pc + 1 + uint.size; ss = src; @@ -1087,7 +1087,7 @@ int trymatch(int pc, int pcend) case REgoto: debug(regexp) printf("\tREgoto\n"); - len = ((uint *)&program[pc + 1])[0]; + len = (cast(uint *)&program[pc + 1])[0]; pc += 1 + uint.size + len; break; @@ -1125,11 +1125,11 @@ int trymatch(int pc, int pcend) case REnm: case REnmq: // len, n, m, () - puint = (uint *)&program[pc + 1]; + puint = cast(uint *)&program[pc + 1]; len = puint[0]; n = puint[1]; m = puint[2]; - debug(regexp) printf("\tREnm%s len=%d, n=%u, m=%u\n", (program[pc] == REnmq) ? (char*)"q" : (char*)"", len, n, m); + debug(regexp) printf("\tREnm%s len=%d, n=%u, m=%u\n", (program[pc] == REnmq) ? cast(char*)"q" : cast(char*)"", len, n, m); pop = pc + 1 + uint.size * 3; for (count = 0; count < n; count++) { @@ -1139,7 +1139,7 @@ int trymatch(int pc, int pcend) if (!psave && count < m) { //version (Win32) - psave = (regmatch_t *)alloca((re_nsub + 1) * regmatch_t.size); + psave = cast(regmatch_t *)alloca((re_nsub + 1) * regmatch_t.size); //else //psave = new regmatch_t[re_nsub + 1]; } @@ -1214,7 +1214,7 @@ int trymatch(int pc, int pcend) case REparen: // len, () debug(regexp) printf("\tREparen\n"); - puint = (uint *)&program[pc + 1]; + puint = cast(uint *)&program[pc + 1]; len = puint[0]; n = puint[1]; pop = pc + 1 + uint.size * 2; @@ -1237,8 +1237,8 @@ int trymatch(int pc, int pcend) c1 = input[src - 1]; c2 = input[src]; if (!( - (isword((tchar)c1) && !isword((tchar)c2)) || - (!isword((tchar)c1) && isword((tchar)c2)) + (isword(cast(tchar)c1) && !isword(cast(tchar)c2)) || + (!isword(cast(tchar)c1) && isword(cast(tchar)c2)) ) ) goto Lnomatch; @@ -1253,8 +1253,8 @@ int trymatch(int pc, int pcend) c1 = input[src - 1]; c2 = input[src]; if ( - (isword((tchar)c1) && !isword((tchar)c2)) || - (!isword((tchar)c1) && isword((tchar)c2)) + (isword(cast(tchar)c1) && !isword(cast(tchar)c2)) || + (!isword(cast(tchar)c1) && isword(cast(tchar)c2)) ) goto Lnomatch; pc++; @@ -1379,15 +1379,15 @@ int parseRegexp() p++; gotooffset = buf.offset; buf.write(REgoto); - buf.write((uint)0); + buf.write(cast(uint)0); len1 = buf.offset - offset; buf.spread(offset, 1 + uint.size); gotooffset += 1 + uint.size; parseRegexp(); len2 = buf.offset - (gotooffset + 1 + uint.size); buf.data[offset] = REor; - ((uint *)&buf.data[offset + 1])[0] = len1; - ((uint *)&buf.data[gotooffset + 1])[0] = len2; + (cast(uint *)&buf.data[offset + 1])[0] = len1; + (cast(uint *)&buf.data[gotooffset + 1])[0] = len2; break; default: @@ -1489,7 +1489,7 @@ int parsePiece() len = buf.offset - offset; buf.spread(offset, 1 + uint.size * 3); buf.data[offset] = op; - uint* puint = (uint *)&buf.data[offset + 1]; + uint* puint = cast(uint *)&buf.data[offset + 1]; puint[0] = len; puint[1] = n; puint[2] = m; @@ -1526,11 +1526,11 @@ int parseAtom() p++; buf.write(REparen); offset = buf.offset; - buf.write((uint)0); // reserve space for length + buf.write(cast(uint)0); // reserve space for length buf.write(re_nsub); re_nsub++; parseRegexp(); - *(uint *)&buf.data[offset] = + *cast(uint *)&buf.data[offset] = buf.offset - (offset + uint.size * 2); if (p == pattern.length || pattern[p] != ')') { @@ -1601,7 +1601,7 @@ int parseAtom() c -= '1'; if (c < re_nsub) { buf.write(REbackref); - buf.write((ubyte)c); + buf.write(cast(ubyte)c); } else { error("no matching back reference"); @@ -1687,7 +1687,7 @@ int parseAtom() Lchar: debug(regexp) printf("It's an REchar '%c'\n", c); buf.write(op); - buf.write((char)c); + buf.write(cast(char)c); } break; } @@ -1725,7 +1725,7 @@ class Range buf.fill0(b - maxb + 1); base = &buf.data[u]; maxb = b + 1; - bits = ((bit*)this.base)[0 .. maxc + 1]; + bits = (cast(bit*)this.base)[0 .. maxc + 1]; } } } @@ -1834,13 +1834,13 @@ int parseRange() case 'w': for (i = 0; i <= cmax; i++) - if (isword((tchar)i)) + if (isword(cast(tchar)i)) r.bits[i] = 1; goto Lrs; case 'W': for (i = 1; i <= cmax; i++) - if (!isword((tchar)i)) + if (!isword(cast(tchar)i)) r.bits[i] = 1; goto Lrs; @@ -1904,8 +1904,8 @@ int parseRange() break; } //printf("maxc = %d, maxb = %d\n",r.maxc,r.maxb); - ((ushort *)&buf.data[offset])[0] = (ushort)r.maxc; - ((ushort *)&buf.data[offset])[1] = (ushort)r.maxb; + (cast(ushort *)&buf.data[offset])[0] = cast(ushort)r.maxc; + (cast(ushort *)&buf.data[offset])[1] = cast(ushort)r.maxb; if (attributes & REA.ignoreCase) { // BUG: what about wchar? @@ -2115,8 +2115,8 @@ void optimize() debug(regexp) printf("\tfilter built\n"); buf.spread(offset, 1 + 4 + r.maxb); buf.data[offset] = REtestbit; - ((ushort *)&buf.data[offset + 1])[0] = (ushort)r.maxc; - ((ushort *)&buf.data[offset + 1])[1] = (ushort)r.maxb; + (cast(ushort *)&buf.data[offset + 1])[0] = cast(ushort)r.maxc; + (cast(ushort *)&buf.data[offset + 1])[1] = cast(ushort)r.maxb; i = offset + 1 + 4; buf.data[i .. i + r.maxb] = r.base[0 .. r.maxb]; } @@ -2161,7 +2161,7 @@ int startchars(Range r, ubyte[] prog) c = prog[i + 1]; if (c <= 0x7F) { r.setbit2(c); - r.setbit2(std.ctype.tolower((tchar)c)); + r.setbit2(std.ctype.tolower(cast(tchar)c)); } return 1; @@ -2173,29 +2173,29 @@ int startchars(Range r, ubyte[] prog) return 0; // no point case REstring: - len = *(uint *)&prog[i + 1]; + len = *cast(uint *)&prog[i + 1]; assert(len); - c = *(tchar *)&prog[i + 1 + uint.size]; + c = *cast(tchar *)&prog[i + 1 + uint.size]; debug(regexp) printf("\tREstring %d, '%c'\n", len, c); if (c <= 0x7F) r.setbit2(c); return 1; case REistring: - len = *(uint *)&prog[i + 1]; + len = *cast(uint *)&prog[i + 1]; assert(len); - c = *(tchar *)&prog[i + 1 + uint.size]; + c = *cast(tchar *)&prog[i + 1 + uint.size]; debug(regexp) printf("\tREistring %d, '%c'\n", len, c); if (c <= 0x7F) - { r.setbit2(std.ctype.toupper((tchar)c)); - r.setbit2(std.ctype.tolower((tchar)c)); + { r.setbit2(std.ctype.toupper(cast(tchar)c)); + r.setbit2(std.ctype.tolower(cast(tchar)c)); } return 1; case REtestbit: case REbit: - maxc = ((ushort *)&prog[i + 1])[0]; - maxb = ((ushort *)&prog[i + 1])[1]; + maxc = (cast(ushort *)&prog[i + 1])[0]; + maxb = (cast(ushort *)&prog[i + 1])[1]; if (maxc <= 0x7F) r.setbitmax(maxc); else @@ -2205,8 +2205,8 @@ int startchars(Range r, ubyte[] prog) return 1; case REnotbit: - maxc = ((ushort *)&prog[i + 1])[0]; - maxb = ((ushort *)&prog[i + 1])[1]; + maxc = (cast(ushort *)&prog[i + 1])[0]; + maxb = (cast(ushort *)&prog[i + 1])[1]; if (maxc <= 0x7F) r.setbitmax(maxc); else @@ -2220,12 +2220,12 @@ int startchars(Range r, ubyte[] prog) return 0; case REor: - len = ((uint *)&prog[i + 1])[0]; + len = (cast(uint *)&prog[i + 1])[0]; return startchars(r, prog[i + 1 + uint.size .. prog.length]) && startchars(r, prog[i + 1 + uint.size + len .. prog.length]); case REgoto: - len = ((uint *)&prog[i + 1])[0]; + len = (cast(uint *)&prog[i + 1])[0]; i += 1 + uint.size + len; break; @@ -2235,9 +2235,9 @@ int startchars(Range r, ubyte[] prog) case REnm: case REnmq: // len, n, m, () - len = ((uint *)&prog[i + 1])[0]; - n = ((uint *)&prog[i + 1])[1]; - m = ((uint *)&prog[i + 1])[2]; + len = (cast(uint *)&prog[i + 1])[0]; + n = (cast(uint *)&prog[i + 1])[1]; + m = (cast(uint *)&prog[i + 1])[2]; pop = &prog[i + 1 + uint.size * 3]; if (!startchars(r, pop[0 .. len])) return 0; @@ -2248,8 +2248,8 @@ int startchars(Range r, ubyte[] prog) case REparen: // len, () - len = ((uint *)&prog[i + 1])[0]; - n = ((uint *)&prog[i + 1])[1]; + len = (cast(uint *)&prog[i + 1])[0]; + n = (cast(uint *)&prog[i + 1])[1]; pop = &prog[0] + i + 1 + uint.size * 2; return startchars(r, pop[0 .. len]); @@ -2291,14 +2291,14 @@ int startchars(Range r, ubyte[] prog) case REword: r.setbitmax(0x7F); for (c = 0; c <= r.maxc; c++) - if (isword((tchar)c)) + if (isword(cast(tchar)c)) r.bits[c] = 1; return 1; case REnotword: r.setbitmax(0x7F); for (c = 0; c <= r.maxc; c++) - if (!isword((tchar)c)) + if (!isword(cast(tchar)c)) r.bits[c] = 1; return 1; @@ -2478,7 +2478,7 @@ private tchar[] replace3(tchar[] format, tchar[] input, regmatch_t[] pmatch) break; } } - result = (tchar[])buf.toBytes(); + result = cast(tchar[])buf.toBytes(); return result; } diff --git a/std/socket.d b/std/socket.d index c016c4d5f..018d63798 100644 --- a/std/socket.d +++ b/std/socket.d @@ -1071,7 +1071,7 @@ class Socket bit isAlive() { int type, typesize = type.sizeof; - return !getsockopt(sock, SOL_SOCKET, SO_TYPE, (char*)type, &typesize); + return !getsockopt(sock, SOL_SOCKET, SO_TYPE, cast(char*)type, &typesize); } diff --git a/std/stream.d b/std/stream.d index 51acafccb..adef09f10 100644 --- a/std/stream.d +++ b/std/stream.d @@ -1161,7 +1161,7 @@ class MemoryStream: Stream uint cur; // current file position // clear to an empty buffer. - this() { this((ubyte[]) null); } + this() { this(cast(ubyte[]) null); } // use this buffer, non-copying. this(ubyte[] buf) @@ -1173,10 +1173,10 @@ class MemoryStream: Stream } // use this buffer, non-copying. - this(byte[] buf) { this((ubyte[]) buf); } + this(byte[] buf) { this(cast(ubyte[]) buf); } // use this buffer, non-copying. - this(char[] buf) { this((ubyte[]) buf); } + this(char[] buf) { this(cast(ubyte[]) buf); } // ensure the stream can hold this many bytes. void reserve(uint count) @@ -1251,7 +1251,7 @@ class MemoryStream: Stream override char[] toString() { - return (char[]) data (); + return cast(char[]) data (); } /* Test the whole class. */ @@ -1268,7 +1268,7 @@ class MemoryStream: Stream assert (m.size () == 12); assert (m.readString (4) == "o, w"); m.writeString ("ie"); - assert ((char[]) m.data () == "Hello, wield"); + assert (cast(char[]) m.data () == "Hello, wield"); m.seekEnd (0); m.writeString ("Foo"); assert (m.position () == 15); @@ -1426,7 +1426,7 @@ class SliceStream : Stream m = new MemoryStream ((cast(char[])"Hello, world").dup); s = new SliceStream (m, 4, 8); assert (s.size () == 4); - assert (s.writeBlock ((char *) "Vroom", 5) == 4); + assert (s.writeBlock (cast(char *) "Vroom", 5) == 4); assert (s.position () == 4); assert (s.seekEnd (-2) == 2); assert (s.seekEnd (2) == 4); diff --git a/std/string.d b/std/string.d index daad51023..1c7049346 100644 --- a/std/string.d +++ b/std/string.d @@ -143,10 +143,10 @@ int icmp(char[] s1, char[] s2) char c2 = s2[i]; if (c1 >= 'A' && c1 <= 'Z') - c1 += (int)'a' - (int)'A'; + c1 += cast(int)'a' - cast(int)'A'; if (c2 >= 'A' && c2 <= 'Z') - c2 += (int)'a' - (int)'A'; - result = (int)c1 - (int)c2; + c2 += cast(int)'a' - cast(int)'A'; + result = cast(int)c1 - cast(int)c2; if (result) break; } @@ -629,7 +629,7 @@ char[] capwords(char[] s) { if (inword == 0) { - c -= (char)'a' - 'A'; + c -= cast(char)'a' - 'A'; r[i] = c; } inword = 1; @@ -1091,7 +1091,7 @@ char[] ljustify(char[] s, int width) return s; char[] r = new char[width]; r[0..s.length] = s; - r[s.length .. width] = (char)' '; + r[s.length .. width] = cast(char)' '; return r; } @@ -1100,7 +1100,7 @@ char[] rjustify(char[] s, int width) if (s.length >= width) return s; char[] r = new char[width]; - r[0 .. width - s.length] = (char)' '; + r[0 .. width - s.length] = cast(char)' '; r[width - s.length .. width] = s; return r; } @@ -1111,9 +1111,9 @@ char[] center(char[] s, int width) return s; char[] r = new char[width]; int left = (width - s.length) / 2; - r[0 .. left] = (char)' '; + r[0 .. left] = cast(char)' '; r[left .. left + s.length] = s; - r[left + s.length .. width] = (char)' '; + r[left + s.length .. width] = cast(char)' '; return r; } @@ -1152,7 +1152,7 @@ char[] zfill(char[] s, int width) if (s.length >= width) return s; char[] r = new char[width]; - r[0 .. width - s.length] = (char)'0'; + r[0 .. width - s.length] = cast(char)'0'; r[width - s.length .. width] = s; return r; } @@ -1206,7 +1206,7 @@ char[] replaceSlice(char[] string, char[] slice, char[] replacement) in { // Verify that slice[] really is a slice of string[] - int so = (char*)slice - (char*)string; + int so = cast(char*)slice - cast(char*)string; assert(so >= 0); //printf("string.length = %d, so = %d, slice.length = %d\n", string.length, so, slice.length); assert(string.length >= so + slice.length); @@ -1214,7 +1214,7 @@ in body { char[] result; - int so = (char*)slice - (char*)string; + int so = cast(char*)slice - cast(char*)string; result.length = string.length - slice.length + replacement.length; diff --git a/std/switcherr.d b/std/switcherr.d index d3f4d4e50..938aa6b29 100644 --- a/std/switcherr.d +++ b/std/switcherr.d @@ -23,7 +23,7 @@ class SwitchError : Object void print() { - printf("Switch Default %s(%u)\n", (char *)filename, linnum); + printf("Switch Default %s(%u)\n", cast(char *)filename, linnum); } } @@ -34,7 +34,7 @@ class SwitchError : Object extern (C) static void _d_switch_error(char[] filename, uint line) { - //printf("_d_switch_error(%s, %d)\n", (char *)filename, line); + //printf("_d_switch_error(%s, %d)\n", cast(char *)filename, line); SwitchError a = new SwitchError(filename, line); //printf("assertion %p created\n", a); throw a; diff --git a/std/thread.d b/std/thread.d index ecabcf8e7..5d87f4b0e 100644 --- a/std/thread.d +++ b/std/thread.d @@ -743,7 +743,7 @@ class Thread allThreads[t.idx] = null; t.idx = -1; nthreads--; - return (void*)result; + return cast(void*)result; } @@ -759,7 +759,7 @@ class Thread t.state = TS.RUNNING; t.id = pthread_self(); - t.stackBottom = (void*)__libc_stack_end; + t.stackBottom = cast(void*)__libc_stack_end; synchronized (threadLock) { assert(!allThreads[0]); diff --git a/std/typeinfo/ti_AC.d b/std/typeinfo/ti_AC.d index e2d5f7928..6b2d04534 100644 --- a/std/typeinfo/ti_AC.d +++ b/std/typeinfo/ti_AC.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_AC : TypeInfo { uint getHash(void *p) - { Object[] s = *(Object[]*)p; + { Object[] s = *cast(Object[]*)p; uint len = s.length; uint hash = 0; @@ -18,8 +18,8 @@ class TypeInfo_AC : TypeInfo int equals(void *p1, void *p2) { - Object[] s1 = *(Object[]*)p1; - Object[] s2 = *(Object[]*)p2; + Object[] s1 = *cast(Object[]*)p1; + Object[] s2 = *cast(Object[]*)p2; if (s1.length == s2.length) { @@ -38,8 +38,8 @@ class TypeInfo_AC : TypeInfo int compare(void *p1, void *p2) { - Object[] s1 = *(Object[]*)p1; - Object[] s2 = *(Object[]*)p2; + Object[] s1 = *cast(Object[]*)p1; + Object[] s2 = *cast(Object[]*)p2; int c; c = cast(int)s1.length - cast(int)s2.length; diff --git a/std/typeinfo/ti_Aa.d b/std/typeinfo/ti_Aa.d index ad272a3a8..e56232af0 100644 --- a/std/typeinfo/ti_Aa.d +++ b/std/typeinfo/ti_Aa.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Aa : TypeInfo { uint getHash(void *p) - { char[] s = *(char[]*)p; + { char[] s = *cast(char[]*)p; uint len = s.length; char *str = s; uint hash = 0; @@ -20,23 +20,23 @@ class TypeInfo_Aa : TypeInfo case 1: hash *= 9; - hash += *(ubyte *)str; + hash += *cast(ubyte *)str; return hash; case 2: hash *= 9; - hash += *(ushort *)str; + hash += *cast(ushort *)str; return hash; case 3: hash *= 9; - hash += (*(ushort *)str << 8) + - ((ubyte *)str)[2]; + hash += (*cast(ushort *)str << 8) + + (cast(ubyte *)str)[2]; return hash; default: hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str += 4; len -= 4; break; @@ -48,17 +48,17 @@ class TypeInfo_Aa : TypeInfo int equals(void *p1, void *p2) { - char[] s1 = *(char[]*)p1; - char[] s2 = *(char[]*)p2; + char[] s1 = *cast(char[]*)p1; + char[] s2 = *cast(char[]*)p2; return s1.length == s2.length && - memcmp((char *)s1, (char *)s2, s1.length) == 0; + memcmp(cast(char *)s1, cast(char *)s2, s1.length) == 0; } int compare(void *p1, void *p2) { - char[] s1 = *(char[]*)p1; - char[] s2 = *(char[]*)p2; + char[] s1 = *cast(char[]*)p1; + char[] s2 = *cast(char[]*)p2; return std.string.cmp(s1, s2); } diff --git a/std/typeinfo/ti_Adchar.d b/std/typeinfo/ti_Adchar.d index 7773ef462..aa34b2dfa 100644 --- a/std/typeinfo/ti_Adchar.d +++ b/std/typeinfo/ti_Adchar.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Aw : TypeInfo { uint getHash(void *p) - { dchar[] s = *(dchar[]*)p; + { dchar[] s = *cast(dchar[]*)p; uint len = s.length; dchar *str = s; uint hash = 0; @@ -24,17 +24,17 @@ class TypeInfo_Aw : TypeInfo int equals(void *p1, void *p2) { - dchar[] s1 = *(dchar[]*)p1; - dchar[] s2 = *(dchar[]*)p2; + dchar[] s1 = *cast(dchar[]*)p1; + dchar[] s2 = *cast(dchar[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * dchar.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * dchar.size) == 0; } int compare(void *p1, void *p2) { - dchar[] s1 = *(dchar[]*)p1; - dchar[] s2 = *(dchar[]*)p2; + dchar[] s1 = *cast(dchar[]*)p1; + dchar[] s2 = *cast(dchar[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Ag.d b/std/typeinfo/ti_Ag.d index 49f321c3a..003742949 100644 --- a/std/typeinfo/ti_Ag.d +++ b/std/typeinfo/ti_Ag.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Ag : TypeInfo { uint getHash(void *p) - { byte[] s = *(byte[]*)p; + { byte[] s = *cast(byte[]*)p; uint len = s.length; byte *str = s; uint hash = 0; @@ -20,23 +20,23 @@ class TypeInfo_Ag : TypeInfo case 1: hash *= 9; - hash += *(ubyte *)str; + hash += *cast(ubyte *)str; return hash; case 2: hash *= 9; - hash += *(ushort *)str; + hash += *cast(ushort *)str; return hash; case 3: hash *= 9; - hash += (*(ushort *)str << 8) + - ((ubyte *)str)[2]; + hash += (*cast(ushort *)str << 8) + + (cast(ubyte *)str)[2]; return hash; default: hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str += 4; len -= 4; break; @@ -48,17 +48,17 @@ class TypeInfo_Ag : TypeInfo int equals(void *p1, void *p2) { - byte[] s1 = *(byte[]*)p1; - byte[] s2 = *(byte[]*)p2; + byte[] s1 = *cast(byte[]*)p1; + byte[] s2 = *cast(byte[]*)p2; return s1.length == s2.length && - memcmp((byte *)s1, (byte *)s2, s1.length) == 0; + memcmp(cast(byte *)s1, cast(byte *)s2, s1.length) == 0; } int compare(void *p1, void *p2) { - byte[] s1 = *(byte[]*)p1; - byte[] s2 = *(byte[]*)p2; + byte[] s1 = *cast(byte[]*)p1; + byte[] s2 = *cast(byte[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Aint.d b/std/typeinfo/ti_Aint.d index 50647a5cc..62f82edf7 100644 --- a/std/typeinfo/ti_Aint.d +++ b/std/typeinfo/ti_Aint.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Ai : TypeInfo { uint getHash(void *p) - { int[] s = *(int[]*)p; + { int[] s = *cast(int[]*)p; uint len = s.length; int *str = s; uint hash = 0; @@ -14,7 +14,7 @@ class TypeInfo_Ai : TypeInfo while (len) { hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str++; len--; } @@ -24,17 +24,17 @@ class TypeInfo_Ai : TypeInfo int equals(void *p1, void *p2) { - int[] s1 = *(int[]*)p1; - int[] s2 = *(int[]*)p2; + int[] s1 = *cast(int[]*)p1; + int[] s2 = *cast(int[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * int.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * int.size) == 0; } int compare(void *p1, void *p2) { - int[] s1 = *(int[]*)p1; - int[] s2 = *(int[]*)p2; + int[] s1 = *cast(int[]*)p1; + int[] s2 = *cast(int[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Along.d b/std/typeinfo/ti_Along.d index 4ae9716d5..7a7e31667 100644 --- a/std/typeinfo/ti_Along.d +++ b/std/typeinfo/ti_Along.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Al : TypeInfo { uint getHash(void *p) - { long[] s = *(long[]*)p; + { long[] s = *cast(long[]*)p; uint len = s.length; long *str = s; uint hash = 0; @@ -24,17 +24,17 @@ class TypeInfo_Al : TypeInfo int equals(void *p1, void *p2) { - long[] s1 = *(long[]*)p1; - long[] s2 = *(long[]*)p2; + long[] s1 = *cast(long[]*)p1; + long[] s2 = *cast(long[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * long.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * long.size) == 0; } int compare(void *p1, void *p2) { - long[] s1 = *(long[]*)p1; - long[] s2 = *(long[]*)p2; + long[] s1 = *cast(long[]*)p1; + long[] s2 = *cast(long[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Ashort.d b/std/typeinfo/ti_Ashort.d index a1d0cc5cb..ae65cb462 100644 --- a/std/typeinfo/ti_Ashort.d +++ b/std/typeinfo/ti_Ashort.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_As : TypeInfo { uint getHash(void *p) - { short[] s = *(short[]*)p; + { short[] s = *cast(short[]*)p; uint len = s.length; short *str = s; uint hash = 0; @@ -20,12 +20,12 @@ class TypeInfo_As : TypeInfo case 1: hash *= 9; - hash += *(short *)str; + hash += *cast(short *)str; return hash; default: hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str += 2; len -= 2; break; @@ -37,17 +37,17 @@ class TypeInfo_As : TypeInfo int equals(void *p1, void *p2) { - short[] s1 = *(short[]*)p1; - short[] s2 = *(short[]*)p2; + short[] s1 = *cast(short[]*)p1; + short[] s2 = *cast(short[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * short.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * short.size) == 0; } int compare(void *p1, void *p2) { - short[] s1 = *(short[]*)p1; - short[] s2 = *(short[]*)p2; + short[] s1 = *cast(short[]*)p1; + short[] s2 = *cast(short[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Aubyte.d b/std/typeinfo/ti_Aubyte.d index fb63bae6d..d7dd1b44b 100644 --- a/std/typeinfo/ti_Aubyte.d +++ b/std/typeinfo/ti_Aubyte.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Ah : TypeInfo { uint getHash(void *p) - { ubyte[] s = *(ubyte[]*)p; + { ubyte[] s = *cast(ubyte[]*)p; uint len = s.length; ubyte *str = s; uint hash = 0; @@ -20,23 +20,23 @@ class TypeInfo_Ah : TypeInfo case 1: hash *= 9; - hash += *(ubyte *)str; + hash += *cast(ubyte *)str; return hash; case 2: hash *= 9; - hash += *(ushort *)str; + hash += *cast(ushort *)str; return hash; case 3: hash *= 9; - hash += (*(ushort *)str << 8) + - ((ubyte *)str)[2]; + hash += (*cast(ushort *)str << 8) + + (cast(ubyte *)str)[2]; return hash; default: hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str += 4; len -= 4; break; @@ -48,17 +48,17 @@ class TypeInfo_Ah : TypeInfo int equals(void *p1, void *p2) { - ubyte[] s1 = *(ubyte[]*)p1; - ubyte[] s2 = *(ubyte[]*)p2; + ubyte[] s1 = *cast(ubyte[]*)p1; + ubyte[] s2 = *cast(ubyte[]*)p2; return s1.length == s2.length && - memcmp((ubyte *)s1, (ubyte *)s2, s1.length) == 0; + memcmp(cast(ubyte *)s1, cast(ubyte *)s2, s1.length) == 0; } int compare(void *p1, void *p2) { - char[] s1 = *(char[]*)p1; - char[] s2 = *(char[]*)p2; + char[] s1 = *cast(char[]*)p1; + char[] s2 = *cast(char[]*)p2; return std.string.cmp(s1, s2); } diff --git a/std/typeinfo/ti_Auint.d b/std/typeinfo/ti_Auint.d index c9e6dd009..cf21812df 100644 --- a/std/typeinfo/ti_Auint.d +++ b/std/typeinfo/ti_Auint.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Ak : TypeInfo { uint getHash(void *p) - { uint[] s = *(uint[]*)p; + { uint[] s = *cast(uint[]*)p; uint len = s.length; uint *str = s; uint hash = 0; @@ -24,17 +24,17 @@ class TypeInfo_Ak : TypeInfo int equals(void *p1, void *p2) { - uint[] s1 = *(uint[]*)p1; - uint[] s2 = *(uint[]*)p2; + uint[] s1 = *cast(uint[]*)p1; + uint[] s2 = *cast(uint[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * uint.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * uint.size) == 0; } int compare(void *p1, void *p2) { - uint[] s1 = *(uint[]*)p1; - uint[] s2 = *(uint[]*)p2; + uint[] s1 = *cast(uint[]*)p1; + uint[] s2 = *cast(uint[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Aulong.d b/std/typeinfo/ti_Aulong.d index fdb7e6e89..2aa3da5f6 100644 --- a/std/typeinfo/ti_Aulong.d +++ b/std/typeinfo/ti_Aulong.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Am : TypeInfo { uint getHash(void *p) - { ulong[] s = *(ulong[]*)p; + { ulong[] s = *cast(ulong[]*)p; uint len = s.length; ulong *str = s; uint hash = 0; @@ -14,7 +14,7 @@ class TypeInfo_Am : TypeInfo while (len) { hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str += 1; len -= 1; } @@ -24,17 +24,17 @@ class TypeInfo_Am : TypeInfo int equals(void *p1, void *p2) { - ulong[] s1 = *(ulong[]*)p1; - ulong[] s2 = *(ulong[]*)p2; + ulong[] s1 = *cast(ulong[]*)p1; + ulong[] s2 = *cast(ulong[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * ulong.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * ulong.size) == 0; } int compare(void *p1, void *p2) { - ulong[] s1 = *(ulong[]*)p1; - ulong[] s2 = *(ulong[]*)p2; + ulong[] s1 = *cast(ulong[]*)p1; + ulong[] s2 = *cast(ulong[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Aushort.d b/std/typeinfo/ti_Aushort.d index d34465e4c..ad3f8b73d 100644 --- a/std/typeinfo/ti_Aushort.d +++ b/std/typeinfo/ti_Aushort.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_At : TypeInfo { uint getHash(void *p) - { ushort[] s = *(ushort[]*)p; + { ushort[] s = *cast(ushort[]*)p; uint len = s.length; ushort *str = s; uint hash = 0; @@ -20,12 +20,12 @@ class TypeInfo_At : TypeInfo case 1: hash *= 9; - hash += *(ushort *)str; + hash += *cast(ushort *)str; return hash; default: hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str += 2; len -= 2; break; @@ -37,17 +37,17 @@ class TypeInfo_At : TypeInfo int equals(void *p1, void *p2) { - ushort[] s1 = *(ushort[]*)p1; - ushort[] s2 = *(ushort[]*)p2; + ushort[] s1 = *cast(ushort[]*)p1; + ushort[] s2 = *cast(ushort[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * ushort.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * ushort.size) == 0; } int compare(void *p1, void *p2) { - ushort[] s1 = *(ushort[]*)p1; - ushort[] s2 = *(ushort[]*)p2; + ushort[] s1 = *cast(ushort[]*)p1; + ushort[] s2 = *cast(ushort[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_Awchar.d b/std/typeinfo/ti_Awchar.d index 34ed65eaf..a3bae33c9 100644 --- a/std/typeinfo/ti_Awchar.d +++ b/std/typeinfo/ti_Awchar.d @@ -6,7 +6,7 @@ private import std.string; class TypeInfo_Au : TypeInfo { uint getHash(void *p) - { wchar[] s = *(wchar[]*)p; + { wchar[] s = *cast(wchar[]*)p; uint len = s.length; wchar *str = s; uint hash = 0; @@ -20,12 +20,12 @@ class TypeInfo_Au : TypeInfo case 1: hash *= 9; - hash += *(wchar *)str; + hash += *cast(wchar *)str; return hash; default: hash *= 9; - hash += *(uint *)str; + hash += *cast(uint *)str; str += 2; len -= 2; break; @@ -37,17 +37,17 @@ class TypeInfo_Au : TypeInfo int equals(void *p1, void *p2) { - wchar[] s1 = *(wchar[]*)p1; - wchar[] s2 = *(wchar[]*)p2; + wchar[] s1 = *cast(wchar[]*)p1; + wchar[] s2 = *cast(wchar[]*)p2; return s1.length == s2.length && - memcmp((void *)s1, (void *)s2, s1.length * wchar.size) == 0; + memcmp(cast(void *)s1, cast(void *)s2, s1.length * wchar.size) == 0; } int compare(void *p1, void *p2) { - wchar[] s1 = *(wchar[]*)p1; - wchar[] s2 = *(wchar[]*)p2; + wchar[] s1 = *cast(wchar[]*)p1; + wchar[] s2 = *cast(wchar[]*)p2; uint len = s1.length; if (s2.length < len) diff --git a/std/typeinfo/ti_C.d b/std/typeinfo/ti_C.d index 12a58f05b..8874353f6 100644 --- a/std/typeinfo/ti_C.d +++ b/std/typeinfo/ti_C.d @@ -7,23 +7,23 @@ class TypeInfo_C : TypeInfo { uint getHash(void *p) { - Object o = *(Object*)p; + Object o = *cast(Object*)p; assert(o); return o.toHash(); } int equals(void *p1, void *p2) { - Object o1 = *(Object*)p1; - Object o2 = *(Object*)p2; + Object o1 = *cast(Object*)p1; + Object o2 = *cast(Object*)p2; return o1 == o2 || (o1 && o1.opCmp(o2) == 0); } int compare(void *p1, void *p2) { - Object o1 = *(Object*)p1; - Object o2 = *(Object*)p2; + Object o1 = *cast(Object*)p1; + Object o2 = *cast(Object*)p2; int c = 0; // Regard null references as always being "less than" diff --git a/std/typeinfo/ti_byte.d b/std/typeinfo/ti_byte.d index 554287422..cdd0872ed 100644 --- a/std/typeinfo/ti_byte.d +++ b/std/typeinfo/ti_byte.d @@ -5,17 +5,17 @@ class TypeInfo_g : TypeInfo { uint getHash(void *p) { - return *(byte *)p; + return *cast(byte *)p; } int equals(void *p1, void *p2) { - return *(byte *)p1 == *(byte *)p2; + return *cast(byte *)p1 == *cast(byte *)p2; } int compare(void *p1, void *p2) { - return *(byte *)p1 - *(byte *)p2; + return *cast(byte *)p1 - *cast(byte *)p2; } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_g : TypeInfo { byte t; - t = *(byte *)p1; - *(byte *)p1 = *(byte *)p2; - *(byte *)p2 = t; + t = *cast(byte *)p1; + *cast(byte *)p1 = *cast(byte *)p2; + *cast(byte *)p2 = t; } } diff --git a/std/typeinfo/ti_cdouble.d b/std/typeinfo/ti_cdouble.d index d86499cd5..016746db9 100644 --- a/std/typeinfo/ti_cdouble.d +++ b/std/typeinfo/ti_cdouble.d @@ -5,19 +5,19 @@ class TypeInfo_r : TypeInfo { uint getHash(void *p) { - return ((uint *)p)[0] + ((uint *)p)[1] + - ((uint *)p)[2] + ((uint *)p)[3]; + return (cast(uint *)p)[0] + (cast(uint *)p)[1] + + (cast(uint *)p)[2] + (cast(uint *)p)[3]; } int equals(void *p1, void *p2) { - return *(cdouble *)p1 == *(cdouble *)p2; + return *cast(cdouble *)p1 == *cast(cdouble *)p2; } int compare(void *p1, void *p2) { - cdouble a = *(cdouble *) p1; - cdouble b = *(cdouble *) p2; + cdouble a = *cast(cdouble *) p1; + cdouble b = *cast(cdouble *) p2; return a < b ? -1 : a > b ? 1 : 0; } @@ -30,9 +30,9 @@ class TypeInfo_r : TypeInfo { cdouble t; - t = *(cdouble *)p1; - *(cdouble *)p1 = *(cdouble *)p2; - *(cdouble *)p2 = t; + t = *cast(cdouble *)p1; + *cast(cdouble *)p1 = *cast(cdouble *)p2; + *cast(cdouble *)p2 = t; } } diff --git a/std/typeinfo/ti_cfloat.d b/std/typeinfo/ti_cfloat.d index 237c11688..cae51bba7 100644 --- a/std/typeinfo/ti_cfloat.d +++ b/std/typeinfo/ti_cfloat.d @@ -5,18 +5,18 @@ class TypeInfo_q : TypeInfo { uint getHash(void *p) { - return ((uint *)p)[0] + ((uint *)p)[1]; + return (cast(uint *)p)[0] + (cast(uint *)p)[1]; } int equals(void *p1, void *p2) { - return *(cfloat *)p1 == *(cfloat *)p2; + return *cast(cfloat *)p1 == *cast(cfloat *)p2; } int compare(void *p1, void *p2) { - cfloat a = *(cfloat *) p1; - cfloat b = *(cfloat *) p2; + cfloat a = *cast(cfloat *) p1; + cfloat b = *cast(cfloat *) p2; return a < b ? -1 : a > b ? 1 : 0; } @@ -29,9 +29,9 @@ class TypeInfo_q : TypeInfo { cfloat t; - t = *(cfloat *)p1; - *(cfloat *)p1 = *(cfloat *)p2; - *(cfloat *)p2 = t; + t = *cast(cfloat *)p1; + *cast(cfloat *)p1 = *cast(cfloat *)p2; + *cast(cfloat *)p2 = t; } } diff --git a/std/typeinfo/ti_char.d b/std/typeinfo/ti_char.d index 45e91619f..3ea160233 100644 --- a/std/typeinfo/ti_char.d +++ b/std/typeinfo/ti_char.d @@ -4,17 +4,17 @@ class TypeInfo_a : TypeInfo { uint getHash(void *p) { - return *(char *)p; + return *cast(char *)p; } int equals(void *p1, void *p2) { - return *(char *)p1 == *(char *)p2; + return *cast(char *)p1 == *cast(char *)p2; } int compare(void *p1, void *p2) { - return *(char *)p1 - *(char *)p2; + return *cast(char *)p1 - *cast(char *)p2; } int tsize() @@ -26,9 +26,9 @@ class TypeInfo_a : TypeInfo { char t; - t = *(char *)p1; - *(char *)p1 = *(char *)p2; - *(char *)p2 = t; + t = *cast(char *)p1; + *cast(char *)p1 = *cast(char *)p2; + *cast(char *)p2 = t; } } diff --git a/std/typeinfo/ti_creal.d b/std/typeinfo/ti_creal.d index 6fcc28e14..7a8df0d82 100644 --- a/std/typeinfo/ti_creal.d +++ b/std/typeinfo/ti_creal.d @@ -5,20 +5,20 @@ class TypeInfo_c : TypeInfo { uint getHash(void *p) { - return ((uint *)p)[0] + ((uint *)p)[1] + - ((uint *)p)[2] + ((uint *)p)[3] + - ((uint *)p)[4]; + return (cast(uint *)p)[0] + (cast(uint *)p)[1] + + (cast(uint *)p)[2] + (cast(uint *)p)[3] + + (cast(uint *)p)[4]; } int equals(void *p1, void *p2) { - return *(creal *)p1 == *(creal *)p2; + return *cast(creal *)p1 == *cast(creal *)p2; } int compare(void *p1, void *p2) { - creal a = *(creal *) p1; - creal b = *(creal *) p2; + creal a = *cast(creal *) p1; + creal b = *cast(creal *) p2; return a < b ? -1 : a > b ? 1 : 0; } @@ -31,9 +31,9 @@ class TypeInfo_c : TypeInfo { creal t; - t = *(creal *)p1; - *(creal *)p1 = *(creal *)p2; - *(creal *)p2 = t; + t = *cast(creal *)p1; + *cast(creal *)p1 = *cast(creal *)p2; + *cast(creal *)p2 = t; } } diff --git a/std/typeinfo/ti_dchar.d b/std/typeinfo/ti_dchar.d index f1f6daad5..bf2c13358 100644 --- a/std/typeinfo/ti_dchar.d +++ b/std/typeinfo/ti_dchar.d @@ -5,17 +5,17 @@ class TypeInfo_w : TypeInfo { uint getHash(void *p) { - return *(dchar *)p; + return *cast(dchar *)p; } int equals(void *p1, void *p2) { - return *(dchar *)p1 == *(dchar *)p2; + return *cast(dchar *)p1 == *cast(dchar *)p2; } int compare(void *p1, void *p2) { - return *(dchar *)p1 - *(dchar *)p2; + return *cast(dchar *)p1 - *cast(dchar *)p2; } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_w : TypeInfo { dchar t; - t = *(dchar *)p1; - *(dchar *)p1 = *(dchar *)p2; - *(dchar *)p2 = t; + t = *cast(dchar *)p1; + *cast(dchar *)p1 = *cast(dchar *)p2; + *cast(dchar *)p2 = t; } } diff --git a/std/typeinfo/ti_delegate.d b/std/typeinfo/ti_delegate.d index 3f128fd99..9a9b3aba8 100644 --- a/std/typeinfo/ti_delegate.d +++ b/std/typeinfo/ti_delegate.d @@ -6,14 +6,14 @@ alias void delegate(int) dg; class TypeInfo_D : TypeInfo { uint getHash(void *p) - { long l = *(long *)p; + { long l = *cast(long *)p; - return (uint)(l + (l >> 32)); + return cast(uint)(l + (l >> 32)); } int equals(void *p1, void *p2) { - return *(dg *)p1 == *(dg *)p2; + return *cast(dg *)p1 == *cast(dg *)p2; } int tsize() @@ -25,9 +25,9 @@ class TypeInfo_D : TypeInfo { dg t; - t = *(dg *)p1; - *(dg *)p1 = *(dg *)p2; - *(dg *)p2 = t; + t = *cast(dg *)p1; + *cast(dg *)p1 = *cast(dg *)p2; + *cast(dg *)p2 = t; } } diff --git a/std/typeinfo/ti_double.d b/std/typeinfo/ti_double.d index 59f68b57b..4a41ed26e 100644 --- a/std/typeinfo/ti_double.d +++ b/std/typeinfo/ti_double.d @@ -5,17 +5,17 @@ class TypeInfo_d : TypeInfo { uint getHash(void *p) { - return ((uint *)p)[0] + ((uint *)p)[1]; + return (cast(uint *)p)[0] + (cast(uint *)p)[1]; } int equals(void *p1, void *p2) { - return *(double *)p1 == *(double *)p2; + return *cast(double *)p1 == *cast(double *)p2; } int compare(void *p1, void *p2) { - return cast(int)(*(double *)p1 - *(double *)p2); + return cast(int)(*cast(double *)p1 - *cast(double *)p2); } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_d : TypeInfo { double t; - t = *(double *)p1; - *(double *)p1 = *(double *)p2; - *(double *)p2 = t; + t = *cast(double *)p1; + *cast(double *)p1 = *cast(double *)p2; + *cast(double *)p2 = t; } } diff --git a/std/typeinfo/ti_float.d b/std/typeinfo/ti_float.d index d029a6e72..e19b516f9 100644 --- a/std/typeinfo/ti_float.d +++ b/std/typeinfo/ti_float.d @@ -5,17 +5,17 @@ class TypeInfo_f : TypeInfo { uint getHash(void *p) { - return *(uint *)p; + return *cast(uint *)p; } int equals(void *p1, void *p2) { - return *(float *)p1 == *(float *)p2; + return *cast(float *)p1 == *cast(float *)p2; } int compare(void *p1, void *p2) { - return cast(int)(*(float *)p1 - *(float *)p2); + return cast(int)(*cast(float *)p1 - *cast(float *)p2); } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_f : TypeInfo { float t; - t = *(float *)p1; - *(float *)p1 = *(float *)p2; - *(float *)p2 = t; + t = *cast(float *)p1; + *cast(float *)p1 = *cast(float *)p2; + *cast(float *)p2 = t; } } diff --git a/std/typeinfo/ti_idouble.d b/std/typeinfo/ti_idouble.d index a15539901..f03f1d403 100644 --- a/std/typeinfo/ti_idouble.d +++ b/std/typeinfo/ti_idouble.d @@ -5,17 +5,17 @@ class TypeInfo_p : TypeInfo { uint getHash(void *p) { - return ((uint *)p)[0] + ((uint *)p)[1]; + return (cast(uint *)p)[0] + (cast(uint *)p)[1]; } int equals(void *p1, void *p2) { - return *(idouble *)p1 == *(idouble *)p2; + return *cast(idouble *)p1 == *cast(idouble *)p2; } int compare(void *p1, void *p2) { - return cast(int)(*(double *)p1 - *(double *)p2); + return cast(int)(*cast(double *)p1 - *cast(double *)p2); } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_p : TypeInfo { idouble t; - t = *(idouble *)p1; - *(idouble *)p1 = *(idouble *)p2; - *(idouble *)p2 = t; + t = *cast(idouble *)p1; + *cast(idouble *)p1 = *cast(idouble *)p2; + *cast(idouble *)p2 = t; } } diff --git a/std/typeinfo/ti_ifloat.d b/std/typeinfo/ti_ifloat.d index 94f651cc7..855107189 100644 --- a/std/typeinfo/ti_ifloat.d +++ b/std/typeinfo/ti_ifloat.d @@ -5,17 +5,17 @@ class TypeInfo_o : TypeInfo { uint getHash(void *p) { - return *(uint *)p; + return *cast(uint *)p; } int equals(void *p1, void *p2) { - return *(ifloat *)p1 == *(ifloat *)p2; + return *cast(ifloat *)p1 == *cast(ifloat *)p2; } int compare(void *p1, void *p2) { - return cast(int)(*(float *)p1 - *(float *)p2); + return cast(int)(*cast(float *)p1 - *cast(float *)p2); } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_o : TypeInfo { ifloat t; - t = *(ifloat *)p1; - *(ifloat *)p1 = *(ifloat *)p2; - *(ifloat *)p2 = t; + t = *cast(ifloat *)p1; + *cast(ifloat *)p1 = *cast(ifloat *)p2; + *cast(ifloat *)p2 = t; } } diff --git a/std/typeinfo/ti_int.d b/std/typeinfo/ti_int.d index cb5f70ce4..9e3947ac2 100644 --- a/std/typeinfo/ti_int.d +++ b/std/typeinfo/ti_int.d @@ -4,17 +4,17 @@ class TypeInfo_i : TypeInfo { uint getHash(void *p) { - return *(uint *)p; + return *cast(uint *)p; } int equals(void *p1, void *p2) { - return *(uint *)p1 == *(uint *)p2; + return *cast(uint *)p1 == *cast(uint *)p2; } int compare(void *p1, void *p2) { - return *(int *)p1 - *(int *)p2; + return *cast(int *)p1 - *cast(int *)p2; } int tsize() @@ -26,9 +26,9 @@ class TypeInfo_i : TypeInfo { int t; - t = *(int *)p1; - *(int *)p1 = *(int *)p2; - *(int *)p2 = t; + t = *cast(int *)p1; + *cast(int *)p1 = *cast(int *)p2; + *cast(int *)p2 = t; } } diff --git a/std/typeinfo/ti_ireal.d b/std/typeinfo/ti_ireal.d index a2513e6d5..4e54cb604 100644 --- a/std/typeinfo/ti_ireal.d +++ b/std/typeinfo/ti_ireal.d @@ -5,17 +5,17 @@ class TypeInfo_j : TypeInfo { uint getHash(void *p) { - return ((uint *)p)[0] + ((uint *)p)[1] + ((ushort *)p)[4]; + return (cast(uint *)p)[0] + (cast(uint *)p)[1] + (cast(ushort *)p)[4]; } int equals(void *p1, void *p2) { - return *(ireal *)p1 == *(ireal *)p2; + return *cast(ireal *)p1 == *cast(ireal *)p2; } int compare(void *p1, void *p2) { - return cast(int)(*(real *)p1 - *(real *)p2); + return cast(int)(*cast(real *)p1 - *cast(real *)p2); } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_j : TypeInfo { ireal t; - t = *(ireal *)p1; - *(ireal *)p1 = *(ireal *)p2; - *(ireal *)p2 = t; + t = *cast(ireal *)p1; + *cast(ireal *)p1 = *cast(ireal *)p2; + *cast(ireal *)p2 = t; } } diff --git a/std/typeinfo/ti_long.d b/std/typeinfo/ti_long.d index 248718545..7969dd8d8 100644 --- a/std/typeinfo/ti_long.d +++ b/std/typeinfo/ti_long.d @@ -5,19 +5,19 @@ class TypeInfo_l : TypeInfo { uint getHash(void *p) { - return *(uint *)p + ((uint *)p)[1]; + return *cast(uint *)p + (cast(uint *)p)[1]; } int equals(void *p1, void *p2) { - return *(long *)p1 == *(long *)p2; + return *cast(long *)p1 == *cast(long *)p2; } int compare(void *p1, void *p2) { - if (*(long *)p1 < *(long *)p2) + if (*cast(long *)p1 < *cast(long *)p2) return -1; - else if (*(long *)p1 > *(long *)p2) + else if (*cast(long *)p1 > *cast(long *)p2) return 1; return 0; } @@ -31,9 +31,9 @@ class TypeInfo_l : TypeInfo { long t; - t = *(long *)p1; - *(long *)p1 = *(long *)p2; - *(long *)p2 = t; + t = *cast(long *)p1; + *cast(long *)p1 = *cast(long *)p2; + *cast(long *)p2 = t; } } diff --git a/std/typeinfo/ti_ptr.d b/std/typeinfo/ti_ptr.d index 083237e17..7d319f04f 100644 --- a/std/typeinfo/ti_ptr.d +++ b/std/typeinfo/ti_ptr.d @@ -5,17 +5,17 @@ class TypeInfo_P : TypeInfo { uint getHash(void *p) { - return (uint)*(void* *)p; + return cast(uint)*cast(void* *)p; } int equals(void *p1, void *p2) { - return *(void* *)p1 == *(void* *)p2; + return *cast(void* *)p1 == *cast(void* *)p2; } int compare(void *p1, void *p2) { - return *(void* *)p1 - *(void* *)p2; + return *cast(void* *)p1 - *cast(void* *)p2; } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_P : TypeInfo { void* t; - t = *(void* *)p1; - *(void* *)p1 = *(void* *)p2; - *(void* *)p2 = t; + t = *cast(void* *)p1; + *cast(void* *)p1 = *cast(void* *)p2; + *cast(void* *)p2 = t; } } diff --git a/std/typeinfo/ti_real.d b/std/typeinfo/ti_real.d index c9bef8467..2203e2942 100644 --- a/std/typeinfo/ti_real.d +++ b/std/typeinfo/ti_real.d @@ -5,17 +5,17 @@ class TypeInfo_e : TypeInfo { uint getHash(void *p) { - return ((uint *)p)[0] + ((uint *)p)[1] + ((ushort *)p)[4]; + return (cast(uint *)p)[0] + (cast(uint *)p)[1] + (cast(ushort *)p)[4]; } int equals(void *p1, void *p2) { - return *(real *)p1 == *(real *)p2; + return *cast(real *)p1 == *cast(real *)p2; } int compare(void *p1, void *p2) { - return cast(int)(*(real *)p1 - *(real *)p2); + return cast(int)(*cast(real *)p1 - *cast(real *)p2); } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_e : TypeInfo { real t; - t = *(real *)p1; - *(real *)p1 = *(real *)p2; - *(real *)p2 = t; + t = *cast(real *)p1; + *cast(real *)p1 = *cast(real *)p2; + *cast(real *)p2 = t; } } diff --git a/std/typeinfo/ti_short.d b/std/typeinfo/ti_short.d index 0fd7c2c43..f738cd26b 100644 --- a/std/typeinfo/ti_short.d +++ b/std/typeinfo/ti_short.d @@ -5,17 +5,17 @@ class TypeInfo_s : TypeInfo { uint getHash(void *p) { - return *(short *)p; + return *cast(short *)p; } int equals(void *p1, void *p2) { - return *(short *)p1 == *(short *)p2; + return *cast(short *)p1 == *cast(short *)p2; } int compare(void *p1, void *p2) { - return *(short *)p1 - *(short *)p2; + return *cast(short *)p1 - *cast(short *)p2; } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_s : TypeInfo { short t; - t = *(short *)p1; - *(short *)p1 = *(short *)p2; - *(short *)p2 = t; + t = *cast(short *)p1; + *cast(short *)p1 = *cast(short *)p2; + *cast(short *)p2 = t; } } diff --git a/std/typeinfo/ti_ubyte.d b/std/typeinfo/ti_ubyte.d index 5f9ac82b1..4e4ed0365 100644 --- a/std/typeinfo/ti_ubyte.d +++ b/std/typeinfo/ti_ubyte.d @@ -5,17 +5,17 @@ class TypeInfo_h : TypeInfo { uint getHash(void *p) { - return *(ubyte *)p; + return *cast(ubyte *)p; } int equals(void *p1, void *p2) { - return *(ubyte *)p1 == *(ubyte *)p2; + return *cast(ubyte *)p1 == *cast(ubyte *)p2; } int compare(void *p1, void *p2) { - return *(ubyte *)p1 - *(ubyte *)p2; + return *cast(ubyte *)p1 - *cast(ubyte *)p2; } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_h : TypeInfo { ubyte t; - t = *(ubyte *)p1; - *(ubyte *)p1 = *(ubyte *)p2; - *(ubyte *)p2 = t; + t = *cast(ubyte *)p1; + *cast(ubyte *)p1 = *cast(ubyte *)p2; + *cast(ubyte *)p2 = t; } } diff --git a/std/typeinfo/ti_uint.d b/std/typeinfo/ti_uint.d index d072a26a4..761103980 100644 --- a/std/typeinfo/ti_uint.d +++ b/std/typeinfo/ti_uint.d @@ -4,17 +4,17 @@ class TypeInfo_k : TypeInfo { uint getHash(void *p) { - return *(uint *)p; + return *cast(uint *)p; } int equals(void *p1, void *p2) { - return *(uint *)p1 == *(uint *)p2; + return *cast(uint *)p1 == *cast(uint *)p2; } int compare(void *p1, void *p2) { - return *(uint *)p1 - *(uint *)p2; + return *cast(uint *)p1 - *cast(uint *)p2; } int tsize() @@ -26,9 +26,9 @@ class TypeInfo_k : TypeInfo { int t; - t = *(uint *)p1; - *(uint *)p1 = *(uint *)p2; - *(uint *)p2 = t; + t = *cast(uint *)p1; + *cast(uint *)p1 = *cast(uint *)p2; + *cast(uint *)p2 = t; } } diff --git a/std/typeinfo/ti_ulong.d b/std/typeinfo/ti_ulong.d index 2946df56c..982a6c877 100644 --- a/std/typeinfo/ti_ulong.d +++ b/std/typeinfo/ti_ulong.d @@ -5,19 +5,19 @@ class TypeInfo_m : TypeInfo { uint getHash(void *p) { - return *(uint *)p + ((uint *)p)[1]; + return *cast(uint *)p + (cast(uint *)p)[1]; } int equals(void *p1, void *p2) { - return *(ulong *)p1 == *(ulong *)p2; + return *cast(ulong *)p1 == *cast(ulong *)p2; } int compare(void *p1, void *p2) { - if (*(ulong *)p1 < *(ulong *)p2) + if (*cast(ulong *)p1 < *cast(ulong *)p2) return -1; - else if (*(ulong *)p1 > *(ulong *)p2) + else if (*cast(ulong *)p1 > *cast(ulong *)p2) return 1; return 0; } @@ -31,9 +31,9 @@ class TypeInfo_m : TypeInfo { ulong t; - t = *(ulong *)p1; - *(ulong *)p1 = *(ulong *)p2; - *(ulong *)p2 = t; + t = *cast(ulong *)p1; + *cast(ulong *)p1 = *cast(ulong *)p2; + *cast(ulong *)p2 = t; } } diff --git a/std/typeinfo/ti_ushort.d b/std/typeinfo/ti_ushort.d index 9e86a01a6..6ec0aa057 100644 --- a/std/typeinfo/ti_ushort.d +++ b/std/typeinfo/ti_ushort.d @@ -5,17 +5,17 @@ class TypeInfo_t : TypeInfo { uint getHash(void *p) { - return *(ushort *)p; + return *cast(ushort *)p; } int equals(void *p1, void *p2) { - return *(ushort *)p1 == *(ushort *)p2; + return *cast(ushort *)p1 == *cast(ushort *)p2; } int compare(void *p1, void *p2) { - return *(ushort *)p1 - *(ushort *)p2; + return *cast(ushort *)p1 - *cast(ushort *)p2; } int tsize() @@ -27,9 +27,9 @@ class TypeInfo_t : TypeInfo { ushort t; - t = *(ushort *)p1; - *(ushort *)p1 = *(ushort *)p2; - *(ushort *)p2 = t; + t = *cast(ushort *)p1; + *cast(ushort *)p1 = *cast(ushort *)p2; + *cast(ushort *)p2 = t; } } diff --git a/std/typeinfo/ti_wchar.d b/std/typeinfo/ti_wchar.d index 5a3d1416f..e25178e70 100644 --- a/std/typeinfo/ti_wchar.d +++ b/std/typeinfo/ti_wchar.d @@ -4,17 +4,17 @@ class TypeInfo_u : TypeInfo { uint getHash(void *p) { - return *(wchar *)p; + return *cast(wchar *)p; } int equals(void *p1, void *p2) { - return *(wchar *)p1 == *(wchar *)p2; + return *cast(wchar *)p1 == *cast(wchar *)p2; } int compare(void *p1, void *p2) { - return *(wchar *)p1 - *(wchar *)p2; + return *cast(wchar *)p1 - *cast(wchar *)p2; } int tsize() @@ -26,9 +26,9 @@ class TypeInfo_u : TypeInfo { wchar t; - t = *(wchar *)p1; - *(wchar *)p1 = *(wchar *)p2; - *(wchar *)p2 = t; + t = *cast(wchar *)p1; + *cast(wchar *)p1 = *cast(wchar *)p2; + *cast(wchar *)p2 = t; } } diff --git a/std/uri.d b/std/uri.d index d2a674f70..5bd023653 100644 --- a/std/uri.d +++ b/std/uri.d @@ -83,7 +83,7 @@ private char[] URI_Encode(dchar[] string, uint unescapedSet) { char* R2; Rsize *= 2; - R2 = (char *)alloca(Rsize * char.size); + R2 = cast(char *)alloca(Rsize * char.size); if (!R2) goto LthrowURIerror; R2[0..Rlen] = R[0..Rlen]; @@ -154,7 +154,7 @@ private char[] URI_Encode(dchar[] string, uint unescapedSet) { char *R2; Rsize = 2 * (Rlen + L * 3); - R2 = (char *)alloca(Rsize * char.size); + R2 = cast(char *)alloca(Rsize * char.size); if (!R2) goto LthrowURIerror; R2[0..Rlen] = R[0..Rlen]; diff --git a/std/utf.d b/std/utf.d index 572059928..d2b78e316 100644 --- a/std/utf.d +++ b/std/utf.d @@ -1,6 +1,6 @@ // utf.d // Written by Walter Bright -// Copyright (c) 2003 Digital Mars +// Copyright (c) 2003-2004 Digital Mars // All Rights Reserved // www.digitalmars.com @@ -18,7 +18,7 @@ class UtfError : Error this(char[] s, uint i) { idx = i; - super("s"); + super(s); } } @@ -34,8 +34,8 @@ bit isValidDchar(dchar c) unittest { debug(utf) printf("utf.isValidDchar.unittest\n"); - assert(isValidDchar((dchar)'a') == true); - assert(isValidDchar((dchar)0x1FFFFF) == false); + assert(isValidDchar(cast(dchar)'a') == true); + assert(isValidDchar(cast(dchar)0x1FFFFF) == false); } /* =================== Decode ======================= */ @@ -135,22 +135,22 @@ unittest static char[] s1 = "abcd"; i = 0; c = decode(s1, i); - assert(c == (dchar)'a'); + assert(c == cast(dchar)'a'); assert(i == 1); c = decode(s1, i); - assert(c == (dchar)'b'); + assert(c == cast(dchar)'b'); assert(i == 2); static char[] s2 = "\xC2\xA9"; i = 0; c = decode(s2, i); - assert(c == (dchar)'\u00A9'); + assert(c == cast(dchar)'\u00A9'); assert(i == 2); static char[] s3 = "\xE2\x89\xA0"; i = 0; c = decode(s3, i); - assert(c == (dchar)'\u2260'); + assert(c == cast(dchar)'\u2260'); assert(i == 3); static char[][] s4 = @@ -310,16 +310,16 @@ unittest debug(utf) printf("utf.encode.unittest\n"); char[] s = "abcd"; - encode(s, (dchar)'a'); + encode(s, cast(dchar)'a'); assert(s.length == 5); assert(s == "abcda"); - encode(s, (dchar)'\u00A9'); + encode(s, cast(dchar)'\u00A9'); assert(s.length == 7); assert(s == "abcda\xC2\xA9"); //assert(s == "abcda\u00A9"); // BUG: fix compiler - encode(s, (dchar)'\u2260'); + encode(s, cast(dchar)'\u2260'); assert(s.length == 10); assert(s == "abcda\xC2\xA9\xE2\x89\xA0"); } diff --git a/std/windows/registry.d b/std/windows/registry.d index fccbe5121..02a744e2b 100644 --- a/std/windows/registry.d +++ b/std/windows/registry.d @@ -4,13 +4,13 @@ * Purpose: Win32 Registry manipulation * * Created 15th March 2003 - * Updated: 18th October 2003 + * Updated: 25th April 2004 * * Author: Matthew Wilson * * License: (Licensed under the Synesis Software Standard Source License) * - * Copyright (C) 2002-2003, Synesis Software Pty Ltd. + * Copyright (C) 2002-2004, Synesis Software Pty Ltd. * * All rights reserved. * @@ -58,8 +58,8 @@ -/** \file D/win32/registry.d This file contains - * the \c D.win32.registry.* classes +/** \file std/windows/registry.d This file contains + * the \c std.windows.registry.* classes */ /* ////////////////////////////////////////////////////////////////////////// */ @@ -70,10 +70,17 @@ module std.windows.registry; * Imports */ +//import std.windows.error_codes; +//import std.windows.types; +private import std.string; +private import std.c.windows.windows; +//private import std.windows.exceptions; + //import synsoft.types; /+ + These are borrowed from synsoft.types, until such time as something similar is in Phobos ++ +/ -public alias int boolean; +/// A strongly-typed Boolean +public alias int boolean; version(LittleEndian) { @@ -84,6 +91,23 @@ version(BigEndian) private const int Endian_Ambient = 2; } +class Win32Exception : Exception +{ + int error; + + this(char[] message) + { + super(msg); + } + + this(char[] msg, int errnum) + { + super(msg); + error = errnum; + } +} + +/// An enumeration representing byte-ordering (Endian) strategies public enum Endian { Unknown = 0 //!< Unknown endian-ness. Indicates an error @@ -111,160 +135,11 @@ public enum Endian /+ + These are borrowed from synsoft.win32.types for the moment, but will not be + needed once I've convinced Walter to use strong typedefs for things like HKEY + +/ -public typedef uint Reserved; +private typedef uint Reserved; +/// The registry key handle public typedef void *HKEY; -public alias HKEY *PHKEY; -public alias char *LPCSTR; -public alias int LONG; -public alias uint DWORD; -public alias DWORD *LPDWORD; -public alias void *LPSECURITY_ATTRIBUTES; -public alias char *LPSTR; -public alias char *LPCSTR; -public alias void *LPCVOID; -public struct FILETIME -{ - DWORD dwLowDateTime; - DWORD dwHighDateTime; -}; -/+ - +/ - - -//import synsoft.win32.error_codes; -/+ +++++++ These are in here for now, but will be in windows.d very soon +++++++ - +/ -public const LONG ERROR_SUCCESS = 0; -public const LONG ERROR_ACCESS_DENIED = 5; -public const LONG ERROR_MORE_DATA = 234; -public const LONG ERROR_NO_MORE_ITEMS = 259; -/+ - +/ - - -//import synsoft.win32.exception; -/+ +++ This is in here, until the Phobos exception hierarchy is implemented ++++ - +/ -class Win32Exception - : Exception -{ -/// \name Construction -//@{ -public: - /// \brief Creates an instance of the exception - /// - /// \param message The message associated with the exception - this(char[] message) - { - this(message, GetLastError()); - } - /// \brief Creates an instance of the exception, with the given - /// - /// \param message The message associated with the exception - /// \param error The Win32 error number associated with the exception - this(char[] message, int error) - { - char sz[24]; // Enough for the three " ()" characters and a 64-bit integer value - int cch = wsprintfA(sz, " (%d)", error); - - m_message = message; - m_error = error; - - super(message ~ sz[0 .. cch]); - } -//@} - -/// \name Attributes -//@{ -public: - /// Returns the message string associated with the exception - char[] Message() - { - return m_message; - } - - /// Returns the Win32 error code associated with the exception - int Error() - { - return m_error; - } - - /// Converts the error code into a string - /// - /// \note Not yet implemented - char[] LookupError(char[] moduleName) - { - return null; - } - -//@} - -/// \name Members -//@{ -private: - char[] m_message; - int m_error; -//@} -} - -unittest -{ - // (i) Test that we can throw and catch one by its own type - try - { - char[] message = "Test 1"; - int code = 3; - char[] string = "Test 1 (3)"; - - try - { - throw new Win32Exception(message, code); - } - catch(Win32Exception x) - { - assert(x.Error == code); - if(message != x.Message) - { - printf( "UnitTest failure for Win32Exception:\n" - " x.message [%d;\"%.*s\"] does not equal [%d;\"%.*s\"]\n" - , x.Message.length, x.Message - , message.length, message); - } - assert(message == x.Message); - } - } - catch(Exception /* x */) - { - int code_flow_should_never_reach_here = 0; - assert(code_flow_should_never_reach_here); - } - - // (ii) Catch that can throw and be caught by Exception - { - char[] message = "Test 2"; - int code = 3; - char[] string = "Test 2 (3)"; - - try - { - throw new Win32Exception(message, code); - } - catch(Exception x) - { - if(string != x.toString()) - { - printf( "UnitTest failure for Win32Exception:\n" - " x.toString() [%d;\"%.*s\"] does not equal [%d;\"%.*s\"]\n" - , x.toString().length, x.toString() - , string.length, string); - } - assert(string == x.toString()); - } - } -} -/+ - +/ - +private alias HKEY *PHKEY; +private alias void *LPSECURITY_ATTRIBUTES; //import synsoft.text.token; /+ ++++++ This is borrowed from synsoft.text.token, until such time as something @@ -337,7 +212,7 @@ char[][] tokenise(char[] source, char delimiter, boolean bElideBlanks, boolean b { for(i = 0; i < tokens.length; ++i) { - tokens[i] ~= (char)0; + tokens[i] ~= cast(char)0; } } @@ -347,12 +222,10 @@ char[][] tokenise(char[] source, char delimiter, boolean bElideBlanks, boolean b +/ -private import std.string; - /* ////////////////////////////////////////////////////////////////////////// */ -/// \defgroup group_D_win32_reg D.win32.registry -/// \ingroup group_D_win32 +/// \defgroup group_std_windows_reg std.windows.registry +/// \ingroup group_std_windows /// \brief This library provides Win32 Registry facilities /* ///////////////////////////////////////////////////////////////////////////// @@ -375,17 +248,17 @@ private const DWORD STANDARD_RIGHTS_ALL = 0x001F0000L; private const DWORD SPECIFIC_RIGHTS_ALL = 0x0000FFFFL; -private const HKEY HKEY_CLASSES_ROOT = ((HKEY)0x80000000); -private const HKEY HKEY_CURRENT_USER = ((HKEY)0x80000001); -private const HKEY HKEY_LOCAL_MACHINE = ((HKEY)0x80000002); -private const HKEY HKEY_USERS = ((HKEY)0x80000003); -private const HKEY HKEY_PERFORMANCE_DATA = ((HKEY)0x80000004); -private const HKEY HKEY_PERFORMANCE_TEXT = ((HKEY)0x80000050); -private const HKEY HKEY_PERFORMANCE_NLSTEXT = ((HKEY)0x80000060); -private const HKEY HKEY_CURRENT_CONFIG = ((HKEY)0x80000005); -private const HKEY HKEY_DYN_DATA = ((HKEY)0x80000006); +private const HKEY HKEY_CLASSES_ROOT = (cast(HKEY)0x80000000); +private const HKEY HKEY_CURRENT_USER = (cast(HKEY)0x80000001); +private const HKEY HKEY_LOCAL_MACHINE = (cast(HKEY)0x80000002); +private const HKEY HKEY_USERS = (cast(HKEY)0x80000003); +private const HKEY HKEY_PERFORMANCE_DATA = (cast(HKEY)0x80000004); +private const HKEY HKEY_PERFORMANCE_TEXT = (cast(HKEY)0x80000050); +private const HKEY HKEY_PERFORMANCE_NLSTEXT = (cast(HKEY)0x80000060); +private const HKEY HKEY_CURRENT_CONFIG = (cast(HKEY)0x80000005); +private const HKEY HKEY_DYN_DATA = (cast(HKEY)0x80000006); -private const Reserved RESERVED = (Reserved)0; +private const Reserved RESERVED = cast(Reserved)0; private const DWORD REG_CREATED_NEW_KEY = 0x00000001; private const DWORD REG_OPENED_EXISTING_KEY = 0x00000002; @@ -569,7 +442,7 @@ body * - removing the reserved arguments. */ -private LONG _Reg_CloseKey(in HKEY hkey) +private LONG Reg_CloseKey_(in HKEY hkey) in { assert(null !== hkey); @@ -581,9 +454,9 @@ body * these hive keys is ignored, we'd rather not trust the Win32 * API. */ - if((uint)hkey & 0x80000000) + if(cast(uint)hkey & 0x80000000) { - switch((uint)hkey) + switch(cast(uint)hkey) { case HKEY_CLASSES_ROOT: case HKEY_CURRENT_USER: @@ -604,7 +477,7 @@ body return RegCloseKey(hkey); } -private LONG _Reg_FlushKey(in HKEY hkey) +private LONG Reg_FlushKey_(in HKEY hkey) in { assert(null !== hkey); @@ -614,7 +487,7 @@ body return RegFlushKey(hkey); } -private LONG _Reg_CreateKeyExA( in HKEY hkey, in char[] subKey +private LONG Reg_CreateKeyExA_( in HKEY hkey, in char[] subKey , in DWORD dwOptions, in REGSAM samDesired , in LPSECURITY_ATTRIBUTES lpsa , out HKEY hkeyResult, out DWORD disposition) @@ -630,7 +503,7 @@ body , disposition); } -private LONG _Reg_DeleteKeyA(in HKEY hkey, in char[] subKey) +private LONG Reg_DeleteKeyA_(in HKEY hkey, in char[] subKey) in { assert(null !== hkey); @@ -641,7 +514,7 @@ body return RegDeleteKeyA(hkey, toStringz(subKey)); } -private LONG _Reg_DeleteValueA(in HKEY hkey, in char[] valueName) +private LONG Reg_DeleteValueA_(in HKEY hkey, in char[] valueName) in { assert(null !== hkey); @@ -652,7 +525,7 @@ body return RegDeleteValueA(hkey, toStringz(valueName)); } -private HKEY _Reg_Dup(HKEY hkey) +private HKEY Reg_Dup_(HKEY hkey) in { assert(null !== hkey); @@ -660,9 +533,9 @@ in body { /* Can't duplicate standard keys, but don't need to, so can just return */ - if((uint)hkey & 0x80000000) + if(cast(uint)hkey & 0x80000000) { - switch((uint)hkey) + switch(cast(uint)hkey) { case HKEY_CLASSES_ROOT: case HKEY_CURRENT_USER: @@ -687,7 +560,7 @@ body { if(ERROR_SUCCESS != lRes) { - printf("_Reg_Dup() failed: 0x%08x 0x%08x %d\n", hkey, hkeyDup, lRes); + printf("Reg_Dup_() failed: 0x%08x 0x%08x %d\n", hkey, hkeyDup, lRes); } assert(ERROR_SUCCESS == lRes); @@ -696,7 +569,7 @@ body return (ERROR_SUCCESS == lRes) ? hkeyDup : null; } -private LONG _Reg_EnumKeyName( in HKEY hkey, in DWORD index, inout char [] name +private LONG Reg_EnumKeyName_( in HKEY hkey, in DWORD index, inout char [] name , out DWORD cchName) in { @@ -732,7 +605,7 @@ body } -private LONG _Reg_EnumValueName(in HKEY hkey, in DWORD dwIndex, in LPSTR lpName +private LONG Reg_EnumValueName_(in HKEY hkey, in DWORD dwIndex, in LPSTR lpName , inout DWORD cchName) in { @@ -743,7 +616,7 @@ body return RegEnumValueA(hkey, dwIndex, lpName, cchName, RESERVED, null, null, null); } -private LONG _Reg_GetNumSubKeys(in HKEY hkey, out DWORD cSubKeys +private LONG Reg_GetNumSubKeys_(in HKEY hkey, out DWORD cSubKeys , out DWORD cchSubKeyMaxLen) in { @@ -755,7 +628,7 @@ body , &cchSubKeyMaxLen, null, null, null, null, null, null); } -private LONG _Reg_GetNumValues( in HKEY hkey, out DWORD cValues +private LONG Reg_GetNumValues_( in HKEY hkey, out DWORD cValues , out DWORD cchValueMaxLen) in { @@ -767,7 +640,7 @@ body , &cValues, &cchValueMaxLen, null, null, null); } -private LONG _Reg_GetValueType( in HKEY hkey, in char[] name +private LONG Reg_GetValueType_( in HKEY hkey, in char[] name , out REG_VALUE_TYPE type) in { @@ -777,7 +650,7 @@ body { DWORD cbData = 0; LONG res = RegQueryValueExA( hkey, toStringz(name), RESERVED, type - , (byte*)0, cbData); + , cast(byte*)0, cbData); if(ERROR_MORE_DATA == res) { @@ -787,7 +660,7 @@ body return res; } -private LONG _Reg_OpenKeyExA( in HKEY hkey, in char[] subKey +private LONG Reg_OpenKeyExA_( in HKEY hkey, in char[] subKey , in REGSAM samDesired, out HKEY hkeyResult) in { @@ -799,7 +672,7 @@ body return RegOpenKeyExA(hkey, toStringz(subKey), RESERVED, samDesired, hkeyResult); } -private void _Reg_QueryValue( in HKEY hkey, in char[] name, out char[] value +private void Reg_QueryValue_( in HKEY hkey, in char[] name, out char[] value , out REG_VALUE_TYPE type) in { @@ -841,7 +714,7 @@ body break; case REG_VALUE_TYPE.REG_SZ: case REG_VALUE_TYPE.REG_EXPAND_SZ: - value = std.string.toString((char*)data); + value = std.string.toString(cast(char*)data); break; version(LittleEndian) { @@ -868,7 +741,7 @@ version(BigEndian) } } -private void _Reg_QueryValue( in HKEY hkey, in char[] name, out char[][] value +private void Reg_QueryValue_( in HKEY hkey, in char[] name, out char[][] value , out REG_VALUE_TYPE type) in { @@ -909,10 +782,10 @@ body } // Now need to tokenise it - value = tokenise(data, (char)0, 1, 0); + value = tokenise(data, cast(char)0, 1, 0); } -private void _Reg_QueryValue( in HKEY hkey, in char[] name, out uint value +private void Reg_QueryValue_( in HKEY hkey, in char[] name, out uint value , out REG_VALUE_TYPE type) in { @@ -955,7 +828,7 @@ version(BigEndian) } } -private void _Reg_QueryValue( in HKEY hkey, in char[] name, out ulong value +private void Reg_QueryValue_( in HKEY hkey, in char[] name, out ulong value , out REG_VALUE_TYPE type) in { @@ -984,7 +857,7 @@ body } } -private void _Reg_QueryValue( in HKEY hkey, in char[] name, out byte[] value +private void Reg_QueryValue_( in HKEY hkey, in char[] name, out byte[] value , out REG_VALUE_TYPE type) in { @@ -1023,7 +896,7 @@ body } } -private void _Reg_SetValueExA( in HKEY hkey, in char[] subKey +private void Reg_SetValueExA_( in HKEY hkey, in char[] subKey , in REG_VALUE_TYPE type, in LPCVOID lpData , in DWORD cbData) in @@ -1048,7 +921,7 @@ body //////////////////////////////////////////////////////////////////////////////// // RegistryException -/// Exception class thrown by the D.win32.registry classes +/// Exception class thrown by the std.windows.registry classes /// /// \ingroup group_D_win32_reg @@ -1091,15 +964,15 @@ unittest } catch(RegistryException x) { - assert(x.Error == code); + assert(x.error == code); if(string != x.toString()) { printf( "UnitTest failure for RegistryException:\n" " x.message [%d;\"%.*s\"] does not equal [%d;\"%.*s\"]\n" - , x.Message.length, x.Message + , x.message.length, x.message , string.length, string); } - assert(message == x.Message); + assert(message == x.message); } } catch(Exception /* x */) @@ -1140,7 +1013,7 @@ private: ~this() { - _Reg_CloseKey(m_hkey); + Reg_CloseKey_(m_hkey); // Even though this is horried waste-of-cycles programming // we're doing it here so that the @@ -1152,7 +1025,7 @@ private: //@{ public: /// The name of the key - char[] Name() + char[] name() { return m_name; } @@ -1165,11 +1038,11 @@ public: */ /// The number of sub keys - uint KeyCount() + uint keyCount() { uint cSubKeys; uint cchSubKeyMaxLen; - LONG res = _Reg_GetNumSubKeys(m_hkey, cSubKeys, cchSubKeyMaxLen); + LONG res = Reg_GetNumSubKeys_(m_hkey, cSubKeys, cchSubKeyMaxLen); if(ERROR_SUCCESS != res) { @@ -1180,23 +1053,23 @@ public: } /// An enumerable sequence of all the sub-keys of this key - KeySequence Keys() + KeySequence keys() { return new KeySequence(this); } /// An enumerable sequence of the names of all the sub-keys of this key - KeyNameSequence KeyNames() + KeyNameSequence keyNames() { return new KeyNameSequence(this); } /// The number of values - uint ValueCount() + uint valueCount() { uint cValues; uint cchValueMaxLen; - LONG res = _Reg_GetNumValues(m_hkey, cValues, cchValueMaxLen); + LONG res = Reg_GetNumValues_(m_hkey, cValues, cchValueMaxLen); if(ERROR_SUCCESS != res) { @@ -1207,13 +1080,13 @@ public: } /// An enumerable sequence of all the values of this key - ValueSequence Values() + ValueSequence values() { return new ValueSequence(this); } /// An enumerable sequence of the names of all the values of this key - ValueNameSequence ValueNames() + ValueNameSequence valueNames() { return new ValueNameSequence(this); } @@ -1227,7 +1100,7 @@ public: /// \param name The name of the subkey to create. May not be null /// \return The created key /// \note If the key cannot be created, a RegistryException is thrown. - Key CreateKey(char[] name, REGSAM access) + Key createKey(char[] name, REGSAM access) { if( null === name || 0 == name.length) @@ -1238,7 +1111,7 @@ public: { HKEY hkey; DWORD disposition; - LONG lRes = _Reg_CreateKeyExA( m_hkey, name, 0 + LONG lRes = Reg_CreateKeyExA_( m_hkey, name, 0 , REGSAM.KEY_ALL_ACCESS , null, hkey, disposition); @@ -1266,7 +1139,7 @@ public: { if(hkey != null) { - _Reg_CloseKey(hkey); + Reg_CloseKey_(hkey); } } } @@ -1278,9 +1151,9 @@ public: /// \return The created key /// \note If the key cannot be created, a RegistryException is thrown. /// \note This function is equivalent to calling CreateKey(name, REGSAM.KEY_ALL_ACCESS), and returns a key with all access - Key CreateKey(char[] name) + Key createKey(char[] name) { - return CreateKey(name, (REGSAM)REGSAM.KEY_ALL_ACCESS); + return createKey(name, cast(REGSAM)REGSAM.KEY_ALL_ACCESS); } /// Returns the named sub-key of this key @@ -1289,17 +1162,17 @@ public: /// \param access The desired access; one of the REGSAM enumeration /// \return The aquired key. /// \note This function never returns null. If a key corresponding to the requested name is not found, a RegistryException is thrown - Key GetKey(char[] name, REGSAM access) + Key getKey(char[] name, REGSAM access) { if( null === name || 0 == name.length) { - return new Key(_Reg_Dup(m_hkey), m_name, false); + return new Key(Reg_Dup_(m_hkey), m_name, false); } else { HKEY hkey; - LONG lRes = _Reg_OpenKeyExA(m_hkey, name, REGSAM.KEY_ALL_ACCESS, hkey); + LONG lRes = Reg_OpenKeyExA_(m_hkey, name, REGSAM.KEY_ALL_ACCESS, hkey); if(ERROR_SUCCESS != lRes) { @@ -1325,7 +1198,7 @@ public: { if(hkey != null) { - _Reg_CloseKey(hkey); + Reg_CloseKey_(hkey); } } } @@ -1337,15 +1210,15 @@ public: /// \return The aquired key. /// \note This function never returns null. If a key corresponding to the requested name is not found, a RegistryException is thrown /// \note This function is equivalent to calling GetKey(name, REGSAM.KEY_READ), and returns a key with read/enum access - Key GetKey(char[] name) + Key getKey(char[] name) { - return GetKey(name, (REGSAM)(REGSAM.KEY_READ)); + return getKey(name, cast(REGSAM)(REGSAM.KEY_READ)); } /// Deletes the named key /// /// \param name The name of the key to delete. May not be null - void DeleteKey(char[] name) + void deleteKey(char[] name) { if( null === name || 0 == name.length) @@ -1354,7 +1227,7 @@ public: } else { - LONG res = _Reg_DeleteKeyA(m_hkey, name); + LONG res = Reg_DeleteKeyA_(m_hkey, name); if(ERROR_SUCCESS != res) { @@ -1367,10 +1240,10 @@ public: /// /// \note if name is null (or the empty-string), then the default value is returned /// \return This function never returns null. If a value corresponding to the requested name is not found, a RegistryException is thrown - Value GetValue(char[] name) + Value getValue(char[] name) { REG_VALUE_TYPE type; - LONG res = _Reg_GetValueType(m_hkey, name, type); + LONG res = Reg_GetValueType_(m_hkey, name, type); if(ERROR_SUCCESS == res) { @@ -1387,9 +1260,9 @@ public: /// \param name The name of the value to set. If null, or the empty string, sets the default value /// \param value The 32-bit unsigned value to set /// \note If a value corresponding to the requested name is not found, a RegistryException is thrown - void SetValue(char[] name, uint value) + void setValue(char[] name, uint value) { - SetValue(name, value, Endian.Ambient); + setValue(name, value, Endian.Ambient); } /// Sets the named value with the given 32-bit unsigned integer value, according to the desired byte-ordering @@ -1398,14 +1271,14 @@ public: /// \param value The 32-bit unsigned value to set /// \param endian Can be Endian.Big or Endian.Little /// \note If a value corresponding to the requested name is not found, a RegistryException is thrown - void SetValue(char[] name, uint value, Endian endian) + void setValue(char[] name, uint value, Endian endian) { REG_VALUE_TYPE type = _RVT_from_Endian(endian); assert( type == REG_VALUE_TYPE.REG_DWORD_BIG_ENDIAN || type == REG_VALUE_TYPE.REG_DWORD_LITTLE_ENDIAN); - _Reg_SetValueExA(m_hkey, name, type, &value, value.size); + Reg_SetValueExA_(m_hkey, name, type, &value, value.size); } /// Sets the named value with the given 64-bit unsigned integer value @@ -1413,9 +1286,9 @@ public: /// \param name The name of the value to set. If null, or the empty string, sets the default value /// \param value The 64-bit unsigned value to set /// \note If a value corresponding to the requested name is not found, a RegistryException is thrown - void SetValue(char[] name, ulong value) + void setValue(char[] name, ulong value) { - _Reg_SetValueExA(m_hkey, name, REG_VALUE_TYPE.REG_QWORD, &value, value.size); + Reg_SetValueExA_(m_hkey, name, REG_VALUE_TYPE.REG_QWORD, &value, value.size); } /// Sets the named value with the given string value @@ -1423,9 +1296,9 @@ public: /// \param name The name of the value to set. If null, or the empty string, sets the default value /// \param value The string value to set /// \note If a value corresponding to the requested name is not found, a RegistryException is thrown - void SetValue(char[] name, char[] value) + void setValue(char[] name, char[] value) { - SetValue(name, value, false); + setValue(name, value, false); } /// Sets the named value with the given string value @@ -1434,9 +1307,9 @@ public: /// \param value The string value to set /// \param asEXPAND_SZ If true, the value will be stored as an expandable environment string, otherwise as a normal string /// \note If a value corresponding to the requested name is not found, a RegistryException is thrown - void SetValue(char[] name, char[] value, boolean asEXPAND_SZ) + void setValue(char[] name, char[] value, boolean asEXPAND_SZ) { - _Reg_SetValueExA(m_hkey, name, asEXPAND_SZ + Reg_SetValueExA_(m_hkey, name, asEXPAND_SZ ? REG_VALUE_TYPE.REG_EXPAND_SZ : REG_VALUE_TYPE.REG_SZ, value , value.length); @@ -1447,7 +1320,7 @@ public: /// \param name The name of the value to set. If null, or the empty string, sets the default value /// \param value The multiple-strings value to set /// \note If a value corresponding to the requested name is not found, a RegistryException is thrown - void SetValue(char[] name, char[][] value) + void setValue(char[] name, char[][] value) { int total = 2; @@ -1475,7 +1348,7 @@ public: base = 1 + top; } - _Reg_SetValueExA(m_hkey, name, REG_VALUE_TYPE.REG_MULTI_SZ, cs, cs.length); + Reg_SetValueExA_(m_hkey, name, REG_VALUE_TYPE.REG_MULTI_SZ, cs, cs.length); } /// Sets the named value with the given binary value @@ -1483,18 +1356,18 @@ public: /// \param name The name of the value to set. If null, or the empty string, sets the default value /// \param value The binary value to set /// \note If a value corresponding to the requested name is not found, a RegistryException is thrown - void SetValue(char[] name, byte[] value) + void setValue(char[] name, byte[] value) { - _Reg_SetValueExA(m_hkey, name, REG_VALUE_TYPE.REG_BINARY, value, value.length); + Reg_SetValueExA_(m_hkey, name, REG_VALUE_TYPE.REG_BINARY, value, value.length); } /// Deletes the named value /// /// \param name The name of the value to delete. May not be null /// \note If a value of the requested name is not found, a RegistryException is thrown - void DeleteValue(char[] name) + void deleteValue(char[] name) { - LONG res = _Reg_DeleteValueA(m_hkey, name); + LONG res = Reg_DeleteValueA_(m_hkey, name); if(ERROR_SUCCESS != res) { @@ -1504,9 +1377,9 @@ public: /// Flushes any changes to the key to disk /// - void Flush() + void flush() { - LONG res = _Reg_FlushKey(m_hkey); + LONG res = Reg_FlushKey_(m_hkey); if(ERROR_SUCCESS != res) { @@ -1557,13 +1430,13 @@ public: /// The name of the value. /// /// \note If the value represents a default value of a key, which has no name, the returned string will be of zero length - char[] Name() + char[] name() { return m_name; } /// The type of value - REG_VALUE_TYPE Type() + REG_VALUE_TYPE type() { return m_type; } @@ -1573,12 +1446,12 @@ public: /// \return The contents of the value /// \note If the value's type is REG_EXPAND_SZ the returned value is not expanded; Value_EXPAND_SZ() should be called /// \note Throws a RegistryException if the type of the value is not REG_SZ, REG_EXPAND_SZ, REG_DWORD(_*) or REG_QWORD(_*): - char[] Value_SZ() + char[] value_SZ() { REG_VALUE_TYPE type; char[] value; - _Reg_QueryValue(m_key.m_hkey, m_name, value, type); + Reg_QueryValue_(m_key.m_hkey, m_name, value, type); if(type != m_type) { @@ -1592,9 +1465,9 @@ public: /// /// \return The contents of the value /// \note This function works with the same value-types as Value_SZ(). - char[] Value_EXPAND_SZ() + char[] value_EXPAND_SZ() { - char[] value = Value_SZ; + char[] value = value_SZ; /+ value = expand_environment_strings(value); @@ -1618,12 +1491,12 @@ public: /// /// \return The contents of the value /// \note Throws a RegistryException if the type of the value is not REG_MULTI_SZ - char[][] Value_MULTI_SZ() + char[][] value_MULTI_SZ() { REG_VALUE_TYPE type; char[][] value; - _Reg_QueryValue(m_key.m_hkey, m_name, value, type); + Reg_QueryValue_(m_key.m_hkey, m_name, value, type); if(type != m_type) { @@ -1637,12 +1510,12 @@ public: /// /// \return The contents of the value /// \note An exception is thrown for all types other than REG_DWORD, REG_DWORD_LITTLE_ENDIAN and REG_DWORD_BIG_ENDIAN. - uint Value_DWORD() + uint value_DWORD() { REG_VALUE_TYPE type; uint value; - _Reg_QueryValue(m_key.m_hkey, m_name, value, type); + Reg_QueryValue_(m_key.m_hkey, m_name, value, type); if(type != m_type) { @@ -1652,26 +1525,26 @@ public: return value; } - deprecated uint Value_DWORD_LITTLEENDIAN() + deprecated uint value_DWORD_LITTLEENDIAN() { - return Value_DWORD(); + return value_DWORD(); } - deprecated uint Value_DWORD_BIGENDIAN() + deprecated uint value_DWORD_BIGENDIAN() { - return Value_DWORD(); + return value_DWORD(); } /// Obtains the value as a 64-bit unsigned integer, ordered correctly according to the current architecture /// /// \return The contents of the value /// \note Throws a RegistryException if the type of the value is not REG_QWORD - ulong Value_QWORD() + ulong value_QWORD() { REG_VALUE_TYPE type; ulong value; - _Reg_QueryValue(m_key.m_hkey, m_name, value, type); + Reg_QueryValue_(m_key.m_hkey, m_name, value, type); if(type != m_type) { @@ -1681,21 +1554,21 @@ public: return value; } - deprecated ulong Value_QWORD_LITTLEENDIAN() + deprecated ulong value_QWORD_LITTLEENDIAN() { - return Value_QWORD(); + return value_QWORD(); } /// Obtains the value as a binary blob /// /// \return The contents of the value /// \note Throws a RegistryException if the type of the value is not REG_BINARY - byte[] Value_BINARY() + byte[] value_BINARY() { REG_VALUE_TYPE type; byte[] value; - _Reg_QueryValue(m_key.m_hkey, m_name, value, type); + Reg_QueryValue_(m_key.m_hkey, m_name, value, type); if(type != m_type) { @@ -1727,19 +1600,19 @@ public class Registry private: static this() { - sm_keyClassesRoot = new Key( _Reg_Dup(HKEY_CLASSES_ROOT) + sm_keyClassesRoot = new Key( Reg_Dup_(HKEY_CLASSES_ROOT) , "HKEY_CLASSES_ROOT", false); - sm_keyCurrentUser = new Key( _Reg_Dup(HKEY_CURRENT_USER) + sm_keyCurrentUser = new Key( Reg_Dup_(HKEY_CURRENT_USER) , "HKEY_CURRENT_USER", false); - sm_keyLocalMachine = new Key( _Reg_Dup(HKEY_LOCAL_MACHINE) + sm_keyLocalMachine = new Key( Reg_Dup_(HKEY_LOCAL_MACHINE) , "HKEY_LOCAL_MACHINE", false); - sm_keyUsers = new Key( _Reg_Dup(HKEY_USERS) + sm_keyUsers = new Key( Reg_Dup_(HKEY_USERS) , "HKEY_USERS", false); - sm_keyPerformanceData = new Key( _Reg_Dup(HKEY_PERFORMANCE_DATA) + sm_keyPerformanceData = new Key( Reg_Dup_(HKEY_PERFORMANCE_DATA) , "HKEY_PERFORMANCE_DATA", false); - sm_keyCurrentConfig = new Key( _Reg_Dup(HKEY_CURRENT_CONFIG) + sm_keyCurrentConfig = new Key( Reg_Dup_(HKEY_CURRENT_CONFIG) , "HKEY_CURRENT_CONFIG", false); - sm_keyDynData = new Key( _Reg_Dup(HKEY_DYN_DATA) + sm_keyDynData = new Key( Reg_Dup_(HKEY_DYN_DATA) , "HKEY_DYN_DATA", false); } @@ -1750,19 +1623,19 @@ private: //@{ public: /// Returns the root key for the HKEY_CLASSES_ROOT hive - static Key ClassesRoot() { return sm_keyClassesRoot; } + static Key classesRoot() { return sm_keyClassesRoot; } /// Returns the root key for the HKEY_CURRENT_USER hive - static Key CurrentUser() { return sm_keyCurrentUser; } + static Key currentUser() { return sm_keyCurrentUser; } /// Returns the root key for the HKEY_LOCAL_MACHINE hive - static Key LocalMachine() { return sm_keyLocalMachine; } + static Key localMachine() { return sm_keyLocalMachine; } /// Returns the root key for the HKEY_USERS hive - static Key Users() { return sm_keyUsers; } + static Key users() { return sm_keyUsers; } /// Returns the root key for the HKEY_PERFORMANCE_DATA hive - static Key PerformanceData() { return sm_keyPerformanceData; } + static Key performanceData() { return sm_keyPerformanceData; } /// Returns the root key for the HKEY_CURRENT_CONFIG hive - static Key CurrentConfig() { return sm_keyCurrentConfig; } + static Key currentConfig() { return sm_keyCurrentConfig; } /// Returns the root key for the HKEY_DYN_DATA hive - static Key DynData() { return sm_keyDynData; } + static Key dynData() { return sm_keyDynData; } //@} private: @@ -1816,9 +1689,9 @@ private: ///@{ public: /// The number of keys - uint Count() + uint count() { - return m_key.KeyCount(); + return m_key.keyCount(); } /// The name of the key at the given index @@ -1826,18 +1699,18 @@ public: /// \param index The 0-based index of the key to retrieve /// \return The name of the key corresponding to the given index /// \note Throws a RegistryException if no corresponding key is retrieved - char[] GetKeyName(uint index) + char[] getKeyName(uint index) { DWORD cSubKeys; DWORD cchSubKeyMaxLen; HKEY hkey = m_key.m_hkey; - LONG res = _Reg_GetNumSubKeys(hkey, cSubKeys, cchSubKeyMaxLen); + LONG res = Reg_GetNumSubKeys_(hkey, cSubKeys, cchSubKeyMaxLen); char[] sName = new char[1 + cchSubKeyMaxLen]; DWORD cchName; assert(ERROR_SUCCESS == res); - res = _Reg_EnumKeyName(hkey, index, sName, cchName); + res = Reg_EnumKeyName_(hkey, index, sName, cchName); assert(ERROR_MORE_DATA != res); @@ -1856,7 +1729,7 @@ public: /// \note Throws a RegistryException if no corresponding key is retrieved char[] opIndex(uint index) { - return GetKeyName(index); + return getKeyName(index); } ///@} @@ -1867,7 +1740,7 @@ public: HKEY hkey = m_key.m_hkey; DWORD cSubKeys; DWORD cchSubKeyMaxLen; - LONG res = _Reg_GetNumSubKeys(hkey, cSubKeys, cchSubKeyMaxLen); + LONG res = Reg_GetNumSubKeys_(hkey, cSubKeys, cchSubKeyMaxLen); char[] sName = new char[1 + cchSubKeyMaxLen]; assert(ERROR_SUCCESS == res); @@ -1875,7 +1748,7 @@ public: for(DWORD index = 0; 0 == result; ++index) { DWORD cchName; - LONG res = _Reg_EnumKeyName(hkey, index, sName, cchName); + LONG res = Reg_EnumKeyName_(hkey, index, sName, cchName); assert(ERROR_MORE_DATA != res); @@ -1949,9 +1822,9 @@ private: ///@{ public: /// The number of keys - uint Count() + uint count() { - return m_key.KeyCount(); + return m_key.keyCount(); } /// The key at the given index @@ -1959,18 +1832,18 @@ public: /// \param index The 0-based index of the key to retrieve /// \return The key corresponding to the given index /// \note Throws a RegistryException if no corresponding key is retrieved - Key GetKey(uint index) + Key getKey(uint index) { DWORD cSubKeys; DWORD cchSubKeyMaxLen; HKEY hkey = m_key.m_hkey; - LONG res = _Reg_GetNumSubKeys(hkey, cSubKeys, cchSubKeyMaxLen); + LONG res = Reg_GetNumSubKeys_(hkey, cSubKeys, cchSubKeyMaxLen); char[] sName = new char[1 + cchSubKeyMaxLen]; DWORD cchName; assert(ERROR_SUCCESS == res); - res = _Reg_EnumKeyName(hkey, index, sName, cchName); + res = Reg_EnumKeyName_(hkey, index, sName, cchName); assert(ERROR_MORE_DATA != res); @@ -1979,7 +1852,7 @@ public: throw new RegistryException("Invalid key", res); } - return m_key.GetKey(sName[0 .. cchName]); + return m_key.getKey(sName[0 .. cchName]); } /// The key at the given index @@ -1989,7 +1862,7 @@ public: /// \note Throws a RegistryException if no corresponding key is retrieved Key opIndex(uint index) { - return GetKey(index); + return getKey(index); } ///@} @@ -2000,7 +1873,7 @@ public: HKEY hkey = m_key.m_hkey; DWORD cSubKeys; DWORD cchSubKeyMaxLen; - LONG res = _Reg_GetNumSubKeys(hkey, cSubKeys, cchSubKeyMaxLen); + LONG res = Reg_GetNumSubKeys_(hkey, cSubKeys, cchSubKeyMaxLen); char[] sName = new char[1 + cchSubKeyMaxLen]; assert(ERROR_SUCCESS == res); @@ -2008,7 +1881,7 @@ public: for(DWORD index = 0; 0 == result; ++index) { DWORD cchName; - LONG res = _Reg_EnumKeyName(hkey, index, sName, cchName); + LONG res = Reg_EnumKeyName_(hkey, index, sName, cchName); assert(ERROR_MORE_DATA != res); @@ -2022,7 +1895,7 @@ public: { try { - Key key = m_key.GetKey(sName[0 .. cchName]); + Key key = m_key.getKey(sName[0 .. cchName]); result = dg(key); } @@ -2030,7 +1903,7 @@ public: { // Skip inaccessible keys; they are // accessible via the KeyNameSequence - if(x.Error == ERROR_ACCESS_DENIED) + if(x.error == ERROR_ACCESS_DENIED) { continue; } @@ -2095,9 +1968,9 @@ private: ///@{ public: /// The number of values - uint Count() + uint count() { - return m_key.ValueCount(); + return m_key.valueCount(); } /// The name of the value at the given index @@ -2105,18 +1978,18 @@ public: /// \param index The 0-based index of the value to retrieve /// \return The name of the value corresponding to the given index /// \note Throws a RegistryException if no corresponding value is retrieved - char[] GetValueName(uint index) + char[] getValueName(uint index) { DWORD cValues; DWORD cchValueMaxLen; HKEY hkey = m_key.m_hkey; - LONG res = _Reg_GetNumValues(hkey, cValues, cchValueMaxLen); + LONG res = Reg_GetNumValues_(hkey, cValues, cchValueMaxLen); char[] sName = new char[1 + cchValueMaxLen]; DWORD cchName = 1 + cchValueMaxLen; assert(ERROR_SUCCESS == res); - res = _Reg_EnumValueName(hkey, index, sName, cchName); + res = Reg_EnumValueName_(hkey, index, sName, cchName); if(ERROR_SUCCESS != res) { @@ -2133,7 +2006,7 @@ public: /// \note Throws a RegistryException if no corresponding value is retrieved char[] opIndex(uint index) { - return GetValueName(index); + return getValueName(index); } ///@} @@ -2144,7 +2017,7 @@ public: HKEY hkey = m_key.m_hkey; DWORD cValues; DWORD cchValueMaxLen; - LONG res = _Reg_GetNumValues(hkey, cValues, cchValueMaxLen); + LONG res = Reg_GetNumValues_(hkey, cValues, cchValueMaxLen); char[] sName = new char[1 + cchValueMaxLen]; assert(ERROR_SUCCESS == res); @@ -2152,7 +2025,7 @@ public: for(DWORD index = 0; 0 == result; ++index) { DWORD cchName = 1 + cchValueMaxLen; - LONG res = _Reg_EnumValueName(hkey, index, sName, cchName); + LONG res = Reg_EnumValueName_(hkey, index, sName, cchName); if(ERROR_NO_MORE_ITEMS == res) { @@ -2222,9 +2095,9 @@ private: ///@{ public: /// The number of values - uint Count() + uint count() { - return m_key.ValueCount(); + return m_key.valueCount(); } /// The value at the given index @@ -2232,25 +2105,25 @@ public: /// \param index The 0-based index of the value to retrieve /// \return The value corresponding to the given index /// \note Throws a RegistryException if no corresponding value is retrieved - Value GetValue(uint index) + Value getValue(uint index) { DWORD cValues; DWORD cchValueMaxLen; HKEY hkey = m_key.m_hkey; - LONG res = _Reg_GetNumValues(hkey, cValues, cchValueMaxLen); + LONG res = Reg_GetNumValues_(hkey, cValues, cchValueMaxLen); char[] sName = new char[1 + cchValueMaxLen]; DWORD cchName = 1 + cchValueMaxLen; assert(ERROR_SUCCESS == res); - res = _Reg_EnumValueName(hkey, index, sName, cchName); + res = Reg_EnumValueName_(hkey, index, sName, cchName); if(ERROR_SUCCESS != res) { throw new RegistryException("Invalid value", res); } - return m_key.GetValue(sName[0 .. cchName]); + return m_key.getValue(sName[0 .. cchName]); } /// The value at the given index @@ -2260,7 +2133,7 @@ public: /// \note Throws a RegistryException if no corresponding value is retrieved Value opIndex(uint index) { - return GetValue(index); + return getValue(index); } ///@} @@ -2271,7 +2144,7 @@ public: HKEY hkey = m_key.m_hkey; DWORD cValues; DWORD cchValueMaxLen; - LONG res = _Reg_GetNumValues(hkey, cValues, cchValueMaxLen); + LONG res = Reg_GetNumValues_(hkey, cValues, cchValueMaxLen); char[] sName = new char[1 + cchValueMaxLen]; assert(ERROR_SUCCESS == res); @@ -2279,7 +2152,7 @@ public: for(DWORD index = 0; 0 == result; ++index) { DWORD cchName = 1 + cchValueMaxLen; - LONG res = _Reg_EnumValueName(hkey, index, sName, cchName); + LONG res = Reg_EnumValueName_(hkey, index, sName, cchName); if(ERROR_NO_MORE_ITEMS == res) { @@ -2288,7 +2161,7 @@ public: } else if(ERROR_SUCCESS == res) { - Value value = m_key.GetValue(sName[0 .. cchName]); + Value value = m_key.getValue(sName[0 .. cchName]); result = dg(value); } @@ -2312,17 +2185,17 @@ private: unittest { - Key HKCR = Registry.ClassesRoot; - Key CLSID = HKCR.GetKey("CLSID"); + Key HKCR = Registry.classesRoot; + Key CLSID = HKCR.getKey("CLSID"); -// foreach(Key key; CLSID.Keys) // Still cannot use a property as a freachable quantity without calling the prop function - foreach(Key key; CLSID.Keys()) - { -// foreach(Value val; key.Values) // Still cannot use a property as a freachable quantity without calling the prop function - foreach(Value val; key.Values()) - { - } - } +// foreach(Key key; CLSID.keys) // Still cannot use a property as a freachable quantity without calling the prop function + foreach(Key key; CLSID.keys()) + { +// foreach(Value val; key.Values) // Still cannot use a property as a freachable quantity without calling the prop function + foreach(Value val; key.values()) + { + } + } } /* ////////////////////////////////////////////////////////////////////////// */ diff --git a/std/zip.d b/std/zip.d index 6d68f6b67..811bb34fb 100644 --- a/std/zip.d +++ b/std/zip.d @@ -150,7 +150,7 @@ class ZipArchive foreach (ArchiveMember de; directory) { de.offset = i; - data[i .. i + 4] = (ubyte[])"PK\x03\x04"; + data[i .. i + 4] = cast(ubyte[])"PK\x03\x04"; putUshort(i + 4, de.extractVersion); putUshort(i + 6, de.flags); putUshort(i + 8, de.compressionMethod); @@ -175,7 +175,7 @@ class ZipArchive numEntries = 0; foreach (ArchiveMember de; directory) { - data[i .. i + 4] = (ubyte[])"PK\x01\x02"; + data[i .. i + 4] = cast(ubyte[])"PK\x01\x02"; putUshort(i + 4, de.madeVersion); putUshort(i + 6, de.extractVersion); putUshort(i + 8, de.flags); @@ -205,7 +205,7 @@ class ZipArchive // Write end record endrecOffset = i; - data[i .. i + 4] = (ubyte[])"PK\x05\x06"; + data[i .. i + 4] = cast(ubyte[])"PK\x05\x06"; putUshort(i + 4, diskNumber); putUshort(i + 6, diskStartDir); putUshort(i + 8, numEntries); @@ -245,7 +245,7 @@ class ZipArchive if (i < iend) throw new ZipException("no end record"); - if (data[i .. i + 4] == (ubyte[])"PK\x05\x06") + if (data[i .. i + 4] == cast(ubyte[])"PK\x05\x06") { endcommentlength = getUshort(i + 20); if (i + 22 + endcommentlength > data.length) @@ -288,7 +288,7 @@ class ZipArchive uint extralen; uint commentlen; - if (data[i .. i + 4] != (ubyte[])"PK\x01\x02") + if (data[i .. i + 4] != cast(ubyte[])"PK\x01\x02") throw new ZipException("invalid directory entry 1"); ArchiveMember de = new ArchiveMember(); de.madeVersion = getUshort(i + 4); @@ -328,7 +328,7 @@ class ZipArchive { uint namelen; uint extralen; - if (data[de.offset .. de.offset + 4] != (ubyte[])"PK\x03\x04") + if (data[de.offset .. de.offset + 4] != cast(ubyte[])"PK\x03\x04") throw new ZipException("invalid directory entry 4"); // These values should match what is in the main zip archive directory @@ -385,7 +385,7 @@ class ZipArchive { version (LittleEndian) { - return *(ushort *)&data[i]; + return *cast(ushort *)&data[i]; } else { @@ -399,11 +399,11 @@ class ZipArchive { version (LittleEndian) { - return *(uint *)&data[i]; + return *cast(uint *)&data[i]; } else { - return bswap(*(uint *)&data[i]); + return bswap(*cast(uint *)&data[i]); } } @@ -411,7 +411,7 @@ class ZipArchive { version (LittleEndian) { - *(ushort *)&data[i] = us; + *cast(ushort *)&data[i] = us; } else { @@ -426,7 +426,7 @@ class ZipArchive { ui = bswap(ui); } - *(uint *)&data[i] = ui; + *cast(uint *)&data[i] = ui; } } @@ -434,7 +434,7 @@ debug(print) { void arrayPrint(ubyte[] array) { - printf("array %p,%d\n", (void*)array, array.length); + printf("array %p,%d\n", cast(void*)array, array.length); for (int i = 0; i < array.length; i++) { printf("%02x ", array[i]); diff --git a/std/zlib.d b/std/zlib.d index c5e54e021..d14eeae13 100644 --- a/std/zlib.d +++ b/std/zlib.d @@ -49,7 +49,7 @@ class ZlibException : Exception uint adler32(uint adler, void[] buf) { - return etc.c.zlib.adler32(adler, (ubyte *)buf, buf.length); + return etc.c.zlib.adler32(adler, cast(ubyte *)buf, buf.length); } unittest @@ -59,7 +59,7 @@ unittest uint adler; debug(zlib) printf("D.zlib.adler32.unittest\n"); - adler = adler32(0u, (void[])data); + adler = adler32(0u, cast(void[])data); debug(zlib) printf("adler = %x\n", adler); assert(adler == 0xdc0037); } @@ -69,7 +69,7 @@ unittest uint crc32(uint crc, void[] buf) { - return etc.c.zlib.crc32(crc, (ubyte *)buf, buf.length); + return etc.c.zlib.crc32(crc, cast(ubyte *)buf, buf.length); } unittest @@ -79,7 +79,7 @@ unittest uint crc; debug(zlib) printf("D.zlib.crc32.unittest\n"); - crc = crc32(0u, (void[])data); + crc = crc32(0u, cast(void[])data); debug(zlib) printf("crc = %x\n", crc); assert(crc == 0x2520577b); } @@ -100,7 +100,7 @@ body destlen = srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12; destbuf = new void[destlen]; - err = etc.c.zlib.compress2((ubyte *)destbuf, &destlen, (ubyte *)srcbuf, srcbuf.length, level); + err = etc.c.zlib.compress2(cast(ubyte *)destbuf, &destlen, cast(ubyte *)srcbuf, srcbuf.length, level); if (err) { delete destbuf; throw new ZlibException(err); @@ -145,10 +145,10 @@ void[] uncompress(void[] srcbuf, uint destlen, int winbits) destbuf = new void[destlen]; - zs.next_in = (ubyte*) srcbuf; + zs.next_in = cast(ubyte*) srcbuf; zs.avail_in = srcbuf.length; - zs.next_out = (ubyte*)destbuf; + zs.next_out = cast(ubyte*)destbuf; zs.avail_out = destlen; err = etc.c.zlib.inflateInit2(&zs, winbits); @@ -273,13 +273,13 @@ class Compress } destbuf = new void[zs.avail_in + buf.length]; - zs.next_out = (ubyte*) destbuf; + zs.next_out = cast(ubyte*) destbuf; zs.avail_out = destbuf.length; if (zs.avail_in) buf = cast(void[])zs.next_in[0 .. zs.avail_in] ~ buf; - zs.next_in = (ubyte*) buf; + zs.next_in = cast(ubyte*) buf; zs.avail_in = buf.length; err = deflate(&zs, Z_NO_FLUSH); @@ -310,7 +310,7 @@ class Compress return null; destbuf = new void[zs.avail_in]; - zs.next_out = (ubyte*) destbuf; + zs.next_out = cast(ubyte*) destbuf; zs.avail_out = destbuf.length; err = deflate(&zs, mode); @@ -321,7 +321,7 @@ class Compress err = Z_BUF_ERROR; error(err); } - destbuf = (void[])(((ubyte *)destbuf)[0 .. zs.next_out - (ubyte*)destbuf]); + destbuf = cast(void[])((cast(ubyte *)destbuf)[0 .. zs.next_out - cast(ubyte*)destbuf]); if (mode == Z_FINISH) { err = deflateEnd(&zs); @@ -396,13 +396,13 @@ class UnCompress if (!destbufsize) destbufsize = buf.length * 2; destbuf = new void[zs.avail_in * 2 + destbufsize]; - zs.next_out = (ubyte*) destbuf; + zs.next_out = cast(ubyte*) destbuf; zs.avail_out = destbuf.length; if (zs.avail_in) buf = cast(void[])zs.next_in[0 .. zs.avail_in] ~ buf; - zs.next_in = (ubyte*) buf; + zs.next_in = cast(ubyte*) buf; zs.avail_in = buf.length; err = inflate(&zs, Z_NO_FLUSH); @@ -435,7 +435,7 @@ class UnCompress L1: destbuf = new void[zs.avail_in * 2 + 100]; - zs.next_out = (ubyte*) destbuf; + zs.next_out = cast(ubyte*) destbuf; zs.avail_out = destbuf.length; err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH); @@ -451,7 +451,7 @@ class UnCompress err = Z_BUF_ERROR; error(err); } - destbuf = (void[])(((ubyte*)destbuf)[0 .. zs.next_out - (ubyte*)destbuf]); + destbuf = cast(void[])((cast(ubyte*)destbuf)[0 .. zs.next_out - cast(ubyte*)destbuf]); err = etc.c.zlib.inflateEnd(&zs); inited = 0; if (err) diff --git a/unittest.d b/unittest.d index fc4cbdbaa..c028b99d3 100644 --- a/unittest.d +++ b/unittest.d @@ -46,7 +46,7 @@ printf("test2\n"); a.sort; // qsort std.date.getUTCtime(); // date StreamError se = new StreamError(""); // stream - isValidDchar((dchar)0); // utf + isValidDchar(cast(dchar)0); // utf std.uri.ascii2hex(0); // uri std.zlib.adler32(0,null); // D.zlib @@ -62,7 +62,7 @@ printf("test2\n"); printf("hello world\n"); printf("args.length = %d\n", args.length); for (int i = 0; i < args.length; i++) - printf("args[%d] = '%s'\n", i, (char *)args[i]); + printf("args[%d] = '%s'\n", i, cast(char *)args[i]); printf("Success\n!"); return 0; } diff --git a/win32.mak b/win32.mak index 6b70bd7ed..56fc06ec5 100644 --- a/win32.mak +++ b/win32.mak @@ -61,7 +61,7 @@ OBJS= asserterror.obj deh.obj switch.obj complex.obj gcstats.obj \ qsort.obj math2.obj date.obj dateparse.obj thread.obj obj.obj \ iunknown.obj crc32.obj conv.obj arraycast.obj utf.obj uri.obj \ Czlib.obj Dzlib.obj zip.obj process.obj registry.obj recls.obj \ - socket.obj socketstream.obj loader.obj \ + socket.obj socketstream.obj loader.obj stdarg.obj \ ti_Aa.obj ti_Ag.obj ti_C.obj ti_int.obj ti_char.obj \ ti_wchar.obj ti_uint.obj ti_short.obj ti_ushort.obj \ ti_byte.obj ti_ubyte.obj ti_long.obj ti_ulong.obj ti_ptr.obj \ @@ -85,7 +85,8 @@ SRC_STD= std\zlib.d std\zip.d std\stdint.d std\conv.d std\utf.d std\uri.d \ std\regexp.d std\random.d std\stream.d std\process.d std\recls.d \ std\socket.d std\socketstream.d std\loader.d -SRC_STD_C= std\c\process.d std\c\stdlib.d std\c\time.d std\c\stdio.d std\c\math.d +SRC_STD_C= std\c\process.d std\c\stdlib.d std\c\time.d std\c\stdio.d \ + std\c\math.d std\c\stdarg.d SRC_TI= \ std\typeinfo\ti_wchar.d std\typeinfo\ti_uint.d \ @@ -416,6 +417,11 @@ iunknown.obj : std\windows\iunknown.d registry.obj : std\windows\registry.d $(DMD) -c $(DFLAGS) std\windows\registry.d +### std\c + +stdarg.obj : std\c\stdarg.d + $(DMD) -c $(DFLAGS) std\c\stdarg.d + ### etc ### etc\c