ecere/com/instance: Tweak to ensureCOM strategy for bindings
[sdk] / ecere / src / com / instance.ec
index 097b732..a96db41 100644 (file)
@@ -2,7 +2,14 @@
 
 namespace com;
 
-// #define DISABLE_MEMMGR
+#if defined(__ANDROID__)
+ #define DISABLE_MEMMGR
+#endif
+
+#if defined(__EMSCRIPTEN__)
+ #define DISABLE_MEMMGR
+ #define _NOMUTEX
+#endif
 
 import "BinaryTree"
 import "OldList"
@@ -22,9 +29,15 @@ import "dataTypes"
 
 #undef __BLOCKS__
 
-#if !defined(__EMSCRIPTEN__)
-#if !defined(ECERE_BOOTSTRAP)
+#if defined(ECERE_BOOTSTRAP)
+ #define _NOMUTEX
+#endif
+
+#if !defined(_NOMUTEX)
 import "Mutex"
+#else
+#if defined(MEMINFO)
+int GetCurrentThreadID() { return 0; }
 #endif
 #endif
 
@@ -51,7 +64,7 @@ import "Mutex"
 #endif
 
 #ifdef MEMINFO
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
 import "Thread"
 #endif
 static define MAX_MEMORY_LOC = 40;
@@ -101,7 +114,7 @@ private:
 
 #if defined(__ANDROID__)
 
-default const char * AndroidInterface_GetLibLocation();
+default const char * AndroidInterface_GetLibLocation(Module m);
 
 #include <android/log.h>
 #include <android/native_activity.h>
@@ -200,7 +213,7 @@ public dllexport void MemoryGuard_PushLoc(const char * loc)
 {
 #ifdef MEMINFO
    MemStack stack;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
    stack = (MemStack)memStacks.Find(GetCurrentThreadID());
@@ -212,7 +225,7 @@ public dllexport void MemoryGuard_PushLoc(const char * loc)
    }
    if(stack.pos < MAX_STACK_FRAMES)
       stack.frames[stack.pos++] = loc;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif
 #endif
@@ -222,7 +235,7 @@ public dllexport void MemoryGuard_PopLoc()
 {
 #ifdef MEMINFO
    MemStack stack;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
    stack = (MemStack)memStacks.Find(GetCurrentThreadID());
@@ -230,7 +243,7 @@ public dllexport void MemoryGuard_PopLoc()
    {
       stack.pos--;
    }
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif
 #endif
@@ -377,6 +390,7 @@ public:
    int numParams;       // TOTAL number of params including all base classes; use templateParams.count for this level
    bool isInstanceClass;
    bool byValueSystemClass;
+   void * bindingsClass;
 
    property const char *
    {
@@ -699,7 +713,7 @@ static class MemInfo : BTNode //struct
          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 (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__) || defined(_M_X64) || defined(_WIN64) || defined(__LP64__) || defined(__LLP64__)
          if(allocLoc[c] && allocLoc[c] != (void *)0xabababababababab)
 #else
          if(allocLoc[c] && allocLoc[c] != (void *)0xabababab)
@@ -732,7 +746,7 @@ static uint TOTAL_MEM = 0;
 static uint OUTSIDE_MEM = 0;
 #endif
 
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
 #if !defined(ECERE_BOOTSTRAP)
 static Mutex memMutex { };
 #endif
@@ -1460,7 +1474,7 @@ static void * _malloc(unsigned int size)
    void * pointer;
 
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
 
@@ -1487,7 +1501,7 @@ static void * _malloc(unsigned int size)
                printf("      %s\n", stack.frames[c]);
 
          memoryErrorsCount++;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
          memMutex.Release();
 #endif
          return null;
@@ -1504,7 +1518,7 @@ static void * _malloc(unsigned int size)
    }
 #endif
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif
 
@@ -1527,7 +1541,7 @@ static void * _calloc(int n, unsigned int size)
 #else
    void * pointer;
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
 
@@ -1552,7 +1566,7 @@ static void * _calloc(int n, unsigned int size)
             if(stack.frames[c])
                printf("      %s\n", stack.frames[c]);
          memoryErrorsCount++;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
          memMutex.Release();
 #endif
          return null;
@@ -1571,7 +1585,7 @@ static void * _calloc(int n, unsigned int size)
    }
 #endif
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif
 
