Opps... I forgot to attach the patch
Hi...

There is a problem using NSInvocation on windows. It always allocates a windows native virtual memory page for it's informations. Depending on the windows version such a page can be very big and the number of these pages are limited. If you have a lot of NSInvocation instances this fragments your memory and you can also run out of virtual pages when you are using ffi invocations.

The attached (trivial) patch fixes this. It allocates pages now using malloc and later on adjusts the allocated memory flags using VirtualProtect().

Thanks for applying,

Roland



--- NSInvocation.m.orig 2010-03-08 10:56:48.000000000 +0100
+++ NSInvocation.m      2010-03-08 10:59:32.000000000 +0100
@@ -73,8 +73,6 @@
     {
 #if     defined(HAVE_MMAP)
       munmap(buffer, size);
-#elif   defined(__MINGW32__)
-      VirtualFree(buffer, 0, MEM_RELEASE);
 #else
       free(buffer);
 #endif
@@ -100,8 +98,6 @@
     MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
 #endif  /* HAVE_MPROTECT */
   if (buffer == (void*)-1) buffer = (void*)0;
-#elif   defined(__MINGW32__)
-  buffer = VirtualAlloc(NULL, _size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
 #else
   buffer = malloc(_size);
 #endif  /* HAVE_MMAP */
@@ -110,6 +106,7 @@
     {
       NSLog(@"Failed to map %u bytes for execute: %@", _size, [NSError _last]);
       buffer = 0;
+      size = 0;
       [self dealloc];
       self = nil;
     }
@@ -127,7 +124,7 @@
 {
 #if   defined(__MINGW32__)
   DWORD old;
-  if (VirtualProtect(buffer, size, PAGE_EXECUTE, &old) == 0)
+  if (!buffer || VirtualProtect(buffer, size, PAGE_EXECUTE_READWRITE, &old) == 
0)
     {
       NSLog(@"Failed to protect memory as executable: %@", [NSError _last]);
     }
_______________________________________________
Discuss-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to