namespace com;
+// #define DISABLE_MEMMGR
+
import "BinaryTree"
import "OldList"
import "String"
import "dataTypes"
+//#define JUST_CHECK_LEAKS
+//#define JUST_CHECK_BOUNDARIES
+
+
#if defined(ECERE_BOOTSTRAP) || defined(ECERE_STATIC)
#define dllexport
#if !defined(ECERE_BOOTSTRAP)
#endif
// #define MEMINFO
+/*
+#ifdef MEMINFO
+ #undef REDZONE
+ #define REDZONE 256
+#endif
+*/
-// #define REDZONE 256
-#ifndef REDZONE
+#if defined(JUST_CHECK_LEAKS) || !defined(REDZONE)
+#undef REDZONE
#define REDZONE 0
#endif
+
+#ifdef _DEBUG
+// #define MEMTRACKING
+#endif
+
#ifdef MEMINFO
import "Thread"
static define MAX_MEMORY_LOC = 40;
+static define MAX_STACK_FRAMES = 1000;
static class MemStack : BTNode
{
- char * frames[1000];
+ const char * frames[MAX_STACK_FRAMES];
int pos;
bool recurse;
};
default:
#define property _property
-#define bool _bool
-#define uint _uint
-#define true _true
-#define false _false
+
+#if defined(DISABLE_MEMMGR)
+
+#ifndef ECERE_BOOTSTRAP
+# include <malloc.h>
+#endif
+
+#if defined(__WIN32__)
+#ifdef ECERE_BOOTSTRAP
+uintsize _msize(void * p);
+#endif
+
+# define msize _msize
+#else
+#ifdef ECERE_BOOTSTRAP
+uintsize malloc_usable_size(void * p);
+#endif
+
+# define msize malloc_usable_size
+#endif
+
+#endif
#include <stdlib.h>
#include <stdio.h>
#endif
#undef property
-#undef bool
-#undef uint
-#undef true
-#undef false
#undef CompareString
public define null = ((void *)0);
-dllexport Class eSystem_FindClass(Module module, char * name);
+dllexport Class eSystem_FindClass(Module module, const char * name);
dllexport void * eSystem_Renew(void * memory, unsigned int size);
dllexport void * eSystem_Renew0(void * memory, unsigned int size);
dllexport void * eSystem_New(unsigned int size);
extern int __ecereVMethodID_class_OnGetDataFromString;
// IMPLEMENTATION FOR THESE IN _instance.c:
-bool Instance_LocateModule(char * name, char * fileName);
-void Instance_COM_Initialize(int argc, char ** argv, char ** parsedCommand, int * argcPtr, char *** argvPtr);
+#if defined(__MINGW32__) && !defined(_W64) && __GNUC__ < 4
+dllexport int isblank(int c);
+#endif
+bool Instance_LocateModule(const char * name, const char * fileName);
+void Instance_COM_Initialize(int argc, char ** argv, char ** parsedCommand, int * argcPtr, const char *** argvPtr);
void * Instance_Module_Load(const char * libLocation, const char * name, void ** Load, void ** Unload);
void Instance_Module_Free(void * library);
#if defined(_DEBUG)
private:
-public class unichar : uint32
+public class Angle : double;
+
+public class ::unichar : uint32
{
- char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+ const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
UTF32toUTF8Len(&this, 1, tempString, 5);
return tempString;
}
- bool OnGetDataFromString(char * string)
+ bool OnGetDataFromString(const char * string)
{
int nb;
this = UTF8GetChar(string, &nb);
};
+// Forward declarations to hook on to libec:
+class ::Type;
+class ::Instantiation;
+class ::ClassDefinition;
+
public class Property : struct
{
public:
class_fixed
class_no_expansion
Property prev, next;
- char * name;
+ const char * name;
bool isProperty;
AccessMode memberAccess;
int id;
Class _class;
- char * dataTypeString;
+ const char * dataTypeString;
Class dataTypeClass;
Type dataType;
int vid;
bool conversion;
uint watcherOffset;
- char * category;
+ const char * category;
bool compiled;
bool selfWatchable, isWatchable;
};
dllexport void eInstance_FireWatchers(Instance instance, Property _property);
-public dllexport void MemoryGuard_PushLoc(char * loc)
+public dllexport void MemoryGuard_PushLoc(const char * loc)
{
#ifdef MEMINFO
MemStack stack;
stack.key = GetCurrentThreadID();
memStacks.Add(stack);
}
- if(stack.pos < 1000)
+ if(stack.pos < MAX_STACK_FRAMES)
stack.frames[stack.pos++] = loc;
- else
- printf("");
memMutex.Release();
#endif
}
{
stack.pos--;
}
- else
- printf("");
memMutex.Release();
#endif
}
{
class_fixed
public:
- char * name;
+ const char * name;
BTNamedLink parent, left, right;
int depth;
void * data;
{
class_fixed
SelfWatcher prev, next;
- void (*callback)(Instance);
+ void (*callback)(void *);
Property _property;
};
public enum AccessMode
-{
+{
defaultAccess,
publicAccess,
privateAccess,
public:
SubModule prev, next;
Module module;
- AccessMode importMode;
+ AccessMode importMode;
};
public enum DataMemberType { normalMember, unionMember, structMember };
class_fixed
class_no_expansion
Class prev, next;
- char * name;
+ const char * name;
int offset, structSize;
- int (** _vTbl)();
+ void ** _vTbl;
int vTblSize;
- int (*Constructor)(Instance);
- void (*Destructor)(Instance);
+ bool (*Constructor)(void *);
+ void (*Destructor)(void *);
int offsetClass, sizeClass;
Class base;
ClassType type;
Module module;
NameSpace * nameSpace;
- char * dataTypeString;
+ const char * dataTypeString;
Type dataType;
int typeSize;
int defaultAlignment;
void (*Initialize)();
int memberOffset; // For structs, this includes all base classes structSize. Otherwise it restarts at for each class hierarchy level.
OldList selfWatchers;
- char * designerClass;
+ const char * designerClass;
bool noExpansion;
- char * defaultProperty;
+ const char * defaultProperty;
bool comRedefinition;
int count; // DEBUGGING
- bool isRemote;
+ int isRemote; // TODO: Convert to an enum, can have values 0..3
bool internalDecl;
void * data;
bool computeSize;
- int structAlignment;
+ short structAlignment; short pointerAlignment;
int destructionWatchOffset;
bool fixed;
OldList delayedCPValues;
AccessMode inheritanceAccess;
- char * fullName;
+ const char * fullName;
void * symbol;
OldList conversions;
ClassTemplateArgument * templateArgs;
Class templateClass;
OldList templatized;
- int numParams;
+ int numParams; // TOTAL number of params including all base classes; use templateParams.count for this level
+ bool isInstanceClass;
+ bool byValueSystemClass;
- property char *
+ property const char *
{
get { return name; }
set
- {
+ {
Class theClass = eSystem_FindClass(__thisModule, value);
/*
if(!theClass)
}
};
- char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+ const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
return name;
}
- bool OnGetDataFromString(char * string)
+ bool OnGetDataFromString(const char * string)
{
Class theClass;
theClass = eSystem_FindClass(__thisModule, string);
// For type
struct
{
- char * dataTypeString;
+ const char * dataTypeString;
Class dataTypeClass;
// Type dataType;
};
// For identifier
struct
{
- char * memberString;
+ const char * memberString;
union
{
DataMember member;
class_fixed
public:
ClassTemplateParameter prev, next;
- char * name;
+ const char * name;
TemplateParameterType type;
union
{
// Class baseClass; // For type
- char * dataTypeString; // For expression
+ const char * dataTypeString; // For expression
TemplateMemberType memberType; // For identifier
};
ClassTemplateArgument defaultArg;
OldList modules;
Module prev, next;
- char * name;
+ const char * name;
void * library;
void (stdcall * Unload)(Module module);
ImportType importType;
public class Application : Module
{
int argc;
- char ** argv;
+ const char ** argv;
int exitCode;
bool isGUIApp;
OldList allModules;
- char * parsedCommand;
+ const char * parsedCommand;
NameSpace systemNameSpace;
};
*/
{
public:
class_fixed
- char * name;
+ const char * name;
Method parent, left, right;
int depth;
int (*function)();
MethodType type;
Class _class;
void * symbol;
- char * dataTypeString;
+ const char * dataTypeString;
Type dataType;
AccessMode memberAccess;
};
public struct NameSpace
{
- char * name;
+ const char * name;
NameSpace * btParent, * left, * right;
int depth;
public:
class_fixed
DataMember prev, next;
- char * name;
+ const char * name;
bool isProperty;
AccessMode memberAccess;
int id;
Class _class;
- char * dataTypeString;
+ const char * dataTypeString;
Class dataTypeClass;
Type dataType;
OldList members;
BinaryTree membersAlpha;
int memberOffset;
- int structAlignment;
+ short structAlignment; short pointerAlignment;
};
public class BitMember : struct
public:
class_fixed
BitMember prev, next;
- char * name;
+ const char * name;
bool isProperty;
AccessMode memberAccess;
int id;
Class _class;
- char * dataTypeString;
+ const char * dataTypeString;
Class dataTypeClass;
Type dataType;
{
public:
class_fixed
- char * name;
+ const char * name;
ClassProperty parent, left, right;
int depth;
void (*Set)(Class, int64);
int64 (*Get)(Class);
- char * dataTypeString;
+ const char * dataTypeString;
Type dataType;
bool constant;
};
public:
class_fixed
DefinedExpression prev, next;
- char * name;
- char * value;
+ const char * name;
+ const char * value;
NameSpace * nameSpace;
};
public:
class_fixed
GlobalFunction prev, next;
- char * name;
+ const char * name;
int (*function)();
Module module;
NameSpace * nameSpace;
- char * dataTypeString;
+ const char * dataTypeString;
Type dataType;
void * symbol;
};
-public class EnumClassData : struct
+public class EnumClassData : struct
{
public:
class_fixed
OldList values;
- int largest;
+ int64 largest;
};
class Watcher : struct
{
class_fixed
Watcher prev, next;
- void (*callback)(Instance, Instance);
+ void (*callback)(void *, void *);
Instance object;
};
byte * oldmem;
uint size;
bool freed;
- char * _class;
+ const char * _class;
uint id;
char * allocLoc[MAX_MEMORY_LOC];
char * freeLoc[MAX_MEMORY_LOC];
printf("Object of class %s\n", _class);
printf(" Allocation Stack:\n");
for(c = 0; c<MAX_MEMORY_LOC; c++)
+#if (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__)
+ if(allocLoc[c] && allocLoc[c] != (void *)0xabababababababab)
+#else
if(allocLoc[c] && allocLoc[c] != (void *)0xabababab)
+#endif
printf(" %s\n", allocLoc[c]);
if(showFree)
#endif
static uint TOTAL_MEM = 0;
+#if !defined(MEMINFO) && !defined(DISABLE_MEMMGR)
static uint OUTSIDE_MEM = 0;
+#endif
#if !defined(ECERE_BOOTSTRAP)
static Mutex memMutex { };
MemBlock prev, next;
MemPart part;
uint size;
+#if !defined(MEMINFO) && defined(MEMTRACKING)
+ Class _class;
+#endif
};
private class MemPart : struct
#define SIZE_POSITION(s) log1_5i(s)
#define NTH_SIZE(p) pow1_5(p)
+#if 0
static int power15[] =
{
/*
466624,
699920
};
+#endif
private struct BlockPool
{
{
int c;
#ifdef _DEBUG
- uint totalAvailable = 0, totalAllocated = 0, totalBlocks = 0, totalUsed = 0;
- uint totalParts = 0;
+ /*uint totalAvailable = 0, totalAllocated = 0, totalBlocks = 0, totalUsed = 0;
+ uint totalParts = 0;*/
#endif
MemBlock block = (MemBlock)memory;
MemPart part = calloc(1, sizeof(class MemPart));
{
BlockPool * pool = &pools[c];
printf("[%d %s (%d)]: available: %d, allocated: %d, free: %d, used: %d k, wasted: %d k, free: %d k\n", c, (&pools[c] == this) ? "*" : " ",
- pools[c].blockSize, pools[c].totalSize, pools[c].numBlocks,
+ pools[c].blockSize, pools[c].totalSize, pools[c].numBlocks,
pools[c].totalSize - pools[c].numBlocks, pools[c].usedSpace / 1024, ((pools[c].numBlocks * pools[c].blockSize) - pools[c].usedSpace) / 1024,
(pools[c].totalSize - pools[c].numBlocks) * pools[c].blockSize / 1024);
totalAvailable += pools[c].totalSize * pools[c].blockSize;
last = block;
free = block.next;
/*if(blockSize == 28)
- printf("Free: %x, free.part: %x, free.part.size: %d, free.part.pool: %x (this = %x), next = %x (part = %x)\n", free, free ? free.part : null,
- (free && free.part) ? free.part.size : 0, (free && free.part) ? free.part.pool : 0, this,
+ printf("Free: %x, free.part: %x, free.part.size: %d, free.part.pool: %x (this = %x), next = %x (part = %x)\n", free, free ? free.part : null,
+ (free && free.part) ? free.part.size : 0, (free && free.part) ? free.part.pool : 0, this,
(free ? free.next : 0), (free && free.next) ? free.next.part : 0);
if(free && free.part && (free.part.size < 0 || free.part.pool == (void *)-1))
printf("WARNING! Bad next free block!\n");*/
void Remove(MemBlock block)
{
+ MemPart part = block.part;
/*if(blockSize == 28)
printf("BlockPool::Remove (%d)\n", blockSize);*/
if(block.prev)
first = block.next;
if(last == block)
last = block.prev;
-
+
// block.prev = null;
block.next = free;
free = block;
printf("Setting new free block: part = %x\n", block.part);
}*/
- block.part.blocksUsed--;
+ part.blocksUsed--;
numBlocks--;
- block.part.pool->usedSpace -= block.size;
+ part.pool->usedSpace -= block.size;
- if(!block.part.blocksUsed && numBlocks && totalSize > numBlocks + numBlocks / 2)
+ if(!part.blocksUsed && numBlocks && totalSize > numBlocks + numBlocks / 2)
{
MemBlock next = free, prev = null;
- MemPart part = block.part;
free = null;
totalSize -= part.size;
/*if(blockSize == 28)
};
if(prev)
prev.next = null;
-
+
TOTAL_MEM -= part.size * blockSpace;
TOTAL_MEM -= sizeof(class MemPart);
numParts--;
}
};
+#if !defined(MEMINFO) && !defined(DISABLE_MEMMGR)
static BlockPool * pools; //[NUM_POOLS];
-static uint PosFibonacci(uint number)
+/*static uint PosFibonacci(uint number)
{
uint pos;
uint last = 1, prev = 0;
uint current = 1;
-
+
for(pos=0; ; pos++)
{
current += prev;
uint pos;
uint last = 1, prev = 0;
uint current = 1;
-
+
for(pos=0; pos <= number; pos++)
{
current += prev;
uint pos;
uint last = 1, prev = 0;
uint current = 1;
-
+
for(pos=0; ; pos++)
{
current += prev;
return current;
}
}
+*/
static uint log1_5i(uint number)
{
uint pos;
uint64 current = sizeof(void *);
-
+
for(pos=0; pos < NUM_POOLS; pos++)
{
if(current >= number)
break;
current = current * 3 / 2;
if(current == 1) current = 2;
+ if(current & 7) current += 8 - (current & 7);
}
return pos;
}
{
current = current * 3 / 2;
if(current == 1) current = 2;
+ if(current & 7) current += 8 - (current & 7);
}
return (uint)current;
}
{
uint pos;
uint64 current = sizeof(void *);
-
+
for(pos=0; pos < NUM_POOLS; pos++)
{
if(current >= number)
return (uint)current;
current = current * 3 / 2;
if(current == 1) current = 2;
+ if(current & 7) current += 8 - (current & 7);
}
return (uint)current;
-}
+}
+#endif
// -- Math Helpers ---
public uint log2i(uint number)
return 1<<log2i(number);
}
+#if !defined(MEMINFO) && !defined(DISABLE_MEMMGR)
static bool memoryInitialized = false;
static void InitMemory()
{
for(c = 0; c<NUM_POOLS; c++)
{
int expansion;
-
+
pools[c].blockSize = NTH_SIZE(c);
if(pools[c].blockSize % sizeof(void *))
pools[c].blockSize += sizeof(void *) - (pools[c].blockSize % sizeof(void *));
pools[c].blockSpace = pools[c].blockSize;
- pools[c].blockSpace += sizeof(class MemBlock);
+ pools[c].blockSpace += sizeof(class MemBlock);
// pools[c].Expand(initNumBlocks[c]);
-
+
expansion = (pools[c].blockSize < 128) ? 1024 : (131072 / pools[c].blockSize);
if(c < 12)
pools[c].Expand(Max(1, expansion));
}
}
+#endif
+#if !defined(MEMINFO) && !defined(DISABLE_MEMMGR)
static void * _mymalloc(unsigned int size)
{
MemBlock block = null;
{
unsigned int p = SIZE_POSITION(size);
if(!memoryInitialized) InitMemory();
- if(p < NUM_POOLS)
+ if(!poolingDisabled && p < NUM_POOLS)
{
block = pools[p].Add();
if(block)
{
+#if defined(MEMTRACKING)
+ block._class = null;
+#endif
block.size = size;
pools[p].usedSpace += size;
}
TOTAL_MEM += sizeof(class MemBlock) + size;
OUTSIDE_MEM += sizeof(class MemBlock) + size;
block.part = null;
+#if defined(MEMTRACKING)
+ block._class = null;
+#endif
block.size = size;
}
}
return pointer;
}
+
static void _myfree(void * pointer)
{
if(pointer)
TOTAL_MEM += size - newBlock.size;
OUTSIDE_MEM += size - newBlock.size;
newPointer = ((struct MemBlock *)newBlock + 1);
+ newBlock.size = size;
}
}
}
return newPointer;
}
-#ifndef MEMINFO
#undef realloc
#undef crealloc
#undef malloc
static void * _malloc(unsigned int size)
{
+#if defined(DISABLE_MEMMGR) && !defined(MEMINFO)
+ return size ? malloc(size) : null;
+#else
void * pointer;
+
#if !defined(ECERE_BOOTSTRAP)
memMutex.Wait();
#endif
}
#endif
return pointer ? ((byte*)pointer + REDZONE) : null;
+#endif
}
static void * _calloc(int n, unsigned int size)
{
+#if defined(DISABLE_MEMMGR) && !defined(MEMINFO)
+ return size ? calloc(n, size) : null;
+#else
void * pointer;
+
#if !defined(ECERE_BOOTSTRAP)
memMutex.Wait();
#endif
MemInfo block;
stack.recurse = true;
- block = MemInfo { (unsigned int)n*size = size, key = (uintptr)((byte *)pointer + REDZONE), _class = allocateClass, internal = allocateInternal, id = blockID++ };
+ block = MemInfo { size = (unsigned int)n*size, key = (uintptr)((byte *)pointer + REDZONE), _class = allocateClass, internal = allocateInternal, id = blockID++ };
memcpy(block.allocLoc, stack.frames + stack.pos - Min(stack.pos, MAX_MEMORY_LOC), Min(stack.pos, MAX_MEMORY_LOC) * sizeof(char *));
memBlocks.Add(block);
stack.recurse = false;
}
}
-}
#endif
#if !defined(ECERE_BOOTSTRAP)
}
#endif
return pointer ? ((byte*)pointer + REDZONE) : null;
+#endif
}
static void * _realloc(void * pointer, unsigned int size)
{
+#if defined(DISABLE_MEMMGR) && !defined(MEMINFO)
+ if(!size) { free(pointer); return null; }
+ return realloc(pointer, size);
+
+#else
if(!size) { _free(pointer); return null; }
+
#if !defined(ECERE_BOOTSTRAP)
memMutex.Wait();
#endif
block.OutputStacks(true);
}
}
-
+
pointer = malloc(size + REDZONE * 2);
if(!pointer)
{
if(block)
{
+#if defined(JUST_CHECK_LEAKS) || defined(JUST_CHECK_BOUNDARIES)
+ memcpy((byte *)pointer + REDZONE, (byte *)block.key, Min(block.size, size));
+ free((byte *)block.key - REDZONE);
+ memBlocks.Remove(block);
+ free(block);
+#else
if(block.freed)
{
memcpy((byte *)pointer + REDZONE, block.oldmem, Min(block.size, size));
memset((byte *)block.key - REDZONE, 0xEC, block.size + REDZONE * 2);
block.freed = true;
}
+#endif
}
if(!recurse && !stack.recurse)
memMutex.Release();
#endif
return pointer ? ((byte *)pointer + REDZONE) : null;
+#endif
}
static void * _crealloc(void * pointer, unsigned int size)
{
- if(!size) return null;
+#if defined(DISABLE_MEMMGR) && !defined(MEMINFO)
+ uintsize s = pointer ? msize(pointer) : 0;
+ void * p;
+ if(!size) { free(pointer); return null; }
+
+ p = realloc(pointer, size);
+ if(size > s)
+ memset((byte *)p + s, 0, size - s);
+ return p;
+#else
+ if(!size) { _free(pointer); return null; }
+
#if !defined(ECERE_BOOTSTRAP)
memMutex.Wait();
#endif
block.OutputStacks(true);
}
}
-
+
pointer = calloc(1, size + REDZONE * 2);
if(!pointer)
{
if(block)
{
+#if defined(JUST_CHECK_LEAKS) || defined(JUST_CHECK_BOUNDARIES)
+ memcpy((byte *)pointer + REDZONE, (byte *)block.key, Min(block.size, size));
+ free((byte *)block.key - REDZONE);
+ memBlocks.Remove(block);
+ free(block);
+#else
if(block.freed)
{
memcpy((byte *)pointer + REDZONE, block.oldmem, Min(block.size, size));
memset((byte *)block.key - REDZONE, 0xEC, block.size + REDZONE * 2);
block.freed = true;
}
+#endif
}
if(!recurse && !stack.recurse)
memMutex.Release();
#endif
return pointer ? ((byte *)pointer + REDZONE) : null;
+#endif
}
static void _free(void * pointer)
{
if(pointer)
{
+#if defined(DISABLE_MEMMGR) && !defined(MEMINFO)
+ free(pointer);
+#else
#if !defined(ECERE_BOOTSTRAP)
if(memMutex != pointer) memMutex.Wait();
#endif
{
if(address[-c-1] != 0xAB)
{
- printf("Buffer Underrun\n");
+ printf("Buffer Underrun (%d bytes before)\n", c+1);
memoryErrorsCount++;
block.OutputStacks(block.freed);
}
if(address[c + size] != 0xAB)
{
- printf("Buffer Overrun\n");
+ printf("Buffer Overrun (%d bytes past block)\n", c);
memoryErrorsCount++;
block.OutputStacks(block.freed);
}
}
block.freed = true;
+#if defined(JUST_CHECK_LEAKS) || defined(JUST_CHECK_BOUNDARIES)
+ free((byte *)block.key - REDZONE);
+ memBlocks.Remove(block);
+ free(block);
+#else
block.oldmem = (byte *)malloc(block.size + REDZONE * 2);
if(block.oldmem)
{
memset((byte *)block.key - REDZONE, 0xEC, block.size + REDZONE * 2);
memcpy(block.freeLoc, stack.frames + stack.pos - Min(stack.pos, MAX_MEMORY_LOC), Min(stack.pos, MAX_MEMORY_LOC) * sizeof(char *));
+#endif
}
stack.recurse = false;
}
#if !defined(ECERE_BOOTSTRAP)
if(memMutex != pointer) memMutex.Release();
#endif
+
+#endif
}
}
}
}
+public void CheckConsistency()
+{
+#ifdef MEMINFO
+ if(!memBlocks.Check())
+ printf("Memory Blocks Tree Integrity Failed\n");
+#endif
+}
+
public void CheckMemory()
{
#ifdef MEMINFO
}
}
- while(block = (MemInfo)memBlocks.root)
+ while((block = (MemInfo)memBlocks.root))
{
byte * address;
int c;
block.OutputStacks(true);
}
}
-
+
address = (byte *)block.key;
for(c = 0; c<REDZONE; c++)
{
if(address[-c-1] != 0xAB)
{
- printf("Buffer Underrun\n");
+ printf("Buffer Underrun (%d bytes before)\n", c + 1);
memoryErrorsCount++;
block.OutputStacks(block.freed);
}
if(address[c + size] != 0xAB)
{
- printf("Buffer Overrun\n");
+ printf("Buffer Overrun (%d bytes past)\n", c);
memoryErrorsCount++;
block.OutputStacks(block.freed);
}
}
-
+
memBlocks.Delete(block);
}
if(leaksCount)
printf("Memory Check Completed.\n");
#if defined(__WIN32__) && !defined(ECERE_BOOTSTRAP)
if(memoryErrorsCount)
- getch();
+ system("pause");
#endif
#endif
}
static void FixDerivativesBase(Class base, Class mod)
{
OldLink derivative;
- OldLink templateLink;
ComputeClassParameters(base, strchr(base.name, '<'), null);
{
Class _class = derivative.data;
ClassType type = _class.type;
+ ClassType oldType = type;
int size = _class.structSize - _class.offset;
int oldSizeClass = _class.sizeClass;
int sizeClass = _class.sizeClass - _class.offsetClass;
Class enumBase = null;
- char * dataTypeString = null;
+ const char * dataTypeString = null;
// NOTE: baseClass is class(class)
Class baseClass;
uint offsetBefore = _class.offset;
dataTypeString = enumBase ? enumBase.dataTypeString : base.dataTypeString;
/////////////////////
-
+
offsetClass = base ? (base.templateClass ? base.templateClass.sizeClass : base.sizeClass) : (type == noHeadClass ? 0 : 0 /*sizeof(class Class)*/);
totalSizeClass = offsetClass + sizeClass;
// _class.memberID = _class.startMemberID = (base && (type == normalClass || type == noHeadClass || type == structClass)) ? base.memberID : 0;
if(type == normalClass || type == noHeadClass)
- _class.offset = (base && (base.templateClass ? base.templateClass.structSize : base.structSize) && base.type != systemClass) ? (base.templateClass ? base.templateClass.structSize : base.structSize) : ((type == noHeadClass) ? 0 : sizeof(class Instance));
+ {
+ // Use 'memberOffset' for nohead class as the members get added without padding
+ _class.offset = (base && (base.templateClass ? (type == normalClass ? base.templateClass.structSize : base.templateClass.memberOffset) : (type == normalClass ? base.structSize : base.memberOffset)) && base.type != systemClass) ? (base.templateClass ? base.templateClass.structSize : base.structSize) : ((type == noHeadClass) ? 0 : sizeof(class Instance));
+ if(_class.structAlignment && (_class.offset % _class.structAlignment))
+ _class.offset += _class.structAlignment - _class.offset % _class.structAlignment;
+ }
+ else
+ _class.offset = 0; // Force set to 0
if(type == structClass)
{
_class.typeSize = _class.structSize = _class.memberOffset + size;
}
else if(type == bitClass || type == enumClass || type == unitClass)
- {
+ {
Class dataTypeClass = eSystem_FindClass(_class.module, dataTypeString);
if(dataTypeClass)
_class.typeSize = dataTypeClass.typeSize;
if(_class.type != systemClass)
_class.type = type;
- delete _class.dataTypeString;
+ delete (void *)_class.dataTypeString;
_class.dataTypeString = CopyString(dataTypeString);
if(totalSizeClass != oldSizeClass)
{
Method method, next;
Class b;
- bool needUpdate = (mod != (base.templateClass ? base.templateClass : base) || _class.vTblSize != mod.vTblSize;
+ bool needUpdate = (mod != (base.templateClass ? base.templateClass : base) || _class.vTblSize != mod.vTblSize);
int updateStart = -1, updateEnd = -1;
if(mod.base && mod.base.base && mod.base.vTblSize > baseClass.vTblSize && needUpdate)
_class._vTbl = renew _class._vTbl void *[_class.vTblSize];
// memmove(_class._vTbl + mod.base.vTblSize, _class._vTbl + baseClass.vTblSize, (mod.base.vTblSize - baseClass.vTblSize) * sizeof(void *));
memmove(_class._vTbl + mod.base.vTblSize, _class._vTbl + baseClass.vTblSize, (_class.vTblSize - mod.vTblSize) * sizeof(void *));
+ memcpy(_class._vTbl + baseClass.vTblSize, mod._vTbl + baseClass.vTblSize, (mod.base.vTblSize - baseClass.vTblSize) * sizeof(void *));
updateStart = baseClass.vTblSize;
updateEnd = updateStart + mod.base.vTblSize - baseClass.vTblSize;
if(method.function) _class._vTbl[vMethod.vid] = method.function;
if(!method.symbol)
{
- delete method.name;
- delete method.dataTypeString;
+ delete (void *)method.name;
+ delete (void *)method.dataTypeString;
_class.methods.Delete((BTNode)method);
}
else
{
- delete method.dataTypeString;
+ delete (void *)method.dataTypeString;
method.type = vMethod.type;
method.dataTypeString = CopyString(vMethod.dataTypeString);
method._class = vMethod._class;
}
// _class.defaultAlignment = base ? base.defaultAlignment : 0;
-
+
if(type == normalClass || type == noHeadClass || type == structClass)
{
Property prop;
}
_property.selfWatchable = true;
_class.prop.Delete((BTNode)link);
- delete prop.name;
- delete prop.dataTypeString;
+ delete (void *)prop.name;
+ delete (void *)prop.dataTypeString;
_class.membersAndProperties.Delete(prop); // Remove only was done before?
}
}
}
// if(mod.base.memberID)
{
- for(member = _class.membersAndProperties.first; member; member = member.next)
+ DataMember next;
+ for(member = _class.membersAndProperties.first; member; member = next)
{
int offsetDiff = _class.offset - offsetBefore;
- if(!member.isProperty && offsetDiff > 0)
+ next = member.next;
+ if(!member.isProperty)
{
- member.offset += offsetDiff;
- member.memberOffset += offsetDiff;
+ if(oldType == bitClass && type != bitClass)
+ {
+ DataMember prev = member.prev;
+ // Correcting a bitClass to be a non-bit class (This should really never be required)
+ _class.membersAndProperties.Remove(member);
+ member = (DataMember)renew0 member byte[sizeof (class DataMember)];
+ _class.membersAndProperties.Insert(prev, member);
+ }
+
+ if(offsetDiff > 0)
+ {
+ member.offset += offsetDiff;
+ member.memberOffset += offsetDiff;
+ }
}
member.id += mod.base.memberID;
}
}
}
}
-
+
{
OldLink templateLink;
for(templateLink = base.templatized.first; templateLink; templateLink = templateLink.next)
{
Class template = templateLink.data;
- char * templateParams = strchr(template.name, '<');
+ //const char * templateParams = strchr(template.name, '<');
template.base = base.base;
template._vTbl = base._vTbl;
//ComputeClassParameters(template, templateParams, null);
template.sizeClass = base.sizeClass;
template.structSize = base.structSize;
template.vTblSize = base.vTblSize;
-
+
FixDerivativesBase(template, mod);
}
}
}
-public dllexport Class eSystem_RegisterClass(ClassType type, char * name, char * baseName, int size, int sizeClass,
- bool (* Constructor)(void *),void (* Destructor)(void *),
+public dllexport Class eSystem_RegisterClass(ClassType type, const char * name, const char * baseName, int size, int sizeClass,
+ bool (* Constructor)(void *), void (* Destructor)(void *),
Module module, AccessMode declMode, AccessMode inheritanceAccess)
{
int start = 0, c;
bool force32Bits = (module.application.isGUIApp & 4) ? true : false;
bool inCompiler = (module.application.isGUIApp & 8) ? true : false;
bool crossBits = force32Bits || force64Bits;
+ bool fixed = false;
+ if(inCompiler && crossBits)
+ {
+ Class c = eSystem_FindClass(__thisModule.application, name);
+ if(c && c.fixed)
+ fixed = true;
+ else if(__thisModule.name && !strcmp(__thisModule.name, "ecereCOM"))
+ fixed = true;
+ }
{
nameSpace = (declMode == publicAccess) ? &module.publicNameSpace : &module.privateNameSpace;
if(c - start)
{
- int offsetClass;
+ int offsetClass;
int totalSizeClass;
BTNamedLink classLink = null;
Class _class = null;
- char * dataTypeString = null;
+ const char * dataTypeString = null;
Class enumBase = null;
Class base = (baseName && baseName[0]) ? eSystem_FindClass(module, baseName) : null;
- bool refine = false;
+ Class prevBase = null;
- if(base && !base.internalDecl && (base.type == noHeadClass || base.type == structClass || base.type == normalClass))
+ if(base && !base.internalDecl && (base.type == noHeadClass || base.type == structClass || base.type == normalClass))
{
// Normal classes inheriting off simple classes should become no head classes
if(base.type == structClass && type == normalClass)
else
type = base.type;
}
- if(base && (type == normalClass || type == noHeadClass || type == structClass) &&
+ if(base && (type == normalClass || type == noHeadClass || type == structClass) &&
(base.type == unitClass || base.type == bitClass || base.type == enumClass))
{
type = base.type;
}
- if(!base || base.type == systemClass)
+ if(!base || base.type == systemClass || base.isInstanceClass)
{
if(type == enumClass)
{
// TO IMPROVE:
if(base || !baseName || !baseName[0] ||
- !strcmp(baseName, "unsigned int") ||
- !strcmp(baseName, "uint") ||
- !strcmp(baseName, "unsigned int64") ||
- !strcmp(baseName, "uint64") ||
- !strcmp(baseName, "int64") ||
- !strcmp(baseName, "unsigned short") ||
- !strcmp(baseName, "short") ||
- !strcmp(baseName, "unsigned char") ||
- !strcmp(baseName, "byte") ||
- !strcmp(baseName, "char") ||
- !strcmp(baseName, "uint32") ||
+ !strcmp(baseName, "unsigned int") ||
+ !strcmp(baseName, "uint") ||
+ !strcmp(baseName, "unsigned int64") ||
+ !strcmp(baseName, "uint64") ||
+ !strcmp(baseName, "int64") ||
+ !strcmp(baseName, "unsigned short") ||
+ !strcmp(baseName, "short") ||
+ !strcmp(baseName, "unsigned char") ||
+ !strcmp(baseName, "byte") ||
+ !strcmp(baseName, "char") ||
+ !strcmp(baseName, "uint32") ||
!strcmp(baseName, "uint16"))
{
base = eSystem_FindClass(module, "enum");
base = eSystem_FindClass(module, "struct");
dataTypeString = name + start;
}
- else
+ else
{
if(type == normalClass)
// dataTypeString = "struct Instance";
// DANGEROUSLY TESTING THIS... PUT IT BACK
//if(!base)
if(base || !baseName || !baseName[0] ||
- !strcmp(baseName, "unsigned int") ||
- !strcmp(baseName, "uint") ||
- !strcmp(baseName, "unsigned int64") ||
- !strcmp(baseName, "uint64") ||
- !strcmp(baseName, "int64") ||
- !strcmp(baseName, "unsigned short") ||
- !strcmp(baseName, "short") ||
- !strcmp(baseName, "unsigned char") ||
- !strcmp(baseName, "byte") ||
- !strcmp(baseName, "char") ||
- !strcmp(baseName, "uint32") ||
+ !strcmp(baseName, "unsigned int") ||
+ !strcmp(baseName, "uint") ||
+ !strcmp(baseName, "unsigned int64") ||
+ !strcmp(baseName, "uint64") ||
+ !strcmp(baseName, "int64") ||
+ !strcmp(baseName, "unsigned short") ||
+ !strcmp(baseName, "short") ||
+ !strcmp(baseName, "unsigned char") ||
+ !strcmp(baseName, "byte") ||
+ !strcmp(baseName, "char") ||
+ !strcmp(baseName, "uint32") ||
!strcmp(baseName, "uint16"))
{
if(type == normalClass && strcmp(name, "ecere::com::Instance") && strcmp(name, "enum") && strcmp(name, "struct"))
offsetClass = base ? base.sizeClass : (type == noHeadClass ? 0 : 0 /*sizeof(class Class)*/);
totalSizeClass = offsetClass + sizeClass;
-
- if((_class = eSystem_FindClass(module, name)))
- {
- FreeTemplatesDerivatives(_class);
+ _class = eSystem_FindClass(module, name);
+ if(!_class)
+ {
+ const char * colons = RSearchString(name, "::", strlen(name), true, false);
+ if(colons && colons)
+ {
+ _class = eSystem_FindClass(module, colons + 2);
+ if(_class)
+ {
+ if(_class.internalDecl)
+ {
+ delete (void *)_class.fullName;
+ _class.fullName = CopyString(name);
+ }
+ else
+ _class = null;
+ }
+ }
+ }
+ if(_class)
+ {
if(!_class.internalDecl)
{
if(declMode != baseSystemAccess)
return null;
}
+ FreeTemplatesDerivatives(_class);
+
classLink = (BTNamedLink)_class.nameSpace->classes.FindString(name + start);
_class.nameSpace->classes.Delete((BTNode)classLink);
{
}
{
NameSpace * ns = _class.nameSpace;
- while(ns->parent &&
- !ns->classes.first &&
+ while(ns != nameSpace &&
+ ns->parent &&
+ !ns->classes.first &&
!ns->functions.first &&
!ns->defines.first &&
!ns->nameSpaces.first)
ns = parent;
}
}
- refine = true;
}
else
{
}
}
- refine = true;
- delete _class.fullName;
+ delete (void *)_class.fullName;
_class.fullName = CopyString(name);
}
else
}
if(nameSpace)
{
- nameSpace->classes.Add((BTNode)BTNamedLink { name = _class.name, data = _class });
+ nameSpace->classes.Add((BTNode)BTNamedLink { name = (char *)_class.name, data = _class });
{
OldLink t;
for(t = _class.templatized.first; t; t = t.next)
{
Class template = t.data;
- nameSpace->classes.Add((BTNode)BTNamedLink { name = template.name, data = template });
+ nameSpace->classes.Add((BTNode)BTNamedLink { name = (char *)template.name, data = template });
}
}
memset((byte *)_class.data + offsetClass, 0, sizeClass);
}
- delete _class.dataTypeString;
+ delete (void *)_class.dataTypeString;
_class.dataTypeString = CopyString(dataTypeString);
_class.defaultAlignment = base ? base.defaultAlignment : 0;
}
_class.module = module;
+ prevBase = _class.base;
_class.base = base;
if(base)
{
}
_class.memberID = _class.startMemberID = (base && (type == normalClass || type == noHeadClass || type == structClass)) ? base.memberID : 0;
if(type == normalClass || type == noHeadClass)
- _class.offset = (base && base.structSize && base.type != systemClass) ? base.structSize : ((type == noHeadClass) ? 0 : (force64Bits ? 24 : (force32Bits && inCompiler) ? 12 : sizeof(class Instance)));
+ _class.offset = (base && base.structSize && base.type != systemClass) ?
+ // Use 'memberOffset' for nohead class as the members get added without padding
+ (base.type == normalClass ? base.structSize : base.memberOffset) : ((type == noHeadClass) ? 0 : ((force64Bits && inCompiler && fixed) ? 24 : (force32Bits && inCompiler && fixed) ? 12 : sizeof(class Instance)));
+ else
+ _class.offset = 0; // Force set to 0 for redefinitions
// For cross-bitness-compiling
if(crossBits)
{
+ // The GNOSIS runtime will use 'offset' to point to the object during compile executation
+ // Need to rethink through our cross-bitness compiling to have a distinct 'offset' (e.g. runtimeOffset)
+ // used by the runtime library vs. 'offset' used by the compiler to hardcode compilation results (or avoid those altogether)
+ if(!strcmp(name, "GNOSISSystem") ||
+ !strcmp(name, "LineStyle") ||
+ !strcmp(name, "FillStyle") ||
+ !strcmp(name, "FontObject") ||
+ !strcmp(name, "SymbolStyle"))
+ {
+ _class.offset = force32Bits ? 24 : 12;
+ }
// Ideally, the running library should be aware of the struct size of both 32 and 64 bit, since the compiler has no knowledge whatsoever of private members
- if(strstr(name, "ecere::sys::EARHeader") ||
+ else if(strstr(name, "ecere::sys::EARHeader") ||
strstr(name, "AnchorValue") ||
!strcmp(name, "ecere::com::CustomAVLTree") ||
!strcmp(name, "ecere::com::Array") ||
{
size = 3*(force32Bits ? 4 : 8);
_class.structAlignment = force32Bits ? 4 : 8; // FileListing is problematic because it is a struct with private data that the user allocates
+ _class.pointerAlignment = 1;
}
// These we want to recompute inside the IDE to help the debugger
else if(!strcmp(name, "ecere::com::Class")) size = 0; // 616
else if(!strcmp(name, "ecere::sys::OldList")) size = 0; // 32
else if(!strcmp(name, "ecere::sys::Item")) size = 0;
else if(!strcmp(name, "ecere::sys::NamedLink")) size = 0;
+ else if(!strcmp(name, "ecere::sys::NamedLink64")) size = 0;
else if(!strcmp(name, "ecere::sys::OldLink")) size = 0;
else if(!strcmp(name, "ecere::sys::NamedItem")) size = 0;
else if(!strcmp(name, "ecere::sys::NamedItem64")) size = 0;
else if(module != module.application && inCompiler)
{
// These we only want to recompute inside the compiler
- size = 0;
+ if(fixed || type == structClass)
+ size = 0;
}
}
}
_class.typeSize = _class.structSize = _class.memberOffset + size;
}
else if(type == bitClass || type == enumClass || type == unitClass)
- {
+ {
Class dataTypeClass = eSystem_FindClass(_class.module, dataTypeString);
if(dataTypeClass)
_class.typeSize = dataTypeClass.typeSize;
}
_class.offsetClass = offsetClass;
_class.sizeClass = totalSizeClass;
- _class.Constructor = (void *)Constructor;
+ _class.Constructor = Constructor;
_class.Destructor = Destructor;
if(_class.type != systemClass)
_class.type = type;
data.largest = ((EnumClassData)(base.data)).largest;
}
}
- if(base && base.vTblSize)
+ if(base)
{
- _class.vTblSize = base.vTblSize;
- // OK to scrap existing virtual table?
- delete _class._vTbl;
- _class._vTbl = _malloc(sizeof(int(*)()) * _class.vTblSize);
- memcpy(_class._vTbl, base._vTbl, sizeof(int(*)()) * _class.vTblSize);
+ int i;
+ uint oldSize = _class.vTblSize;
+ if(base.vTblSize && _class.vTblSize < base.vTblSize)
+ {
+ _class.vTblSize = base.vTblSize;
+ // OK to scrap existing virtual table?
+ //delete _class._vTbl;
+ //_class._vTbl = _malloc(sizeof(int(*)()) * _class.vTblSize);
+ // memcpy(_class._vTbl, base._vTbl, sizeof(int(*)()) * _class.vTblSize);
+ _class._vTbl = _realloc(_class._vTbl, sizeof(int(*)()) * _class.vTblSize);
+ }
+ if(!prevBase)
+ {
+ if(_class.type == normalClass && strcmp(_class.name, "ecere::com::Instance") && strcmp(_class.name, "enum") && strcmp(_class.name, "struct"))
+ prevBase = eSystem_FindClass(module, "ecere::com::Instance");
+ else
+ prevBase = eSystem_FindClass(module, "class");
+ }
+ for(i = 0; i < base.vTblSize; i++)
+ {
+ if(i >= oldSize || _class._vTbl[i] == prevBase._vTbl[i])
+ _class._vTbl[i] = base._vTbl[i];
+ }
}
if(_class.base)
}
FixDerivativesBase(_class, _class);
+
return _class;
}
}
{
DataMember member;
BTNamedLink namedLink;
- delete parentMember.name;
- delete parentMember.dataTypeString;
+ delete (void *)parentMember.name;
+ delete (void *)parentMember.dataTypeString;
while((member = parentMember.members.first))
{
}
}
-static void FreeEnumValue(NamedLink value)
+static void FreeEnumValue(NamedLink64 value)
{
delete value.name;
}
switch(param.type)
{
case type:
- delete template.templateArgs[id].dataTypeString;
+ delete (void *)template.templateArgs[id].dataTypeString;
+ template.templateArgs[id].dataTypeClass = null;
break;
case identifier:
- delete template.templateArgs[id].memberString;
+ delete (void *)template.templateArgs[id].memberString;
break;
case expression:
-
+
break;
}
}
ClassTemplateParameter param;
int id = 0;
if(_class.templateClass) _class = _class.templateClass;
- for(prevClass = _class.base; prevClass; prevClass = prevClass.base)
+ for(prevClass = _class.base; prevClass; prevClass = prevClass.base)
{
if(prevClass.templateClass) prevClass = prevClass.templateClass;
id += prevClass.templateParams.count;
switch(param.type)
{
case type:
- delete template.templateArgs[id].dataTypeString;
+ delete (void *)template.templateArgs[id].dataTypeString;
+ template.templateArgs[id].dataTypeClass = null;
break;
case identifier:
- delete template.templateArgs[id].memberString;
+ delete (void *)template.templateArgs[id].memberString;
break;
case expression:
// delete template.templateArgs[id].dataTypeString;
if(template.nameSpace)
{
BTNamedLink link = (BTNamedLink)template.nameSpace->classes.FindString(template.name);
- template.nameSpace->classes.Delete((BTNode)link);
+ if(link)
+ template.nameSpace->classes.Delete((BTNode)link);
}
- FreeTemplateArgs(template);
- delete template.fullName;
- delete template.name;
- delete template.templateArgs;
- delete template.dataTypeString;
+ FreeTemplatesDerivatives(template);
+ FreeTemplateArgs(template);
while((deriv = template.derivatives.first))
{
template.derivatives.Delete(deriv);
}
- _free(template);
+ delete (void *)template.fullName;
+ delete (void *)template.name;
+ delete template.templateArgs;
+ delete (void *)template.dataTypeString;
+
+ if(template.module)
+ template.module.classes.Delete(template);
+ else
+ _free(template);
}
static void FreeTemplates(Class _class)
}
FreeTemplateArgs(_class);
- //if(_class.templateArgs)
- //printf("Deleting Template args for %s\n", _class.name);
delete _class.templateArgs;
- delete _class.dataTypeString;
+ delete (void *)_class.dataTypeString;
while((template = _class.templatized.first))
{
ClassProperty classProp;
ClassTemplateParameter param;
+ if(_class.templateClass)
+ {
+ // Unregistering templates... Used in IDE to address crash on Ecere classes templatized with imported modules
+ OldLink templateLink;
+ for(templateLink = _class.templateClass.templatized.first; templateLink; templateLink = templateLink.next)
+ {
+ if(templateLink.data == _class)
+ {
+ _class.templateClass.templatized.Delete(templateLink);
+ break;
+ }
+ }
+ FreeTemplate(_class);
+ return;
+ }
+
delete _class._vTbl;
FreeTemplates(_class);
-
- FreeTemplateArgs(_class);
- delete _class.templateArgs;
while((template = _class.templatized.first))
{
{
if(!member.isProperty && (member.type == unionMember || member.type == structMember))
DataMember_Free(member);
- delete member.name;
- delete member.dataTypeString;
+ delete (void *)member.name;
+ delete (void *)member.dataTypeString;
_class.membersAndProperties.Delete(member);
}
while((member = _class.conversions.first))
{
- delete member.name;
- delete member.dataTypeString;
+ delete (void *)member.name;
+ delete (void *)member.dataTypeString;
_class.conversions.Delete(member);
}
while((classProp = (ClassProperty)_class.classProperties.first))
{
- delete classProp.name;
- delete classProp.dataTypeString;
+ delete (void *)classProp.name;
+ delete (void *)classProp.dataTypeString;
_class.classProperties.Delete((BTNode)classProp);
}
while((method = (Method)_class.methods.first))
{
- delete method.name;
- delete method.dataTypeString;
+ delete (void *)method.name;
+ delete (void *)method.dataTypeString;
_class.methods.Delete((BTNode)method);
}
_class.delayedCPValues.Free(null);
_class.selfWatchers.Free(null);
-
+
if(_class.base)
{
// Class base = _class.base.templateClass ? _class.base.templateClass : _class.base;
_class.nameSpace->classes.Delete((BTNode)link);
}
- delete _class.name;
- delete _class.fullName;
-
- delete _class.dataTypeString;
+ delete (void *)_class.name;
+ delete (void *)_class.fullName;
+
+ delete (void *)_class.dataTypeString;
delete _class.data;
switch(param.type)
{
case type:
- delete param.defaultArg.dataTypeString;
+ delete (void *)param.defaultArg.dataTypeString;
break;
case identifier:
- delete param.defaultArg.memberString;
+ delete (void *)param.defaultArg.memberString;
break;
case expression:
-
+
break;
}
- if(param.type != identifier) delete param.dataTypeString;
- delete param.name;
+ if(param.type != identifier) delete (void *)param.dataTypeString;
+ delete (void *)param.name;
_class.templateParams.Delete(param);
}
_free(_class);
}
-static BTNamedLink ScanNameSpace(NameSpace nameSpace, char * name, void * listOffset)
+static BTNamedLink ScanNameSpace(NameSpace nameSpace, const char * name, void * listOffset)
{
- BinaryTree * tree = (BinaryTree *)((byte *)nameSpace + (uint)listOffset);
+ BinaryTree * tree = (BinaryTree *)((byte *)nameSpace + (uintptr)listOffset);
BTNamedLink link = (BTNamedLink)tree->Find((uintptr)name);
NameSpace * child;
if(!link)
return link;
}
-static BTNamedLink SearchNameSpace(NameSpace nameSpace, char * name, void * listOffset)
+static BTNamedLink SearchNameSpace(NameSpace nameSpace, const char * name, void * listOffset)
{
int start = 0, c;
char ch;
return null;
}
-static BTNamedLink SearchModule(Module module, char * name, void * listOffset, bool searchPrivate)
+static BTNamedLink SearchModule(Module module, const char * name, void * listOffset, bool searchPrivate)
{
SubModule subModule;
BTNamedLink link;
return null;
}
-public int64 _strtoi64(char * string, char ** endString, int base)
+public int64 _strtoi64(const char * string, const char ** endString, int base)
{
int64 value = 0;
int sign = 1;
{
if(ch >= '0' && ch <= '9')
ch -= '0';
- else if(ch >= 'a' && ch <= 'z')
- ch -= ('a' - 10);
- else if(ch >= 'A' && ch <= 'Z')
+ else if(ch >= 'a' && ch <= 'z')
+ ch -= ('a' - 10);
+ else if(ch >= 'A' && ch <= 'Z')
ch -= ('A'- 10);
else
- {
- if(endString)
- *endString = string + c;
// Invalid character
break;
- }
if(ch < base)
{
value *= base;
value += ch;
}
else
- {
- if(endString)
- *endString = string + c;
// Invalid character
break;
- }
}
+ if(endString)
+ *endString = string + c;
+
return sign*value;
}
-public uint64 _strtoui64(char * string, char ** endString, int base)
+public uint64 _strtoui64(const char * string, const char ** endString, int base)
{
uint64 value = 0;
int sign = 1;
{
if(ch >= '0' && ch <= '9')
ch -= '0';
- else if(ch >= 'a' && ch <= 'z')
- ch -= ('a' - 10);
- else if(ch >= 'A' && ch <= 'Z')
+ else if(ch >= 'a' && ch <= 'z')
+ ch -= ('a' - 10);
+ else if(ch >= 'A' && ch <= 'Z')
ch -= ('A' - 10);
else
- {
- if(endString)
- *endString = string + c;
// Invalid character
break;
- }
if(ch < base)
{
value *= base;
value += ch;
}
else
- {
- if(endString)
- *endString = string + c;
// Invalid character
break;
- }
}
+ if(endString)
+ *endString = string + c;
return sign*value;
}
-public dllexport Class eSystem_FindClass(Module module, char * name)
+public dllexport Class eSystem_FindClass(Module module, const char * name)
{
if(name && module)
{
BTNamedLink link;
+ if(!strncmp(name, "const ", 6)) name += 6;
link = SearchNameSpace(&module.application.systemNameSpace, name, &((NameSpace *)0)->classes);
if(link) return link.data;
link = SearchModule(module, name, &((NameSpace *)0)->classes, true);
if(link) return link.data;
-
+
{
char noTemplateName[1024];
char * templateParams = strchr(name, '<');
templatedClass.fullName = CopyString(className);
templatedClass.dataTypeString = CopyString(_class.dataTypeString);
templatedClass.name = CopyString(templatedClass.fullName + strlen(_class.fullName) - strlen(_class.name));
- templatedClass.nameSpace->classes.Add((BTNode)BTNamedLink { name = templatedClass.name, data = templatedClass });
+ templatedClass.nameSpace->classes.Add((BTNode)BTNamedLink { name = (char *)templatedClass.name, data = templatedClass });
templatedClass.templateArgs = null;
templatedClass.numParams = 0;
templatedClass.derivatives = { };
templatedClass.templatized = { };
+ templatedClass.module = module;
+ templatedClass.count = 0; // TOCHECK: Keeping track of individual templatized classes?
+ templatedClass.prev = null;
+ templatedClass.next = null;
+
+ module.classes.Add(templatedClass);
ComputeClassParameters(templatedClass, templateParams, module);
arg.dataTypeString = CopyString(arg.dataTypeString);
break;
case expression:
-
+
break;
case identifier:
arg.memberString = CopyString(arg.memberString);
}
}
-static void ComputeClassParameters(Class templatedClass, char * templateParams, Module findModule)
+static void ComputeClassParameters(Class templatedClass, const char * templateParams, Module findModule)
{
char ch;
- char * nextParamStart = templateParams ? (templateParams + 1) : null;
+ const char * nextParamStart = templateParams ? (templateParams + 1) : null;
ClassTemplateParameter curParam = null;
Class lastClass = null, sClass;
int curParamID = 0;
if(sClass.templateClass) sClass = sClass.templateClass;
numParams += sClass.templateParams.count;
}
-
+
if(templatedClass.templateArgs)
FreeTemplateArgs(templatedClass);
delete templatedClass.templateArgs;
CopyTemplateArg(param, templatedClass.templateArgs[id++]);
}*/
}
-
+
if(templatedClass.base && templatedClass.base.templateArgs && _class == templatedClass)
{
Class sClass;
- memcpy(templatedClass.templateArgs, templatedClass.base.templateArgs,
+ memcpy(templatedClass.templateArgs, templatedClass.base.templateArgs,
sizeof(ClassTemplateArgument) * (numParams - templatedClass.templateParams.count));
for(sClass = templatedClass.base; sClass; sClass = sClass.base)
{
CopyTemplateArg(param, templatedClass.templateArgs[id++]);
}
}
-
+
while(nextParamStart)
{
- char * paramStart = nextParamStart;
- char * paramEnd;
+ const char * paramStart = nextParamStart;
+ const char * paramEnd;
int level = 0;
while(*paramStart == ' ') paramStart++;
paramEnd = paramStart;
- while((ch = *paramEnd, ch && (level > 0 || (ch != '>' && ch != ','))))
+ while((ch = *paramEnd, ch && (level > 0 || (ch != '>' && ch != ','))))
{
if(ch == '<') level++;
if(ch == '>') level--;
while(*paramEnd == ' ') paramEnd--;
if(paramEnd > paramStart)
{
- char * ptr, * equal = null;
+ const char * ptr, * equal = null;
for(ptr = paramStart; ptr <= paramEnd; ptr++)
{
if(*ptr == '=')
}
if(equal)
{
- char * end = equal - 1;
+ const char * end = equal - 1;
char ident[1024];
-
+
while(*end == ' ') end--;
strncpy(ident, paramStart, end + 1 - paramStart);
ident[end + 1 - paramStart] = 0;
-
+
for(sClass = _class; sClass; sClass = sClass.base)
{
if(sClass.templateClass) sClass = sClass.templateClass;
curParam = param;
break;
}
- if(curParam)
+ if(curParam)
{
Class nextClass;
for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
{
curParamID += nextClass.templateParams.count;
break;
- }
+ }
break;
}
}
{
ClassTemplateArgument argument { };
char value[1024];
- if(equal)
+ if(equal)
{
equal++;
while(*equal == ' ') equal++;
{
case type:
argument.dataTypeString = CopyString(value);
- argument.dataTypeClass = eSystem_FindClass(_class.module, value);
- if(!argument.dataTypeClass) argument.dataTypeClass = eSystem_FindClass(_class.module.application, value);
- if(!argument.dataTypeClass) argument.dataTypeClass = eSystem_FindClass(findModule, value);
+ argument.dataTypeClass = eSystem_FindClass(findModule, value);
+ if(!argument.dataTypeClass)
+ argument.dataTypeClass = eSystem_FindClass(_class.module, value);
+ if(!argument.dataTypeClass)
+ argument.dataTypeClass = eSystem_FindClass(_class.module.application, value);
break;
case expression:
{
if(!expClass) expClass = eSystem_FindClass(_class.module.application, curParam.dataTypeString);
if(expClass)
{
- //if(expClass.type ==
+ //if(expClass.type ==
((bool (*)(void *, void *, const char *))(void *)expClass._vTbl[__ecereVMethodID_class_OnGetDataFromString])(expClass, &argument.expression, value);
}
// Expression should be pre simplified here
}
else if(!strcmp(curParam.dataTypeString, "uint"))
{
- argument.expression.ui = strtoul(value, null, 0);
+ argument.expression.ui = (uint)strtoul(value, null, 0);
}
else if(!strcmp(curParam.dataTypeString, "char"))
{
}
else // if(!strcmp(curParam.dataTypeString, "int"))
{
- argument.expression.i = strtol(value, null, 0);
+ argument.expression.i = (int)strtol(value, null, 0);
}
break;
- }
+ }
case identifier:
argument.memberString = CopyString(value);
break;
CopyTemplateArg(param, templatedClass.templateArgs[curParamID]);
if(param.type == type && param.defaultArg.dataTypeString)
{
- templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module, param.defaultArg.dataTypeString);
- if(!templatedClass.templateArgs[curParamID].dataTypeClass)
+ templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(findModule, param.defaultArg.dataTypeString);
+ if(!templatedClass.templateArgs[curParamID].dataTypeClass)
+ templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module, param.defaultArg.dataTypeString);
+ if(!templatedClass.templateArgs[curParamID].dataTypeClass)
templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module.application, param.defaultArg.dataTypeString);
- if(!templatedClass.templateArgs[curParamID].dataTypeClass)
- templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(findModule, param.defaultArg.dataTypeString);
}
}
curParamID++;
Class cClass = null;
int paramCount = 0;
int lastParam = -1;
-
+
char templateString[1024];
sprintf(templateString, "%s<", expClass.templateClass.fullName);
for(cClass = expClass; cClass; cClass = cClass.base)
{
int id = p;
Class sClass;
+ // NOTE: This struct 'arg' here is only to build up templateString
ClassTemplateArgument arg;
for(sClass = expClass.base; sClass; sClass = sClass.base) id += sClass.templateParams.count;
arg = expClass.templateArgs[id];
{
if(cParam.type == type && arg.dataTypeString && !strcmp(cParam.name, arg.dataTypeString))
{
- arg.dataTypeString = templatedClass.templateArgs[p].dataTypeString;
- arg.dataTypeClass = templatedClass.templateArgs[p].dataTypeClass;
+ arg = templatedClass.templateArgs[p];
break;
}
}
}
}
{
- int len = strlen(templateString);
+ int len = (int)strlen(templateString);
if(templateString[len-1] == '>') templateString[len++] = ' ';
templateString[len++] = '>';
templateString[len++] = '\0';
FreeTemplateArg(templatedClass, param, c);
arg->dataTypeString = CopyString(templateString);
- arg->dataTypeClass = eSystem_FindClass(templatedClass.module, templateString);
+ arg->dataTypeClass = eSystem_FindClass(findModule, templateString);
+ if(!arg->dataTypeClass)
+ arg->dataTypeClass = eSystem_FindClass(templatedClass.module, templateString);
if(!arg->dataTypeClass)
arg->dataTypeClass = eSystem_FindClass(templatedClass.module.application, templateString);
}
{
FreeTemplateArg(templatedClass, param, c);
+ // TRICKY: This copies from equivalent parameters
arg->dataTypeString = templatedClass.templateArgs[p].dataTypeString;
arg->dataTypeClass = templatedClass.templateArgs[p].dataTypeClass;
CopyTemplateArg(cParam, arg);
}
}
}
- c--;
+ c--;
}
}
}
Class nextClass;
ClassTemplateParameter param;
if(sClass.templateClass) sClass = sClass.templateClass;
-
- for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
+
+ for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
{
if(nextClass.templateClass) nextClass = nextClass.templateClass;
curParamID += nextClass.templateParams.count;
CopyTemplateArg(param, templatedClass.templateArgs[curParamID]);
if(param.type == type && param.defaultArg.dataTypeString)
{
- templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module, param.defaultArg.dataTypeString);
+ templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(findModule, param.defaultArg.dataTypeString);
if(!templatedClass.templateArgs[curParamID].dataTypeClass)
- templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module.application, param.defaultArg.dataTypeString);
+ templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module, param.defaultArg.dataTypeString);
if(!templatedClass.templateArgs[curParamID].dataTypeClass)
- templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(findModule, param.defaultArg.dataTypeString);
+ templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module.application, param.defaultArg.dataTypeString);
}
}
curParamID++;
Class dClass;
int p = numParams - 1;
for(dClass = _class; dClass; dClass = dClass.base)
- {
+ {
if(dClass.templateClass) dClass = dClass.templateClass;
for(cParam = dClass.templateParams.last; cParam; cParam = cParam.prev, p--)
{
if(param.type == identifier && arg->memberString)
{
Class memberClass = templatedClass;
- char * memberString = arg->memberString;
- char * colon = strstr(memberString, "::");
- char * memberName = memberString;
+ const char * memberString = arg->memberString;
+ const char * colon = strstr(memberString, "::");
+ const char * memberName = memberString;
if(colon) memberName = colon + 2;
if(!colon)
{
memcpy(className, memberString, colon - memberString);
className[colon - memberString] = '\0';
-
+
for(sClass = _class; sClass; sClass = sClass.base)
{
ClassTemplateParameter cParam;
int id = 0;
if(sClass.templateClass) sClass = sClass.templateClass;
- for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
+ for(nextClass = sClass.base; nextClass; nextClass = nextClass.base)
{
if(nextClass.templateClass) nextClass = nextClass.templateClass;
id += nextClass.templateParams.count;
strcpy(className, templatedClass.templateArgs[id].dataTypeString);
}
id++;
- }
+ }
}
- memberClass = eSystem_FindClass(templatedClass.module, className);
// TESTING: Added this here...
+ memberClass = eSystem_FindClass(findModule, className);
if(!memberClass)
- memberClass = eSystem_FindClass(findModule, className);
+ memberClass = eSystem_FindClass(templatedClass.module, className);
if(!memberClass)
memberClass = eSystem_FindClass(templatedClass.module.application, className);
}
ClassTemplateParameter param;
Class nextClass;
int p = 0;
- for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
+ for(nextClass = sClass.base; nextClass; nextClass = nextClass.base) p += nextClass.templateParams.count;
for(param = sClass.templateParams.first; param; param = param.next, p++)
{
ClassTemplateArgument * arg = &_class.templateArgs[p];
{
for(; _class && from; _class = _class.base)
{
- if(_class == from || _class.templateClass == from || (_class.type == systemClass && from.name && !strcmp(_class.name, from.name)))
+ if(_class == from || _class.templateClass == from || ((_class.type == systemClass || (_class.type == normalClass && _class.isInstanceClass)) && from.name && !strcmp(_class.name, from.name)))
return true;
}
}
return false;
}
-static void FixDerivativeVirtualMethod(Class base, char * name, int vid, void * origFunction, char * type)
+static void FixDerivativeVirtualMethod(Class base, const char * name, int vid, void * origFunction, const char * type)
{
OldLink derivative;
for(derivative = base.derivatives.first; derivative; derivative = derivative.next)
if(!method.symbol)
{
- delete method.name;
- delete method.dataTypeString;
+ delete (void *)method.name;
+ delete (void *)method.dataTypeString;
_class.methods.Delete((BTNode)method);
}
else
{
- delete method.dataTypeString;
+ delete (void *)method.dataTypeString;
method.type = virtualMethod;
method.dataTypeString = CopyString(type);
method._class = base;
}
}
-public dllexport Method eClass_AddMethod(Class _class, char * name, char * type, void * function, AccessMode declMode)
+public dllexport Method eClass_AddMethod(Class _class, const char * name, const char * type, void * function, AccessMode declMode)
{
- if(_class && name)
+ if(_class && !_class.comRedefinition && name)
{
Class base;
for(base = _class; base; base = base.base)
{
- Method method = (Method)base.methods.FindString(name);
+ Method method;
+ if(base.templateClass) base = base.templateClass;
+ method = (Method)base.methods.FindString(name);
if(method)
{
- // If this overides a virtual method
+ // If this overrides a virtual method
if(method.type == virtualMethod)
{
OldLink deriv;
void * oldFunction = _class._vTbl[method.vid];
- if(method.vid > _class.vTblSize)
- printf("error");
+ if(method.vid >= _class.vTblSize)
+ printf("error: virtual methods overriding failure\n");
else
- _class._vTbl[method.vid] = function ? function : DefaultFunction;
+ _class._vTbl[method.vid] = function ? function : null; //(void *)DefaultFunction;
for(deriv = _class.derivatives.first; deriv; deriv = deriv.next)
{
Class derivClass = deriv.data;
Method method
{
name = CopyString(name),
- function = function ? function : DefaultFunction;
+ function = function ? function : null; //DefaultFunction;
_class = _class;
dataTypeString = CopyString(type);
memberAccess = declMode;
return null;
}
-public dllexport Method eClass_AddVirtualMethod(Class _class, char * name, char * type, void * function, AccessMode declMode)
+public dllexport Method eClass_AddVirtualMethod(Class _class, const char * name, const char * type, void * function, AccessMode declMode)
{
- if(_class && name)
+ if(_class && !_class.comRedefinition && name)
{
Class base;
for(base = _class; base; base = base.base)
{
// If this overides a virtual method
if(method.type == virtualMethod)
- _class._vTbl[method.vid] = function ? function : DefaultFunction;
+ {
+ if(method.vid >= _class.vTblSize)
+ printf("error: virtual methods overriding failure\n");
+ else
+ _class._vTbl[method.vid] = function ? function : null; //(void *)DefaultFunction;
+ }
else
base = null;
return method;
Method method
{
name = CopyString(name);
- function = function ? function : DefaultFunction;
+ function = function ? function : null; //DefaultFunction;
type = virtualMethod;
_class = _class;
vid = _class.vTblSize++;
};
_class.methods.Add((BTNode)method);
_class._vTbl = renew _class._vTbl void *[_class.vTblSize];
- _class._vTbl[method.vid] = function ? function : DefaultFunction;
+ _class._vTbl[method.vid] = function ? function : null; //(void *)DefaultFunction;
// TODO: Fix derived classes
if(_class.derivatives.first || _class.templatized.first)
- FixDerivativeVirtualMethod(_class, name, method.vid, function ? function : (void *)DefaultFunction, type);
+ FixDerivativeVirtualMethod(_class, name, method.vid, function ? function : null /*(void *)DefaultFunction*/, type);
return method;
}
}
{
Class _class = derivative.data;
Property prop;
- BTNamedLink link;
- link = (BTNamedLink)_class.prop.FindString(_property.name);
+ BTNamedLink link = (BTNamedLink)_class.prop.FindString(_property.name);
if(link)
{
prop = link.data;
}
_property.selfWatchable = true;
- delete prop.name;
- delete prop.dataTypeString;
+ delete (void *)prop.name;
+ delete (void *)prop.dataTypeString;
_class.membersAndProperties.Delete(prop);
_class.prop.Delete((BTNode)link);
}
}
}
-public dllexport Property eClass_AddProperty(Class _class, char * name, char * dataType, void * setStmt, void * getStmt, AccessMode declMode)
+public dllexport Property eClass_AddProperty(Class _class, const char * name, const char * dataType, void * setStmt, void * getStmt, AccessMode declMode)
{
Property _property = null;
if(_class)
{
- if(!_class.prop.FindString((name ? name : dataType)))
+ BTNamedLink link = (BTNamedLink)_class.prop.FindString(name ? name : dataType);
+ bool isConversion = name ? false : true;
+ if(!name && dataType && !strncmp(dataType, "const ", 6))
+ {
+ name = dataType + 6;
+ isConversion = true;
+ }
+ if(link)
+ _property = link.data;
+ if(!_property)
{
_property =
{
dataTypeString = CopyString(dataType);
_class = _class;
compiled = true;
- conversion = name ? false : true;
+ conversion = isConversion;
memberAccess = declMode;
};
- if(name)
+ if(!isConversion)
_class.membersAndProperties.Add(_property);
else
_class.conversions.Add(_property);
}
}
-public dllexport ClassProperty eClass_AddClassProperty(Class _class, char * name, char * dataType, void * setStmt, void * getStmt)
+public dllexport ClassProperty eClass_AddClassProperty(Class _class, const char * name, const char * dataType, void * setStmt, void * getStmt)
{
- if(name && !_class.classProperties.FindString(name))
+ if(name && !_class.classProperties.FindString(name))
{
ClassProperty _property
{
return classFindTotalTime;
}
*/
-public dllexport ClassProperty eClass_FindClassProperty(Class _class, char * name)
+public dllexport ClassProperty eClass_FindClassProperty(Class _class, const char * name)
{
//Time startTime = GetTime();
ClassProperty _property = null;
return _property;
}
-public dllexport int64 eClass_GetProperty(Class _class, char * name)
+public dllexport int64 eClass_GetProperty(Class _class, const char * name)
{
ClassProperty _property = eClass_FindClassProperty(_class, name);
if(_property && _property.Get && _property.Get != (void *)1)
return 0;
}
-public dllexport void eClass_SetProperty(Class _class, char * name, int64 value)
+public dllexport void eClass_SetProperty(Class _class, const char * name, int64 value)
{
ClassProperty _property = eClass_FindClassProperty(_class, name);
if(_property)
}
else
{
- _class.delayedCPValues.Add(NamedLink64 { name = name, value });
+ _class.delayedCPValues.Add(NamedLink64 { name = (char *)name, value });
}
}
-public dllexport Method eClass_FindMethod(Class _class, char * name, Module module)
+public dllexport Method eClass_FindMethod(Class _class, const char * name, Module module)
{
//Time startTime = GetTime();
if(_class && name)
Instance instance = null;
if(_class)
{
- // instance = _malloc(_class.size);
+ // instance = _malloc(_class.size);
#ifdef MEMINFO
#undef malloc
size *= 3;
}
instance = _calloc(1, size);
+ if(!instance && size)
+ printf("Failed to allocate memory instantiating %s object!\n", _class.name);
+ else if(!size)
+ printf("Warning: 0 size instantiating %s object!\n", _class.name);
}
#ifdef MEMINFO
allocateClass = null;
memMutex.Release();
#endif
- if(_class.type == normalClass)
+
+#if !defined(MEMINFO) && defined(MEMTRACKING)
+ {
+ MemBlock block = (MemBlock)((byte *)instance - sizeof(class MemBlock));
+ block._class = _class;
+ }
+#endif
+
+ if(instance && _class.type == normalClass)
{
instance._class = _class;
// Copy the virtual table initially
instance._vTbl = _class._vTbl;
}
- if(!ConstructInstance(instance, _class, null))
+ if(instance && !ConstructInstance(instance, _class, null))
{
_free(instance);
instance = null;
if(_class && instancePtr && *instancePtr)
{
bool wasApp = false, wasGuiApp = false;
+ Instance oldInstance = *instancePtr;
Instance instance = (Instance)renew *instancePtr byte[_class.structSize];
Class fromClass = instance._class;
*instancePtr = instance;
for(nameSpace = (NameSpace *)app.systemNameSpace.nameSpaces.first; nameSpace; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
nameSpace->parent = &app.systemNameSpace;
// --------------------------------------------------
-
+
for(_class = app.classes.first; _class; _class = _class.next)
{
OldLink templateLink;
_class.module = (Module) app;
for(templateLink = _class.templatized.first; templateLink; templateLink = templateLink.next)
- {
+ {
Class template = templateLink.data;
- template.module = _class.module;
+ if(template.module == oldInstance)
+ template.module = _class.module;
}
}
for(_class = module.classes.first; _class; _class = _class.next)
{
OldLink templateLink;
+ Module oldModule = _class.module;
_class.module = module;
for(templateLink = _class.templatized.first; templateLink; templateLink = templateLink.next)
{
Class template = templateLink.data;
- template.module = _class.module;
+ if(template.module == oldModule)
+ template.module = _class.module;
}
}
}
bool ownVtbl;
#ifdef MEMINFO
+#if (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__)
+ if(instance._class == (void *)0xecececececececec)
+#else
if(instance._class == (void *)0xecececec)
+#endif
_free(instance);
#endif
OldList * watchers = (OldList *)((byte *)instance + _property.watcherOffset);
Watcher watcher, next;
for(watcher = watchers->first; watcher; watcher = next)
- {
+ {
next = watcher.next;
watchers->Delete(watcher);
}
}
}
}*/
-
+
base = _class.base;
- if(base && base.type == systemClass) base = null;
+ if(base && (base.type == systemClass || base.isInstanceClass)) base = null;
if(_class.Destructor)
_class.Destructor(instance);
#ifdef MEMINFO
}
}
-public dllexport Property eClass_FindProperty(Class _class, char * name, Module module)
+public dllexport Property eClass_FindProperty(Class _class, const char * name, Module module)
{
//Time startTime = GetTime();
if(_class && name)
{
+ if(!strncmp(name, "const ", 6))
+ name += 6;
+
for(; _class; _class = _class.base)
{
BTNamedLink link;
return null;
}
-static DataMember FindDataMember(OldList list, BinaryTree alist, char * name, uint * offset, int * id, bool searchPrivate, DataMember * subMemberStack, int * subMemberStackPos)
+static DataMember FindDataMember(OldList list, BinaryTree alist, const char * name, uint * offset, int * id, bool searchPrivate, DataMember * subMemberStack, int * subMemberStackPos)
{
BTNamedLink link;
DataMember dataMember;
return null;
}
-public dllexport DataMember eClass_FindDataMember(Class _class, char * name, Module module, DataMember * subMemberStack, int * subMemberStackPos)
+public dllexport DataMember eClass_FindDataMember(Class _class, const char * name, Module module, DataMember * subMemberStack, int * subMemberStackPos)
{
//Time startTime = GetTime();
DataMember dataMember = null;
return dataMember;
}
-public dllexport DataMember eClass_FindDataMemberAndOffset(Class _class, char * name, uint * offset, Module module, DataMember * subMemberStack, int * subMemberStackPos)
+public dllexport DataMember eClass_FindDataMemberAndOffset(Class _class, const char * name, uint * offset, Module module, DataMember * subMemberStack, int * subMemberStackPos)
{
//Time startTime = GetTime();
DataMember dataMember = null;
return dataMember;
}
-public dllexport DataMember eClass_FindDataMemberAndId(Class _class, char * name, int * id, Module module, DataMember * subMemberStack, int * subMemberStackPos)
+public dllexport DataMember eClass_FindDataMemberAndId(Class _class, const char * name, int * id, Module module, DataMember * subMemberStack, int * subMemberStackPos)
{
//Time startTime = GetTime();
DataMember dataMember = null;
public dllexport void eClass_FindNextMember(Class _class, Class * curClass, DataMember * curMember, DataMember * subMemberStack, int * subMemberStackPos)
{
// THIS CODE WILL FIND NEXT MEMBER... (PUBLIC MEMBERS ONLY)
- if(*curMember)
+ if(*curMember)
{
*curMember = (*curMember).next;
*curMember = (*curMember).members.first;
while(*curMember && ((*curMember).memberAccess == privateAccess))
- *curMember = (*curMember).next;
+ *curMember = (*curMember).next;
}
}
}
else
while(*curMember && (*curMember).name) // ADDED THIS HERE for eComPacket packet { Connect, 0, { ECOMMUNICATOR_PROTOCOL_VERSION } };
{
- DataMember dataMember = eClass_FindDataMember(_class, curMember->name, null, null, null);
- if(!dataMember) dataMember = (DataMember)eClass_FindProperty(_class, curMember->name, null);
- if(dataMember && dataMember.memberAccess != privateAccess)
+ DataMember dataMember = null;
+ if(((*curMember).memberAccess != privateAccess))
+ {
+ dataMember = eClass_FindDataMember(_class, curMember->name, null, null, null);
+ if(!dataMember) dataMember = (DataMember)eClass_FindProperty(_class, curMember->name, null);
+ }
+ if(dataMember && dataMember.memberAccess != privateAccess && dataMember.id >= 0) // Skip _vTbl, _refCount and _class in Instance
{
*curMember = dataMember;
break;
*curMember = (*curMember).members.first;
while(*curMember && (*curMember).memberAccess == privateAccess)
- *curMember = (*curMember).next;
+ *curMember = (*curMember).next;
}
}
}
}
}
-public dllexport void eInstance_SetMethod(Instance instance, char * name, void * function) // YET TO BE DECIDED: , Module module)
+public dllexport void eInstance_SetMethod(Instance instance, const char * name, void * function) // YET TO BE DECIDED: , Module module)
{
if(instance && name)
{
{
instance._vTbl = _malloc(sizeof(void *) * instance._class.vTblSize);
memcpy(instance._vTbl, instance._class._vTbl,
- sizeof(int(*)()) * instance._class.vTblSize);
+ sizeof(int(*)()) * instance._class.vTblSize);
}
- instance._vTbl[method.vid] = function ? function : DefaultFunction;
+ instance._vTbl[method.vid] = function ? function : null; //(void *)DefaultFunction;
}
}
}
OldLink deriv;
_class.structSize += _class.base.structSize - _class.offset;
- _class.offset = _class.base.structSize;
+ _class.offset = _class.base.structSize;
for(deriv = _class.derivatives.first; deriv; deriv = deriv.next)
FixOffsets(deriv.data);
for(deriv = _class.derivatives.first; deriv; deriv = deriv.next)
FixOffsets(deriv.data);
}
-
-public dllexport DataMember eClass_AddDataMember(Class _class, char * name, char * type, unsigned int size, unsigned int alignment, AccessMode declMode)
+ // F000F000 will mean a pointer size alignment
+public dllexport DataMember eClass_AddDataMember(Class _class, const char * name, const char * type, unsigned int size, unsigned int alignment, AccessMode declMode)
{
if(_class && name)
{
- if(!_class.members.FindString(name))
+ if(!_class.members.FindString(name))
{
DataMember dataMember;
if(alignment)
{
+ bool pointerAlignment = alignment == 0xF000F000;
+ bool force64Bits = (_class.module.application.isGUIApp & 2) ? true : false;
+ bool force32Bits = (_class.module.application.isGUIApp & 4) ? true : false;
+ if((force32Bits || force64Bits) && !strcmp(_class.name, "AVLNode") && !strcmp(name, "__ecerePrivateData0"))
+ {
+ if(force64Bits)
+ {
+ type = "byte[32]";
+ size = 32;
+ }
+ if(force32Bits)
+ {
+ type = "byte[16]";
+ size = 16;
+ }
+ }
+
+ if(pointerAlignment) alignment = force64Bits ? 8 : force32Bits ? 4 : sizeof(void *);
+
+ if(pointerAlignment && _class.structAlignment <= 4)
+ _class.pointerAlignment = 1;
+ else if(!pointerAlignment && alignment >= 8)
+ _class.pointerAlignment = 0;
+
_class.structAlignment = Max(_class.structAlignment, alignment);
+ if(_class.offset % alignment)
+ {
+ _class.structSize += alignment - (_class.offset % alignment);
+ _class.offset += alignment - (_class.offset % alignment);
+ }
if(_class.memberOffset % alignment)
_class.memberOffset += alignment - (_class.memberOffset % alignment);
}
-
+
dataMember = DataMember {
name = CopyString(name);
dataTypeString = CopyString(type);
}
return null;
}
-
-public dllexport DataMember eMember_AddDataMember(DataMember member, char * name, char * type, unsigned int size, unsigned int alignment, AccessMode declMode)
+ // F000F000 will mean a pointer size alignment
+public dllexport DataMember eMember_AddDataMember(DataMember member, const char * name, const char * type, unsigned int size, unsigned int alignment, AccessMode declMode)
{
- if(name && !member.membersAlpha.FindString(name))
+ if(name && !member.membersAlpha.FindString(name))
{
DataMember dataMember;
if(alignment)
{
+ bool pointerAlignment = alignment == 0xF000F000;
+ bool force64Bits = false; //(member._class.module.application.isGUIApp & 2) ? true : false;
+ bool force32Bits = false; //(member._class.module.application.isGUIApp & 4) ? true : false;
+ if(pointerAlignment) alignment = force64Bits ? 8 : force32Bits ? 4 : sizeof(void *);
+
+ if(pointerAlignment && member.structAlignment <= 4)
+ member.pointerAlignment = 1;
+ else if(!pointerAlignment && alignment >= 8)
+ member.pointerAlignment = 0;
+
member.structAlignment = Max(member.structAlignment, alignment);
if(member.memberOffset % alignment)
DataMember dataMember;
member._class = _class;
for(dataMember = member.members.first; dataMember; dataMember = dataMember.next)
- SetMemberClass(dataMember, _class);
+ SetMemberClass(dataMember, _class);
}
public dllexport bool eMember_AddMember(DataMember addTo, DataMember dataMember)
{
- if(dataMember.name && addTo.membersAlpha.FindString(dataMember.name)) return false;
+ if(dataMember.name && addTo.membersAlpha.FindString(dataMember.name))
+ {
+ DataMember_Free(dataMember);
+ delete dataMember;
+ return false;
+ }
addTo.members.Add(dataMember);
if(dataMember.name)
else
addTo.memberID += dataMember.memberID;
+ if(dataMember.pointerAlignment && dataMember.structAlignment <= 4)
+ addTo.pointerAlignment = 1;
+ else if(!dataMember.pointerAlignment && dataMember.structAlignment >= 8)
+ addTo.pointerAlignment = 0;
+
addTo.structAlignment = Max(addTo.structAlignment, dataMember.structAlignment);
+
dataMember.offset = (addTo.type == unionMember) ? 0 : addTo.memberOffset;
+
+ if(dataMember.structAlignment)
+ {
+ if(addTo.memberOffset % dataMember.structAlignment)
+ addTo.memberOffset += dataMember.structAlignment - (addTo.memberOffset % dataMember.structAlignment);
+ }
+
if(addTo.type == unionMember)
{
if(dataMember.memberOffset > addTo.memberOffset)
public dllexport bool eClass_AddMember(Class _class, DataMember dataMember)
{
if(!_class || _class.comRedefinition || (dataMember.name && _class.members.FindString(dataMember.name)))
+ {
+ DataMember_Free(dataMember);
+ delete dataMember;
return false;
+ }
_class.membersAndProperties.Add(dataMember);
if(dataMember.name)
//dataMember.id = _class.memberID++;
dataMember.id = _class.memberID;
+ if(dataMember.pointerAlignment && dataMember.structAlignment <= 4)
+ _class.pointerAlignment = 1;
+ else if(!dataMember.pointerAlignment && dataMember.structAlignment >= 8)
+ _class.pointerAlignment = 0;
+
_class.structAlignment = Max(_class.structAlignment, dataMember.structAlignment);
if(dataMember.type == unionMember)
_class.memberID += 1;
else
_class.memberID += dataMember.memberID;
+
+ if(dataMember.structAlignment)
+ {
+ if(_class.memberOffset % dataMember.structAlignment)
+ _class.memberOffset += dataMember.structAlignment - (_class.memberOffset % dataMember.structAlignment);
+ }
+
dataMember.offset = _class.memberOffset;
_class.memberOffset += dataMember.memberOffset;
return true;
}
-public dllexport BitMember eClass_AddBitMember(Class _class, char * name, char * type, int bitSize, int bitPos, AccessMode declMode)
+public dllexport BitMember eClass_AddBitMember(Class _class, const char * name, const char * type, int bitSize, int bitPos, AccessMode declMode)
{
- if(_class && name && !_class.members.FindString(name))
+ if(_class && name && !_class.members.FindString(name))
{
uint64 mask = 0;
int c;
return null;
}
-static Module Module_Load(Module fromModule, char * name, AccessMode importAccess, bool ensureCOM)
+static Module Module_Load(Module fromModule, const char * name, AccessMode importAccess, bool ensureCOM)
{
bool (stdcall * Load)(Module module) = null;
bool (stdcall * Unload)(Module module) = null;
}
else
{
- char * libLocation = null;
+ const char * libLocation = null;
#if defined(__ANDROID__)
libLocation = AndroidInterface_GetLibLocation();
#endif
module = (Module)eInstance_New(eSystem_FindClass(fromModule, "Module"));
module.application = fromModule.application;
module.library = library;
- module.name = CopyString(name);
+ {
+ char moduleName[MAX_FILENAME];
+ char ext[MAX_EXTENSION];
+ GetLastDirectory(name, moduleName);
+ GetExtension(moduleName, ext);
+ StripExtension(moduleName);
+ if((!strcmpi(ext, "dylib") || !strcmpi(ext, "so")) && strstr(moduleName, "lib") == moduleName)
+ {
+ int len = (int)strlen(moduleName) - 3;
+ memmove(moduleName, moduleName + 3, len);
+ moduleName[len] = 0;
+ }
+ module.name = CopyString(moduleName);
+ }
module.Unload = Unload;
module.origImportType = normalImport;
if(ensureCOM && !strcmp(name, "ecere") && module)
{
name = !strcmp(module.name, "ecereCOM") ? "ecere" : "ecereCOM";
- if((!Load && !strcmp(module.name, "ecereCOM")) ||
- (Load && (!__thisModule || !__thisModule.name || !strcmp(__thisModule.name, "ecereCOM")) && Load != COM_LOAD_FUNCTION))
+ if((!Load && !strcmp(module.name, "ecereCOM")) ||
+ (Load && (!__thisModule || !__thisModule.name || !strcmp(__thisModule.name, "ecereCOM")) && Load != (void *)COM_LOAD_FUNCTION))
{
Module module;
for(module = fromModule.application.allModules.first; module; module = module.next)
return module;
}
-public dllexport Module eModule_Load(Module fromModule, char * name, AccessMode importAccess)
+public dllexport Module eModule_Load(Module fromModule, const char * name, AccessMode importAccess)
{
return Module_Load(fromModule, name, importAccess, true);
}
-public dllexport Module eModule_LoadStrict(Module fromModule, char * name, AccessMode importAccess)
+public dllexport Module eModule_LoadStrict(Module fromModule, const char * name, AccessMode importAccess)
{
return Module_Load(fromModule, name, importAccess, false);
}
-public dllexport Module eModule_LoadStatic(Module fromModule, char * name, AccessMode importAccess, bool (* Load)(Module module), bool (* Unload)(Module module))
+public dllexport Module eModule_LoadStatic(Module fromModule, const char * name, AccessMode importAccess, bool (* Load)(Module module), bool (* Unload)(Module module))
{
Module module;
for(module = fromModule.application.allModules.first; module; module = module.next)
}
}
-public dllexport void eEnum_AddFixedValue(Class _class, char * string, int value)
+public dllexport void eEnum_AddFixedValue(Class _class, const char * string, int64 value)
{
if(_class && _class.type == enumClass)
{
EnumClassData data = (EnumClassData)_class.data;
- NamedLink item;
-
+ NamedLink64 item;
+
for(item = data.values.first; item; item = item.next)
- if(!strcmp(item.name, string))
+ if(!strcmp(item.name, string))
break;
if(!item)
{
- data.values.Add(NamedLink { data = (void *)value, name = CopyString(string) });
+ data.values.Add(NamedLink64 { data = value, name = CopyString(string) });
if(value > data.largest)
data.largest = value;
}
}
}
-public dllexport int eEnum_AddValue(Class _class, char * string)
+public dllexport int64 eEnum_AddValue(Class _class, const char * string)
{
if(_class && _class.type == enumClass)
{
EnumClassData data = (EnumClassData)_class.data;
- int value = ((int) data.largest) + 1;
- NamedLink item;
+ int64 value = data.largest + 1;
+ NamedLink64 item;
for(item = data.values.first; item; item = item.next)
- if(!strcmp(item.name, string))
+ if(!strcmp(item.name, string))
break;
if(!item)
{
- data.values.Add(NamedLink { data = (void *)value, name = CopyString(string) });
+ data.values.Add(NamedLink64 { data = value, name = CopyString(string) });
if(value > data.largest)
data.largest = value;
return value;
static void NameSpace_Free(NameSpace parentNameSpace)
{
NameSpace * nameSpace;
- delete parentNameSpace.name;
+ delete (void *)parentNameSpace.name;
+
+ /* {
+ BTNamedLink n, next;
+ for(n = (BTNamedLink)parentNameSpace.classes.first; n; n = next)
+ {
+ Class c = n.data;
+
+ next = (BTNamedLink)((BTNode)n).next;
+
+ if(c.templateClass)
+ eClass_Unregister(c);
+ }
+ } */
while((nameSpace = (NameSpace *)parentNameSpace.nameSpaces.first))
{
{
if(app.parsedCommand)
{
- delete app.argv;
+ delete (void *)app.argv;
delete app.parsedCommand;
}
}
while((handle = module.modules.last)) // STARTING WITH LAST SO THAT ecereCOM IS UNLOADED LAST...
{
Module depModule = handle.module;
- if(depModule == ourWorld)
+ if(depModule == ourWorld)
{
module.modules.Remove(handle);
ourHandle = handle;
{
module.modules.Delete(handle);
delete depModule;
- }
+ }
}
if(ourHandle)
{
if(_class.nameSpace)
{
BTNamedLink classLink = (BTNamedLink)_class.nameSpace->classes.FindString(_class.name);
- OldLink t;
- for(t = _class.templatized.first; t; t = t.next)
+ if(classLink)
{
- Class template = t.data;
- BTNamedLink link;
- link = (BTNamedLink)template.nameSpace->classes.FindString(template.name);
+ OldLink t;
+ for(t = _class.templatized.first; t; t = t.next)
+ {
+ Class template = t.data;
+ BTNamedLink link;
+ link = (BTNamedLink)template.nameSpace->classes.FindString(template.name);
- template.nameSpace->classes.Delete((BTNode)link);
- template.nameSpace = null;
+ template.nameSpace->classes.Delete((BTNode)link);
+ template.nameSpace = null;
+ }
+ _class.nameSpace->classes.Delete((BTNode)classLink);
}
- _class.nameSpace->classes.Delete((BTNode)classLink);
+#ifdef _DEBUG
+ else
+ {
+ printf("Warning: Could not find %s in namespace classes while destructing module %s\n", _class.name, module.name);
+ }
+#endif
_class.nameSpace = null;
}
_class.module = null;
module.classes.Remove(_class);
- if(!_class.count || _class.type != normalClass)
+ if(_class.count <= 0 || _class.type != normalClass || _class.isInstanceClass)
eClass_Unregister(_class);
else
{
break;
}
}
- delete def.name;
- delete def.value;
+ delete (void *)def.name;
+ delete (void *)def.value;
module.defines.Delete(def);
}
break;
}
}
- delete function.name;
- delete function.dataTypeString;
+ delete (void *)function.name;
+ delete (void *)function.dataTypeString;
module.functions.Delete(function);
}
- delete module.name;
+ delete (void *)module.name;
NameSpace_Free(module.privateNameSpace);
NameSpace_Free(module.publicNameSpace);
#endif
}
-static int GetEnumSize(Class _class)
+static int64 GetEnumSize(Class _class)
{
EnumClassData data = (EnumClassData)_class.data;
return data.largest+1;
}
#endif
-public dllexport DefinedExpression eSystem_RegisterDefine(char * name, char * value, Module module, AccessMode declMode)
+public dllexport DefinedExpression eSystem_RegisterDefine(const char * name, const char * value, Module module, AccessMode declMode)
{
NameSpace * nameSpace = null;
-
+
int start = 0, c;
nameSpace = (declMode == publicAccess) ? &module.publicNameSpace : &module.privateNameSpace;
delete spaceName;
nameSpace = newSpace;
if(name[c] == ':') c++;
- start = c+1;
+ start = c+1;
}
}
}
else
- c = strlen(name);
+ c = (int)strlen(name);
if(c - start && !nameSpace->defines.FindString(name + start))
{
return null;
}
-public dllexport GlobalFunction eSystem_RegisterFunction(char * name, char * type, void * func, Module module, AccessMode declMode)
+public dllexport GlobalFunction eSystem_RegisterFunction(const char * name, const char * type, void * func, Module module, AccessMode declMode)
{
NameSpace * nameSpace = null;
int start = 0, c;
delete spaceName;
nameSpace = newSpace;
if(name[c] == ':') c++;
- start = c+1;
+ start = c+1;
}
}
}
else
- c = strlen(name);
+ c = (int)strlen(name);
if(c - start && !nameSpace->functions.FindString(name + start))
{
return null;
}
-public dllexport DefinedExpression eSystem_FindDefine(Module module, char * name)
+public dllexport DefinedExpression eSystem_FindDefine(Module module, const char * name)
{
if(name && module)
{
return null;
}
-public dllexport GlobalFunction eSystem_FindFunction(Module module, char * name)
+public dllexport GlobalFunction eSystem_FindFunction(Module module, const char * name)
{
if(name && module)
{
}
}
-public dllexport void eProperty_SelfWatch(Class _class, char * name, void (*callback)(void *))
+public dllexport void eProperty_SelfWatch(Class _class, const char * name, void (*callback)(void *))
{
if(_class)
{
Property _property = eClass_FindProperty(_class, name, _class.module);
-
+
if(!_property)
_property = eClass_AddProperty(_class, name, null, null, null, baseSystemAccess /*privateAccess*/);
_class.selfWatchers.Add(SelfWatcher { _property = _property, callback = callback });
}
}
-public dllexport void eInstance_WatchDestruction(Instance instance, Instance object, void (*callback)(Instance, Instance))
+public dllexport void eInstance_WatchDestruction(Instance instance, Instance object, void (*callback)(void *, void *))
{
OldList * watchers = (OldList *)((byte *)instance + instance._class.destructionWatchOffset);
watchers->Add(Watcher { callback = callback, object = object });
}
}
base = _class.base;
- if(base && base.type == systemClass) base = null;
+ if(base && (base.type == systemClass || base.isInstanceClass)) base = null;
}
}
}
return null;
}
-public bool LocateModule(char * name, char * fileName)
+public bool LocateModule(const char * name, const char * fileName)
{
return Instance_LocateModule(name, fileName);
}
+/*
+#if (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__)
+#define _64BIT 1
+#else
+#define _64BIT 0
+#endif
+
+#define arch_PointerSize sizeof(void *)
+#define structSize_Instance (_64BIT ? 24 : 12)
+#define structSize_Module (_64BIT ? 560 : 300)
+#define structSize_BinaryTree (_64BIT ? 32 : 16)
+#define structSize_OldList (_64BIT ? 32 : 20)
+#define structSize_NamedLink64 (_64BIT ? 32 : 24)
+#define structSize_ClassTemplateArgument (_64BIT ? 16 : 8)
+#define structSize_ClassTemplateParameter (_64BIT ? 64 : 40)
+#define structSize_OldLink (_64BIT ? 24 : 12)
+#define structSize_BTNamedLink (_64BIT ? 48 : 24)
+#define structSize_Application (_64BIT ? 800 : 428)
+#define structSize_Watcher (_64BIT ? 32 : 16)
+#define structSize_SelfWatcher (_64BIT ? 32 : 16)
+#define structSize_GlobalFunction (_64BIT ? 72 : 36)
+#define structSize_DefinedExpression (_64BIT ? 40 : 20)
+#define structSize_BitMember (_64BIT ? 96 : 64)
+#define structSize_DataMember (_64BIT ? 160 : 96)
+#define structSize_ClassProperty (_64BIT ? 80 : 40)
+#define structSize_Method (_64BIT ? 96 : 52)
+#define structSize_Property (_64BIT ? 152 : 88)
+#define structSize_Class (_64BIT ? 624 : 376)
+*/
+
static void LoadCOM(Module module)
{
bool force64Bits = (module.application.isGUIApp & 2) ? true : false;
{
Class instanceClass = eSystem_RegisterClass(normalClass, "ecere::com::Instance", null, 0, 0, null, null, module, baseSystemAccess, publicAccess);
- // Instance should really be a Normal class, but inheritance checks for systemClass to see if something has a non system ancestor
- instanceClass.type = systemClass;
+ instanceClass.type = normalClass;
+ instanceClass.isInstanceClass = true;
instanceClass.fixed = true;
instanceClass.memberOffset = 0;
instanceClass.offset = 0;
instanceClass.memberID = -3;
instanceClass.startMemberID = -3;
- eClass_AddDataMember(instanceClass, "_vTbl", "int (**)()", pointerSize, pointerSize, publicAccess);
+ eClass_AddDataMember(instanceClass, "_vTbl", "void **", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(instanceClass, "_class", "ecere::com::Class", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(instanceClass, "_refCount", "int", sizeof(int), sizeof(int), publicAccess);
}
enumClass = eSystem_RegisterClass(normalClass, "enum", null, 0, force64Bits ? 40 : sizeof(class EnumClassData), null, null, module, baseSystemAccess, publicAccess);
eClass_AddClassProperty(enumClass, "enumSize", "int", null, GetEnumSize).constant = true;
enumClass.type = systemClass;
-
- delete enumClass.dataTypeString;
+
+ delete (void *)enumClass.dataTypeString;
enumClass.dataTypeString = CopyString(/*"unsigned int"*/"int");
// Create Struct (simple) class
sizeof(struct Module), 0, (void *)Module_Constructor, (void *)Module_Destructor, module, baseSystemAccess, publicAccess);
eClass_AddVirtualMethod(moduleClass, "OnLoad", "bool()", null, publicAccess);
eClass_AddVirtualMethod(moduleClass, "OnUnload", "void()", null, publicAccess);
- eClass_AddMethod(moduleClass, "Load", "Module(char * name, AccessMode importAccess)", eModule_Load, publicAccess);
+ eClass_AddMethod(moduleClass, "Load", "Module(const char * name, AccessMode importAccess)", eModule_Load, publicAccess);
eClass_AddMethod(moduleClass, "Unload", "void(Module module)", eModule_Unload, publicAccess);
eClass_AddDataMember(moduleClass, "application", "Application", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(moduleClass, "classes", "OldList", force64Bits ? 32 : force32Bits ? 20 : sizeof(OldList), pointerSize, publicAccess);
eClass_AddDataMember(moduleClass, "modules", "OldList", force64Bits ? 32 : force32Bits ? 20 : sizeof(OldList), pointerSize, publicAccess);
eClass_AddDataMember(moduleClass, "prev", "Module", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(moduleClass, "next", "Module", pointerSize, pointerSize, publicAccess);
- eClass_AddDataMember(moduleClass, "name", "char *", pointerSize, pointerSize, publicAccess);
+ eClass_AddDataMember(moduleClass, "name", "const char *", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(moduleClass, "library", "void *", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(moduleClass, "Unload", "void *", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(moduleClass, "importType", "ImportType", sizeof(ImportType), 4, publicAccess);
moduleClass.count++;
if(inCompiler && force32Bits)
moduleClass.structSize = 12 + 4 + 20 + 20 + 20 + 20 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + (16 + 4 + 4 + 4*16) + (16 + 4 + 4 + 4*16);
-
+
// Create Application class
applicationClass = eSystem_RegisterClass(normalClass, "ecere::com::Application", "Module", force64Bits ? (8+8+4+4 + 32 + 8 + 176) : sizeof(struct Application), 0, null, (void *)Application_Destructor, module, baseSystemAccess, publicAccess);
if(inCompiler && force32Bits)
}
eClass_AddVirtualMethod(applicationClass, "Main", "void()", null, publicAccess);
eClass_AddDataMember(applicationClass, "argc", "int", sizeof(int), 4, publicAccess);
- eClass_AddDataMember(applicationClass, "argv", "char **", pointerSize, pointerSize, publicAccess);
+ eClass_AddDataMember(applicationClass, "argv", "const char **", pointerSize, pointerSize, publicAccess);
eClass_AddDataMember(applicationClass, "exitCode", "int", sizeof(int), 4, publicAccess);
eClass_AddDataMember(applicationClass, "isGUIApp", "bool", sizeof(bool), 4, publicAccess);
eClass_AddDataMember(applicationClass, "allModules", "OldList", force64Bits ? 32 : force32Bits ? 20 : sizeof(OldList), pointerSize, publicAccess);
eSystem_RegisterFunction("asin", "Angle asin(double number)", asin, module, baseSystemAccess);
eSystem_RegisterFunction("acos", "Angle acos(double number)", acos, module, baseSystemAccess);
eSystem_RegisterFunction("atan", "Angle atan(double number)", atan, module, baseSystemAccess);
+ eSystem_RegisterFunction("asinh", "Angle asinh(double number)", asinh, module, baseSystemAccess);
+ eSystem_RegisterFunction("acosh", "Angle acosh(double number)", acosh, module, baseSystemAccess);
+ eSystem_RegisterFunction("atanh", "Angle atanh(double number)", atanh, module, baseSystemAccess);
eSystem_RegisterFunction("pow", "double pow(double number, double number2)", pow, module, baseSystemAccess);
eSystem_RegisterFunction("fmod", "double fmod(double x, double y)", fmod, module, baseSystemAccess);
eSystem_RegisterFunction("fabs", "double fabs(double number)", fabs, module, baseSystemAccess);
// --- Stdlib ---
eSystem_RegisterFunction("qsort", "void qsort(void *, uintsize, uintsize, int (*)(void *, void *))", qsort, module, baseSystemAccess);
- eSystem_RegisterFunction("strtod", "double strtod(char*, char**)", strtod, module, baseSystemAccess);
- eSystem_RegisterFunction("strtol", "int strtol(char*, char**, int base)", strtol, module, baseSystemAccess);
+ eSystem_RegisterFunction("strtod", "double strtod(const char*, char**)", strtod, module, baseSystemAccess);
+ eSystem_RegisterFunction("strtol", "int strtol(const char*, char**, int base)", strtol, module, baseSystemAccess);
+ eSystem_RegisterFunction("strtoul", "unsigned long strtoul(const char * nptr, char ** endptr, int base)", strtoul, module, baseSystemAccess);
+ eSystem_RegisterFunction("strtoll", "int64 strtoll(const char * nptr, char ** endptr, int base)", strtoll, module, baseSystemAccess);
+ eSystem_RegisterFunction("strtoull", "uint64 strtoull(const char * nptr, char ** endptr, int base)", strtoull, module, baseSystemAccess);
eSystem_RegisterFunction("system", "int system(const char*)", system, module, baseSystemAccess);
eSystem_RegisterFunction("atoi", "int atoi(const char*)", atoi, module, baseSystemAccess);
- eSystem_RegisterFunction("atof", "float atof(const char*)", atof, module, baseSystemAccess);
- eSystem_RegisterFunction("tolower", "int tolower(int)", tolower, module, baseSystemAccess);
- eSystem_RegisterFunction("toupper", "int toupper(int)", toupper, module, baseSystemAccess);
- eSystem_RegisterFunction("isdigit", "bool isdigit(int)", isdigit, module, baseSystemAccess);
+ eSystem_RegisterFunction("atof", "double atof(const char*)", atof, module, baseSystemAccess);
eSystem_RegisterFunction("memset", "void * memset(void * area, int value, uintsize count)", memset, module, baseSystemAccess);
eSystem_RegisterFunction("getenv", "char * getenv(const char * name)", getenv, module, baseSystemAccess);
eSystem_RegisterFunction("rename", "int rename(const char *oldpath, const char *newpath)", rename, module, baseSystemAccess);
eSystem_RegisterFunction("strncat", "char * strncat(char *, const char *, uintsize n)", strncat, module, baseSystemAccess);
eSystem_RegisterFunction("strchr", "char * strchr(const char *, int)", strchr, module, baseSystemAccess);
eSystem_RegisterFunction("strstr", "char * strstr(const char *, const char *)", strstr, module, baseSystemAccess);
+ eSystem_RegisterFunction("strspn", "uintsize strspn(const char *, const char *)", strspn, module, baseSystemAccess);
+ eSystem_RegisterFunction("strcspn", "uintsize strcspn(const char *, const char *)", strcspn, module, baseSystemAccess);
+ eSystem_RegisterFunction("strpbrk", "char * strpbrk(const char *, const char *)", strpbrk, module, baseSystemAccess);
- eSystem_RegisterDefine("fstrcmp", "(GetRuntimePlatform() == win32) ? strcmpi : strcmp", module, baseSystemAccess);
+ eSystem_RegisterDefine("fstrcmp", "(__runtimePlatform == win32) ? strcmpi : strcmp", module, baseSystemAccess);
//#if defined(__GNUC__)
eSystem_RegisterDefine("strcmpi", "strcasecmp", module, baseSystemAccess);
eSystem_RegisterFunction("strncpy", "char * strncpy(char *, const char *, uintsize n)", strncpy, module, baseSystemAccess);
eSystem_RegisterFunction("memcpy", "void * memcpy(void *, const void *, uintsize size)", memcpy, module, baseSystemAccess);
eSystem_RegisterFunction("memmove", "void * memmove(void *, const void *, uintsize size)", memmove, module, baseSystemAccess);
+ eSystem_RegisterFunction("memcmp", "int memcmp(const void *, const void *, uintsize size)", memcmp, module, baseSystemAccess);
// --- Stdio ---
- eSystem_RegisterFunction("sprintf", "int sprintf(char *, char *, ...)", sprintf, module, baseSystemAccess);
- eSystem_RegisterFunction("snprintf", "int sprintf(char *, uintsize, char *, ...)", snprintf, module, baseSystemAccess);
- eSystem_RegisterFunction("printf", "int printf(char *, ...)", printf, module, baseSystemAccess);
+ eSystem_RegisterFunction("sprintf", "int sprintf(char *, const char *, ...)", sprintf, module, baseSystemAccess);
+ eSystem_RegisterFunction("snprintf", "int sprintf(char *, uintsize, const char *, ...)", snprintf, module, baseSystemAccess);
+ eSystem_RegisterFunction("printf", "int printf(const char *, ...)", printf, module, baseSystemAccess);
eSystem_RegisterFunction("vsprintf", "int vsprintf(char*, const char*, __builtin_va_list)", vsprintf, module, baseSystemAccess);
eSystem_RegisterFunction("vsnprintf", "int vsnprintf(char*, uintsize, const char*, __builtin_va_list)", vsnprintf, module, baseSystemAccess);
- eSystem_RegisterFunction("puts", "int puts(char *)", puts, module, baseSystemAccess);
- eSystem_RegisterFunction("fputs", "int fputs(char *, void * stream)", fputs, module, baseSystemAccess);
+ eSystem_RegisterFunction("puts", "int puts(const char *)", puts, module, baseSystemAccess);
+ eSystem_RegisterFunction("fputs", "int fputs(const char *, void * stream)", fputs, module, baseSystemAccess);
// --- Ctype ---
+ eSystem_RegisterFunction("tolower", "int tolower(int)", tolower, module, baseSystemAccess);
+ eSystem_RegisterFunction("toupper", "int toupper(int)", toupper, module, baseSystemAccess);
+ eSystem_RegisterFunction("isdigit", "bool isdigit(int)", isdigit, module, baseSystemAccess);
+ eSystem_RegisterFunction("isxdigit","bool isxdigit(int)", isxdigit, module, baseSystemAccess);
eSystem_RegisterFunction("isalnum", "int isalnum(int c)", isalnum, module, baseSystemAccess);
eSystem_RegisterFunction("isspace", "int isspace(int c)", isspace, module, baseSystemAccess);
eSystem_RegisterFunction("isalpha", "int isalpha(int c)", isalpha, module, baseSystemAccess);
eSystem_RegisterFunction("islower", "int islower(int c)", islower, module, baseSystemAccess);
eSystem_RegisterFunction("isupper", "int isupper(int c)", isupper, module, baseSystemAccess);
eSystem_RegisterFunction("isprint", "int isprint(int c)", isprint, module, baseSystemAccess);
- eSystem_RegisterFunction("strtoul", "unsigned long strtoul(const char * nptr, char ** endptr, int base)", strtoul, module, baseSystemAccess);
+ eSystem_RegisterFunction("isblank", "int isblank(int c)", isblank, module, baseSystemAccess);
}
Instance_COM_Initialize(argc, argv, &app.parsedCommand, &app.argc, &app.argv);
app.application = app;
- app.allModules.offset = sizeof(class Instance) + (uint)&((struct Module *)0)->prev;
+ app.allModules.offset = sizeof(class Instance) + (uint)(uintptr)&((struct Module *)0)->prev;
app.isGUIApp = guiApp;
LoadCOM(app);
return app;
}
-public dllexport ClassTemplateParameter eClass_AddTemplateParameter(Class _class, char * name, TemplateParameterType type, void * info, ClassTemplateArgument defaultArg)
+public dllexport ClassTemplateParameter eClass_AddTemplateParameter(Class _class, const char * name, TemplateParameterType type, const void * info, ClassTemplateArgument defaultArg)
{
if(_class && name)
{
type = type;
(type == identifier) ? info : CopyString(info);
};
- if(defaultArg != null)
+ if(defaultArg != null)
{
param.defaultArg = defaultArg;
CopyTemplateArg(param, param.defaultArg);
{
if(base)
{
- OldLink derivative;
ClassTemplateParameter param;
{
void * first = base.templateParams.first;
int count = base.templateParams.count;
- base.templateParams.first = null;
- base.templateParams.count = 0;
FreeTemplateArgs(base);
delete base.templateArgs;
+
+ base.templateParams.first = null;
+ base.templateParams.count = 0;
+
FreeTemplatesDerivatives(base);
base.templateParams.first = first;
if(param.type == identifier && param.defaultArg.memberString)
{
Class memberClass = base;
- char * colon = strstr(param.defaultArg.memberString, "::");
- char * memberName;
+ const char * colon = strstr(param.defaultArg.memberString, "::");
+ const char * memberName;
if(colon)
{
char className[1024];
}
}
}
- }
+ }
//ComputeClassParameters(base, null, null);
{
unknown, win32, tux, apple;
- property char *
+ property const char *
{
get { return OnGetString(null, null, null); }
set
- {
+ {
if(value)
{
Platform c;
}
};
- char * OnGetString(char * tempString, void * fieldData, bool * needClass)
+ const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
{
if(this >= firstPlatform && this <= lastPlatform)
{
tempString[0] = '\0';
return null;
}
-
- bool OnGetDataFromString(char * string)
+
+ bool OnGetDataFromString(const char * string)
{
this = string;
- return (bool)this;
+ return this != unknown;
}
};
OldList instances;
ClassDefinition classDefinition;
bool modified;
+ void * i18nStrings;
};
public class DesignerBase : Window
{
public:
- virtual bool FindObject(Instance * instance, char * string);
- virtual void RenameObject(ObjectInfo object, char * name);
+ virtual bool FindObject(Instance * instance, const char * string);
+ virtual void RenameObject(ObjectInfo object, const char * name);
virtual void SelectObjectFromDesigner(ObjectInfo object);
virtual void CodeAddObject(Instance instance, ObjectInfo * object);
virtual void SheetAddObject(ObjectInfo object);
virtual void UpdateProperties(void);
ClassDesignerBase classDesigner;
- char * objectClass;
+ const char * objectClass;
bool isDragging;
// FIX THIS WITH PUBLIC:
property ClassDesignerBase classDesigner
- {
+ {
get { return classDesigner; }
set { classDesigner = value; }
};
- property char * objectClass
- {
+ property const char * objectClass
+ {
get { return objectClass; }
set { objectClass = value; }
};
property bool isDragging
- {
+ {
get { return isDragging; }
set { isDragging = value; }
};
}
-
+
public class ClassDesignerBase : Window
{
public:
virtual void ::DroppedObject(Instance instance, ObjectInfo object, bool isClass, Instance _class);
virtual void ::DestroyObject(Instance object);
virtual void ::FixProperty(Property prop, Instance object);
- virtual void ::CreateNew(EditBox editBox, Size clientSize, char * name, char * inherit);
+ virtual void ::CreateNew(EditBox editBox, Size clientSize, const char * name, const char * inherit);
}
DesignerBase activeDesigner;
return activeDesigner;
}
+
+bool poolingDisabled;
+
+public dllexport void eSystem_SetPoolingDisabled(bool disabled)
+{
+ poolingDisabled = disabled;
+}
+
namespace sys;
// constants
define LEAD_OFFSET = 0xD800 - (0x10000 >> 10);
define SURROGATE_OFFSET = 0x10000 - (0xD800 << 10) - 0xDC00;
-public bool UTF8Validate(char * source)
+public bool UTF8Validate(const char * source)
{
if(source)
{
}
if(i < numBytes) return false;
- if(codePoint > 0x10FFFF || (codePoint >= 0xD800 && codePoint <= 0xDFFF) ||
- (codePoint < 0x80 && numBytes > 1) ||
- (codePoint < 0x800 && numBytes > 2) ||
+ if(codePoint > 0x10FFFF || (codePoint >= 0xD800 && codePoint <= 0xDFFF) ||
+ (codePoint < 0x80 && numBytes > 1) ||
+ (codePoint < 0x800 && numBytes > 2) ||
(codePoint < 0x10000 && numBytes > 3))
return false;
}
return true;
}
-public int ISO8859_1toUTF8(char * source, char * dest, int max)
+public int ISO8859_1toUTF8(const char * source, char * dest, int max)
{
int c;
int d = 0;
+ byte * byteDest = (byte *)dest;
for(c = 0; source[c]; c++)
{
unichar ch = ((byte *)source)[c];
+ switch(ch)
+ {
+ case 150: ch = (unichar)0x2012; break;
+ }
if(ch < 0x80)
{
if(d + 1 >= max) break;
- dest[d++] = (char)ch;
+ byteDest[d++] = (char)ch;
}
else if(ch < 0x800)
{
if(d + 2 >= max) break;
- dest[d++] = 0xC0 | (byte)((ch & 0x7C0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xC0 | (byte)((ch & 0x7C0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
else if(ch < 0x10000)
{
if(d + 3 >= max) break;
- dest[d++] = 0xE0 | (byte)((ch & 0xF000) >> 12);
- dest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xE0 | (byte)((ch & 0xF000) >> 12);
+ byteDest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
else
{
if(d + 4 >= max) break;
- dest[d++] = 0xF0 | (byte)((ch & 0x1C0000) >> 18);
- dest[d++] = 0x80 | (byte)((ch & 0x3F000) >> 12);
- dest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xF0 | (byte)((ch & 0x1C0000) >> 18);
+ byteDest[d++] = 0x80 | (byte)((ch & 0x3F000) >> 12);
+ byteDest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
}
dest[d] = 0;
return d;
}
-public char * UTF16toUTF8(uint16 * source)
+public char * UTF16toUTF8(const uint16 * source)
{
int c;
int d = 0;
int len;
- char * dest;
+ byte * dest;
uint16 u16;
bool invert = false;
for(len = 0; source[len]; len++);
- dest = new char[len * 3 + 1];
+ dest = new byte[len * 3 + 1];
for(c = 0; (u16 = source[c]); c++)
{
unichar ch;
continue;
}
if(invert) { u16 = ((u16 & 0xFF00) >> 8) | ((u16 & 0x00FF) << 8); }
-
+
if(u16 < 0xD800 || u16 > 0xDBFF)
- ch = (unichar)u16;
+ ch = (unichar)u16;
else
ch = ((unichar)u16 << 10) + source[c++] + SURROGATE_OFFSET;
-
+
if(ch < 0x80)
{
dest[d++] = (char)ch;
}
}
dest[d] = 0;
- dest = renew dest char[d+1];
- return dest;
+ dest = renew dest byte[d+1];
+ return (char *)dest;
}
-public int UTF16toUTF8Buffer(uint16 * source, byte * dest, int max)
+public int UTF16toUTF8Buffer(const uint16 * source, char * dest, int max)
{
int c;
int d = 0;
uint16 u16;
+ byte * byteDest = (byte *)dest;
for(c = 0; (u16 = source[c]); c++)
{
unichar ch;
if(u16 < 0xD800 || u16 > 0xDBFF)
- ch = (unichar)u16;
+ ch = (unichar)u16;
else
ch = ((unichar)u16 << 10) + source[c++] + SURROGATE_OFFSET;
if(ch < 0x80)
{
if(d + 1 >= max) break;
- dest[d++] = (char)ch;
+ byteDest[d++] = (char)ch;
}
else if(ch < 0x800)
{
if(d + 2 >= max) break;
- dest[d++] = 0xC0 | (byte)((ch & 0x7C0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xC0 | (byte)((ch & 0x7C0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
else if(ch < 0x10000)
{
if(d + 3 >= max) break;
- dest[d++] = 0xE0 | (byte)((ch & 0xF000) >> 12);
- dest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xE0 | (byte)((ch & 0xF000) >> 12);
+ byteDest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
else
{
if(d + 4 >= max) break;
- dest[d++] = 0xF0 | (byte)((ch & 0x1C0000) >> 18);
- dest[d++] = 0x80 | (byte)((ch & 0x3F000) >> 12);
- dest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xF0 | (byte)((ch & 0x1C0000) >> 18);
+ byteDest[d++] = 0x80 | (byte)((ch & 0x3F000) >> 12);
+ byteDest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
}
- dest[d] = 0;
+ byteDest[d] = 0;
return d;
}
-public unichar UTF8GetChar(char * string, int * numBytes)
+// NOTE: UTF8GetChar now returns 0 into numBytes for the null-terminating character ('\0')
+public unichar UTF8GetChar(const char * string, int * numBytes)
{
unichar ch;
byte b = ((byte *)string)[0];
}
}
- if(i < nb ||
- ch > 0x10FFFF || (ch >= 0xD800 && ch <= 0xDFFF) ||
- (ch < 0x80 && nb > 1) ||
- (ch < 0x800 && nb > 2) ||
+ if(i < nb ||
+ ch > 0x10FFFF || (ch >= 0xD800 && ch <= 0xDFFF) ||
+ (ch < 0x80 && nb > 1) ||
+ (ch < 0x800 && nb > 2) ||
(ch < 0x10000 && nb > 3))
{
ch = 0;
return ch;
}
-public int UTF8toUTF16Buffer(char * source, uint16 * dest, int max)
+public int UTF8toUTF16Buffer(const char * source, uint16 * dest, int max)
{
if(source)
{
if(codePoint > 0xFFFF)
{
uint16 lead = (uint16)(LEAD_OFFSET + (codePoint >> 10));
- uint16 trail = 0xDC00 + (uint16)(codePoint & 0x3FF);
+ uint16 trail = (uint16)(0xDC00 | (codePoint & 0x3FF));
if(d >= max - 1) break;
dest[d++] = lead;
dest[d++] = trail;
dest[d] = 0;
return d;
}
- return 0;
+ return 0;
}
-public int UTF32toUTF8Len(unichar * source, int count, byte * dest, int max)
+public int UTF32toUTF8Len(const unichar * source, int count, char * dest, int max)
{
int c;
int d = 0;
uint32 ch;
+ byte * byteDest = (byte *)dest;
for(c = 0; c<count && (ch = source[c]); c++)
{
if(ch < 0x80)
{
if(d + 1 >= max) break;
- dest[d++] = (char)ch;
+ byteDest[d++] = (char)ch;
}
else if(ch < 0x800)
{
if(d + 2 >= max) break;
- dest[d++] = 0xC0 | (byte)((ch & 0x7C0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xC0 | (byte)((ch & 0x7C0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
else if(ch < 0x10000)
{
if(d + 3 >= max) break;
- dest[d++] = 0xE0 | (byte)((ch & 0xF000) >> 12);
- dest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xE0 | (byte)((ch & 0xF000) >> 12);
+ byteDest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
else
{
if(d + 4 >= max) break;
- dest[d++] = 0xF0 | (byte)((ch & 0x1C0000) >> 18);
- dest[d++] = 0x80 | (byte)((ch & 0x3F000) >> 12);
- dest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
- dest[d++] = 0x80 | (byte)(ch & 0x03F);
+ byteDest[d++] = 0xF0 | (byte)((ch & 0x1C0000) >> 18);
+ byteDest[d++] = 0x80 | (byte)((ch & 0x3F000) >> 12);
+ byteDest[d++] = 0x80 | (byte)((ch & 0xFC0) >> 6);
+ byteDest[d++] = 0x80 | (byte)(ch & 0x03F);
}
}
- dest[d] = 0;
+ byteDest[d] = 0;
return d;
}
-public uint16 * UTF8toUTF16(char * source, int * wordCount)
+public uint16 * UTF8toUTF16(const char * source, int * wordCount)
{
if(source)
{
- int len = strlen(source);
+ int len = (int)strlen(source);
uint16 * dest = new uint16[len + 1];
int c;
int d = 0;
if(codePoint > 0xFFFF)
{
uint16 lead = (uint16)(LEAD_OFFSET + (codePoint >> 10));
- uint16 trail = 0xDC00 + (uint16)(codePoint & 0x3FF);
+ uint16 trail = (uint16)(0xDC00 | (codePoint & 0x3FF));
dest[d++] = lead;
dest[d++] = trail;
}
}
namespace com;
+
+#if !defined(MEMINFO) && defined(MEMTRACKING)
+import "Map"
+
+Map<Class, int> blocksByClass { };
+Map<Class, uintsize> sizeByClass { };
+#endif
+
+public void queryMemInfo(char * string)
+{
+#if !defined(MEMINFO) && defined(MEMTRACKING) && !defined(DISABLE_MEMMGR)
+ char s[1024];
+ int p;
+ uint numBlocks = 0;
+ uintsize totalMemUsed = 0;
+ sprintf(s, "Total System Memory Usage: %.02f\n", TOTAL_MEM / 1048576.0f);
+ strcat(string, s);
+
+ for(p = 0; pools && p < NUM_POOLS; p++)
+ {
+ BlockPool * pool = &pools[p];
+ if(pool->totalSize)
+ {
+ numBlocks += pool->totalSize;
+ sprintf(s, "%8d bytes: %d blocks in %d parts (%.02f mb used; taking up %.02f mb space)\n",
+ pool->blockSize, pool->numBlocks, pool->numParts, pool->usedSpace / 1048576.0f, pool->totalSize * pool->blockSpace / 1048576.0f);
+ totalMemUsed += pool->usedSpace;
+ strcat(string, s);
+ }
+ }
+
+
+ blocksByClass.Free();
+ sizeByClass.Free();
+ memMutex.Wait();
+ for(p = 0; pools && p < NUM_POOLS; p++)
+ {
+ BlockPool * pool = &pools[p];
+ MemBlock block;
+ for(block = pool->first; block; block = block.next)
+ {
+ Class c = block._class;
+ blocksByClass[c]++;
+ sizeByClass[c] += block.size;
+ }
+ }
+ memMutex.Release();
+
+ //for(c : blocksByClass)
+ {
+ MapIterator<Class, int> it { map = blocksByClass };
+ while(it.Next())
+ {
+ int c = it.data;
+ Class _class = it.key; //&c;
+ uintsize size = sizeByClass[_class];
+ float totalSize = (float) size / 1048576.0f;
+ if(totalSize > 1)
+ {
+ sprintf(s, "%s (%d bytes): %d instances (%.02f mb used)\n", _class ? _class.name : "(none)", (int)size, c, totalSize);
+ strcat(string, s);
+ }
+ }
+ }
+
+ sprintf(s, "Non-pooled memory: %.02f\n", OUTSIDE_MEM / 1048576.0f);
+ strcat(string, s);
+ sprintf(s, "Total Memory in use: %.02f\n", (float)(totalMemUsed + OUTSIDE_MEM) / 1048576.0f);
+ strcat(string, s);
+
+ sprintf(s, "Total Blocks Count: %d (%.02f mb overhead)\n", numBlocks, (float)sizeof(struct MemBlock) * numBlocks / 1048576.0f);
+ strcat(string, s);
+#ifdef MEMORYGUARD
+ sprintf(s, "MemoryGuard: %d blocks (%.02f mb RedZone, %.02f mb MemInfo)\n", memBlocks.count,
+ numBlocks * 2 * REDZONE / 1048576.0f, sizeof(struct MemInfo) * memBlocks.count / 1048576.0f);
+ strcat(string, s);
+#endif
+#endif
+}