@@ -1595,7 +1609,7 @@ static void * _realloc(void * pointer, unsigned int size)
 #else
    if(!size) { _free(pointer); return null; }
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
 
@@ -1637,7 +1651,7 @@ static void * _realloc(void * pointer, unsigned int size)
          if(stack.frames[c])
             printf("      %s\n", stack.frames[c]);
       memoryErrorsCount++;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
       memMutex.Release();
 #endif
       return null;
@@ -1687,7 +1701,7 @@ static void * _realloc(void * pointer, unsigned int size)
    pointer = realloc(pointer, size);
 #endif
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif
    return pointer ? ((byte *)pointer + REDZONE) : null;
@@ -1708,7 +1722,7 @@ static void * _crealloc(void * pointer, unsigned int size)
 #else
    if(!size) { _free(pointer); return null; }
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
 
@@ -1750,7 +1764,7 @@ static void * _crealloc(void * pointer, unsigned int size)
          if(stack.frames[c])
             printf("      %s\n", stack.frames[c]);
       memoryErrorsCount++;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
       memMutex.Release();
 #endif
       return null;
@@ -1800,7 +1814,7 @@ static void * _crealloc(void * pointer, unsigned int size)
    pointer = crealloc(pointer, size);
 #endif
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif
    return pointer ? ((byte *)pointer + REDZONE) : null;
@@ -1814,7 +1828,7 @@ static void _free(void * pointer)
 #if defined(DISABLE_MEMMGR) && !defined(MEMINFO)
       free(pointer);
 #else
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
       if(memMutex != pointer) memMutex.Wait();
 #endif
 
@@ -1924,7 +1938,7 @@ static void _free(void * pointer)
       free(pointer);
 #endif
 
-#if !defined(ECERE_BOOTSTRAP) && !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
       if(memMutex != pointer) memMutex.Release();
 #endif
 
