discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with NSInvocation on Windows - Now with patch


From: Roland Schwingel
Subject: Problem with NSInvocation on Windows - Now with patch
Date: Mon, 08 Mar 2010 11:42:01 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

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]);
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]