Subject: Re: Building NT Emacs 19.34 on Windows 95

From: Pat Knight <[email-masked]>
Date: Wed, 25 Sep 1996 14:55:35 +0100

In a message sent at 10:30 25/09/96 +0100, I wrote that:
>I'm trying to build NT Emacs 19.34 on Windows 95 so that I can modify the
>packages in loaddefs before dumping. I'm using MSVC++ 4.2. The make runs
>fine up to the point where temacs is called to do the loadup and dump.
>temacs fails to start up correctly as the Emacs internal malloc cannot get
>any system memory.
>

OK - cracked it. MSVC++ 4.2 changed the way it initialised its runtime heap,
so that it now called VirtualAlloc earlier in the start up process than the
code in ntheap.c. This meant that the call in ntheap.c failed. I've patched
ntheap.c so that it supplies the _heap_init function VC++ uses to initialise
its runtime heap and everything's wonderful again.

Here are the diffs for building with 4.2:

diff -c -r1.1 ntheap.c
*** ntheap.c    1996/09/24 20:36:40     1.1
--- ntheap.c    1996/09/25 12:43:36
***************
*** 282,284 ****
--- 282,313 ----
    if (need_to_alloc)
      sbrk (need_to_alloc);
  }
+
+ #define EMULATE_MSVC42_HEAP
+ #ifdef EMULATE_MSVC42_HEAP
+
+ /* MSVC 4.2 introduced a "small heap" which it initialises early in start
+    up processing. As part of this processing, it does a call to HeapCreate,
+    which calls VirtualAlloc, breaking our call to VirtualAlloc in
+    allocate_heap (above). Replace the runtime _heap_init function with one
+    of our own which causes our heap to be allocated and initialised.
+ */
+ int __cdecl
+ _heap_init (void)
+ {
+   char *ptr = malloc(1);
+   if (ptr)
+     free (ptr);
+ }
+
+ /* C runtime wants to call this, and we don't want the normal version called,
+    as we replaced the normal version of _heap_init.
+ */
+ void __cdecl
+ _heap_term (void)
+ {
+   return;
+ }
+
+ #endif
+

Cheers,
	Pat