@@ -2076,7 +2090,7 @@ static void FixDerivativesBase(Class base, Class mod)
 {
    OldLink derivative;
 
-   ComputeClassParameters(base, strchr(base.name, '<'), null);
+   ComputeClassParameters(base, strchr(base.name, '<'), null, base.templateClass != mod);
 
    for(derivative = base.derivatives.first; derivative; derivative = derivative.next)
    {
@@ -2352,7 +2366,7 @@ static void FixDerivativesBase(Class base, Class mod)
          //const char * templateParams = strchr(template.name, '<');
          template.base = base.base;
          template._vTbl = base._vTbl;
-         //ComputeClassParameters(template, templateParams, null);
+         //ComputeClassParameters(template, templateParams, null, true);
 
          template.data = base.data;
          template.offset = base.offset;
@@ -2434,7 +2448,7 @@ public dllexport Class eSystem_RegisterClass(ClassType type, const char * name,
       Class _class = null;
       const char * dataTypeString = null;
       Class enumBase = null;
-      Class base = (baseName && baseName[0]) ? eSystem_FindClass(module, baseName) : null;
+      Class base = (baseName && baseName[0]) ? System_FindClass(module, baseName, true) : null;
       Class prevBase = null;
 
       if(base && !base.internalDecl && (base.type == noHeadClass || base.type == structClass || base.type == normalClass))
@@ -2549,13 +2563,13 @@ public dllexport Class eSystem_RegisterClass(ClassType type, const char * name,
       offsetClass = base ? base.sizeClass : (type == noHeadClass ? 0 : 0 /*sizeof(class Class)*/);
       totalSizeClass = offsetClass + sizeClass;
 
-      _class = eSystem_FindClass(module, name);
+      _class = System_FindClass(module, name, true);
       if(!_class)
       {
          const char * colons = RSearchString(name, "::", strlen(name), true, false);
          if(colons && colons)
          {
-            _class = eSystem_FindClass(module, colons + 2);
+            _class = System_FindClass(module, colons + 2, true);
             if(_class)
             {
                if(_class.internalDecl)
@@ -2682,13 +2696,13 @@ public dllexport Class eSystem_RegisterClass(ClassType type, const char * name,
                Class templateBase;
                strcpy(templateClassName, baseName);
                *strchr(templateClassName, '<') = '\0';
-               templateBase = eSystem_FindClass(module, templateClassName);
+               templateBase = System_FindClass(module, templateClassName, true);
                if(!templateBase)
                {
                   templateBase = eSystem_RegisterClass(0, templateClassName, null, 0,0, null, null, module, declMode, publicAccess);
                   templateBase.internalDecl = true;
                }
-               base = eSystem_FindClass(module, baseName);
+               base = System_FindClass(module, baseName, true);
             }
             else
             {
@@ -2814,7 +2828,8 @@ public dllexport Class eSystem_RegisterClass(ClassType type, const char * name,
                !strcmp(name, "LineStyle") ||
                !strcmp(name, "FillStyle") ||
                !strcmp(name, "FontObject") ||
-               !strcmp(name, "SymbolStyle"))
+               !strcmp(name, "FontObject") ||
+               !strcmp(name, "ecere::sys::Thread"))
             {
                _class.offset = force32Bits ? 24 : 12;
             }
@@ -2864,7 +2879,7 @@ public dllexport Class eSystem_RegisterClass(ClassType type, const char * name,
          }
          else if(type == bitClass || type == enumClass || type == unitClass)
          {
-            Class dataTypeClass = eSystem_FindClass(_class.module, dataTypeString);
+            Class dataTypeClass = System_FindClass(_class.module, dataTypeString, true);
             if(dataTypeClass)
                _class.typeSize = dataTypeClass.typeSize;
             _class.structSize = 0;
@@ -3395,6 +3410,11 @@ public uint64 _strtoui64(const char * string, const char ** endString, int base)
 
 public dllexport Class eSystem_FindClass(Module module, const char * name)
 {
+   return System_FindClass(module, name, false);
+}
+
+Class System_FindClass(Module module, const char * name, bool registerTemplatesInternalDecl)
+{
    if(name && module)
    {
       BTNamedLink link;
@@ -3459,7 +3479,7 @@ public dllexport Class eSystem_FindClass(Module module, const char * name)
 
                module.classes.Add(templatedClass);
 
-               ComputeClassParameters(templatedClass, templateParams, module);
+               ComputeClassParameters(templatedClass, templateParams, module, registerTemplatesInternalDecl);
 
                _class.templatized.Add(OldLink { data = templatedClass });
             }
@@ -3486,7 +3506,7 @@ static void CopyTemplateArg(ClassTemplateParameter param, ClassTemplateArgument
    }
 }
 
-static void ComputeClassParameters(Class templatedClass, const char * templateParams, Module findModule)
+static void ComputeClassParameters(Class templatedClass, const char * templateParams, Module findModule, bool registerInternalDecl)
 {
    char ch;
    const char * nextParamStart = templateParams ? (templateParams + 1) : null;
@@ -3692,16 +3712,28 @@ static void ComputeClassParameters(Class templatedClass, const char * templatePa
             {
                case type:
                   argument.dataTypeString = CopyString(value);
-                  argument.dataTypeClass = eSystem_FindClass(findModule, value);
+                  argument.dataTypeClass = System_FindClass(findModule, value, registerInternalDecl);
                   if(!argument.dataTypeClass)
-                     argument.dataTypeClass = eSystem_FindClass(_class.module, value);
+                     argument.dataTypeClass = System_FindClass(_class.module, value, registerInternalDecl);
                   if(!argument.dataTypeClass)
-                     argument.dataTypeClass = eSystem_FindClass(_class.module.application, value);
+                     argument.dataTypeClass = System_FindClass(_class.module.application, value, registerInternalDecl);
+                  if(registerInternalDecl && !argument.dataTypeClass)
+                  {
+                     ClassTemplateParameter param;
+                     for(param = templatedClass.templateParams.first; param; param = param.next)
+                        if(!strcmp(param.name, value))
+                           break;
+                     if(!param)
+                     {
+                        argument.dataTypeClass = eSystem_RegisterClass(0, value, null, 0,0, null, null, _class.module, publicAccess, publicAccess);
+                        argument.dataTypeClass.internalDecl = true;
+                     }
+                  }
                   break;
                case expression:
                {
-                  Class expClass = eSystem_FindClass(_class.module, curParam.dataTypeString);
-                  if(!expClass) expClass = eSystem_FindClass(_class.module.application, curParam.dataTypeString);
+                  Class expClass = System_FindClass(_class.module, curParam.dataTypeString, true);
+                  if(!expClass) expClass = System_FindClass(_class.module.application, curParam.dataTypeString, true);
                   if(expClass)
                   {
                      //if(expClass.type ==
@@ -3794,11 +3826,11 @@ static void ComputeClassParameters(Class templatedClass, const char * templatePa
             CopyTemplateArg(param, templatedClass.templateArgs[curParamID]);
             if(param.type == type && param.defaultArg.dataTypeString)
             {
-               templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(findModule, param.defaultArg.dataTypeString);
+               templatedClass.templateArgs[curParamID].dataTypeClass = System_FindClass(findModule, param.defaultArg.dataTypeString, true);
                if(!templatedClass.templateArgs[curParamID].dataTypeClass)
-                  templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module, param.defaultArg.dataTypeString);
+                  templatedClass.templateArgs[curParamID].dataTypeClass = System_FindClass(templatedClass.module, param.defaultArg.dataTypeString, true);
                if(!templatedClass.templateArgs[curParamID].dataTypeClass)
-                  templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module.application, param.defaultArg.dataTypeString);
+                  templatedClass.templateArgs[curParamID].dataTypeClass = System_FindClass(templatedClass.module.application, param.defaultArg.dataTypeString, true);
             }
          }
          curParamID++;
@@ -3922,11 +3954,11 @@ static void ComputeClassParameters(Class templatedClass, const char * templatePa
                      FreeTemplateArg(templatedClass, param, c);
 
                      arg->dataTypeString = CopyString(templateString);
-                     arg->dataTypeClass = eSystem_FindClass(findModule, templateString);
+                     arg->dataTypeClass = System_FindClass(findModule, templateString, true);
                      if(!arg->dataTypeClass)
-                        arg->dataTypeClass = eSystem_FindClass(templatedClass.module, templateString);
+                        arg->dataTypeClass = System_FindClass(templatedClass.module, templateString, true);
                      if(!arg->dataTypeClass)
-                        arg->dataTypeClass = eSystem_FindClass(templatedClass.module.application, templateString);
+                        arg->dataTypeClass = System_FindClass(templatedClass.module.application, templateString, true);
                   }
                   else
                   {
@@ -3977,11 +4009,11 @@ static void ComputeClassParameters(Class templatedClass, const char * templatePa
                CopyTemplateArg(param, templatedClass.templateArgs[curParamID]);
                if(param.type == type && param.defaultArg.dataTypeString)
                {
-                  templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(findModule, param.defaultArg.dataTypeString);
+                  templatedClass.templateArgs[curParamID].dataTypeClass = System_FindClass(findModule, param.defaultArg.dataTypeString, true);
                   if(!templatedClass.templateArgs[curParamID].dataTypeClass)
-                     templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module, param.defaultArg.dataTypeString);
+                     templatedClass.templateArgs[curParamID].dataTypeClass = System_FindClass(templatedClass.module, param.defaultArg.dataTypeString, true);
                   if(!templatedClass.templateArgs[curParamID].dataTypeClass)
-                     templatedClass.templateArgs[curParamID].dataTypeClass = eSystem_FindClass(templatedClass.module.application, param.defaultArg.dataTypeString);
+                     templatedClass.templateArgs[curParamID].dataTypeClass = System_FindClass(templatedClass.module.application, param.defaultArg.dataTypeString, true);
                }
             }
             curParamID++;
@@ -4080,11 +4112,11 @@ static void ComputeClassParameters(Class templatedClass, const char * templatePa
                      }
                   }
                   // TESTING: Added this here...
-                  memberClass = eSystem_FindClass(findModule, className);
+                  memberClass = System_FindClass(findModule, className, true);
                   if(!memberClass)
-                     memberClass = eSystem_FindClass(templatedClass.module, className);
+                     memberClass = System_FindClass(templatedClass.module, className, true);
                   if(!memberClass)
-                     memberClass = eSystem_FindClass(templatedClass.module.application, className);
+                     memberClass = System_FindClass(templatedClass.module.application, className, true);
                }
 
                if(memberClass)
@@ -4587,12 +4619,12 @@ public dllexport Method eClass_FindMethod(Class _class, const char * name, Modul
 }
 
 // Construct an instance
-static bool ConstructInstance(void * instance, Class _class, Class from)
+static bool ConstructInstance(void * instance, Class _class, Class from, bool bindingsAlloc)
 {
    if(_class.templateClass) _class = _class.templateClass;
    if(_class.base && from != _class.base)
    {
-      if(!ConstructInstance(instance, _class.base, from))
+      if(!ConstructInstance(instance, _class.base, from, false))
          return false;
    }
    if(_class.Initialize)
@@ -4603,7 +4635,12 @@ static bool ConstructInstance(void * instance, Class _class, Class from)
    }
    if(_class.Constructor)
    {
-      if(!_class.Constructor(instance))
+      bool result;
+      if(_class.bindingsClass)
+         result = ((bool (*)(void *, bool))(void *)_class.Constructor)(instance, bindingsAlloc);
+      else
+         result = _class.Constructor(instance);
+      if(!result)
       {
          for(; _class; _class = _class.base)
          {
@@ -4618,7 +4655,7 @@ static bool ConstructInstance(void * instance, Class _class, Class from)
    return true;
 }
 
-public dllexport void * eInstance_New(Class _class)
+static void * Instance_New(Class _class, bool bindingsAlloc)
 {
    Instance instance = null;
    if(_class)
@@ -4627,7 +4664,7 @@ public dllexport void * eInstance_New(Class _class)
 #ifdef MEMINFO
 
 #undef malloc
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
       //allocateClass = _class;
@@ -4662,7 +4699,7 @@ public dllexport void * eInstance_New(Class _class)
       }
 #ifdef MEMINFO
       allocateClass = null;
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif
 #endif
@@ -4680,7 +4717,7 @@ public dllexport void * eInstance_New(Class _class)
          // Copy the virtual table initially
          instance._vTbl = _class._vTbl;
       }
-      if(instance && !ConstructInstance(instance, _class, null))
+      if(instance && !ConstructInstance(instance, _class, null, bindingsAlloc))
       {
          _free(instance);
          instance = null;
@@ -4691,6 +4728,16 @@ public dllexport void * eInstance_New(Class _class)
    return instance;
 }
 
+public dllexport void * eInstance_New(Class _class)
+{
+   return Instance_New(_class, true);
+}
+
+public dllexport void * eInstance_NewEx(Class _class, bool bindingsAlloc)
+{
+   return Instance_New(_class, bindingsAlloc);
+}
+
 public dllexport void eInstance_Evolve(Instance * instancePtr, Class _class)
 {
    if(_class && instancePtr && *instancePtr)
@@ -4800,7 +4847,7 @@ public dllexport void eInstance_Evolve(Instance * instancePtr, Class _class)
       instance._vTbl = _class._vTbl;
 
       // We don't want to reconstruct the portion already constructed...
-      if(!ConstructInstance(instance, _class, fromClass))
+      if(!ConstructInstance(instance, _class, fromClass, false))
       {
          _free(instance);
          *instancePtr = null;
@@ -4819,7 +4866,7 @@ public dllexport void eInstance_Delete(Instance instance)
       bool ownVtbl;
 
 #ifdef MEMINFO
-#if (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__)
+#if (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__) || defined(_M_X64) || defined(_WIN64) || defined(__LP64__) || defined(__LLP64__)
       if(instance._class == (void *)0xecececececececec)
 #else
       if(instance._class == (void *)0xecececec)
@@ -5567,7 +5614,7 @@ static Module Module_Load(Module fromModule, const char * name, AccessMode impor
       {
          const char * libLocation = null;
 #if defined(__ANDROID__)
-         libLocation = AndroidInterface_GetLibLocation();
+         libLocation = AndroidInterface_GetLibLocation(fromModule.application);
 #endif
          library = Instance_Module_Load(libLocation, name, &Load, &Unload);
       }
@@ -5603,7 +5650,7 @@ static Module Module_Load(Module fromModule, const char * name, AccessMode impor
    }
    if(ensureCOM && !strcmp(name, "ecere") && module)
    {
-      name = !strcmp(module.name, "ecereCOM") ? "ecere" : "ecereCOM";
+      name = !strcmp(module.name, "ecereCOM") ? "ecereCOM" : "ecere";
       if((!Load && !strcmp(module.name, "ecereCOM")) ||
          (Load && (!__thisModule || !__thisModule.name || !strcmp(__thisModule.name, "ecereCOM")) && Load != (void *)COM_LOAD_FUNCTION))
       {
@@ -5650,7 +5697,7 @@ static Module Module_Load(Module fromModule, const char * name, AccessMode impor
       }
       incref module;
    }
-#if defined(_DEBUG)
+#if defined(_DEBUG) && !defined(__ANDROID__)
    InternalModuleLoadBreakpoint();
 #endif
    return module;
@@ -6253,7 +6300,7 @@ public dllexport void eProperty_SelfWatch(Class _class, const char * name, void
    }
 }
 
-public dllexport void eInstance_Watch(void * instance, Property _property, void * object, void (*callback)(void *, void *))
+public dllexport void eInstance_Watch(Instance instance, Property _property, void * object, void (*callback)(void *, void *))
 {
    if(_property.isWatchable)
    {
@@ -6345,7 +6392,7 @@ public bool LocateModule(const char * name, const char * fileName)
 }
 
 /*
-#if (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__)
+#if (defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__) || defined(_M_X64) || defined(_WIN64) || defined(__LP64__) || defined(__LLP64__)
 #define _64BIT 1
 #else
 #define _64BIT 0
@@ -6588,8 +6635,11 @@ public dllexport Application __ecere_COM_Initialize(bool guiApp, int argc, char
 
 #ifdef __ANDROID__
    // Clean up global variables
+#if !defined(DISABLE_MEMMGR)
    memoryInitialized = false;
    pools = null;
+#endif
+
 #ifdef MEMINFO
    memset(&memStacks, 0, sizeof(BinaryTree));
    memoryErrorsCount = 0;
@@ -6649,6 +6699,15 @@ public dllexport ClassTemplateParameter eClass_AddTemplateParameter(Class _class
          type = type;
          (type == identifier) ? info : CopyString(info);
       };
+
+      {
+         Class c = eSystem_FindClass(_class.module, name);
+         if(c && c.internalDecl)
+         {
+            c.module.classes.Remove(c);
+            eClass_Unregister(c);
+         }
+      }
       if(defaultArg != null)
       {
          param.defaultArg = defaultArg;
@@ -7390,7 +7449,7 @@ public void queryMemInfo(char * string)
 
    blocksByClass.Free();
    sizeByClass.Free();
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Wait();
 #endif
    for(p = 0; pools && p < NUM_POOLS; p++)
@@ -7404,7 +7463,7 @@ public void queryMemInfo(char * string)
          sizeByClass[c] += block.size;
       }
    }
-#if !defined(__EMSCRIPTEN__)
+#if !defined(_NOMUTEX)
    memMutex.Release();
 #endif