X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f From: sandmann AT clio DOT rice DOT edu (Charles Sandmann) Message-Id: <10202120441.AA22905@clio.rice.edu> Subject: Re: Alignment problem To: rudd AT cyberoptics DOT com Date: Mon, 11 Feb 2002 22:41:28 -0600 (CST) Cc: eliz AT is DOT elta DOT co DOT il, djgpp-workers AT delorie DOT com In-Reply-To: <3C684B4A.3AC31AA2@cyberoptics.com> from "Eric Rudd" at Feb 11, 2002 04:52:58 PM X-Mailer: ELM [version 2.5 PL2] Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Here's a malloc.c patch vs 2.03 (not CVS - but should apply OK there with a line number offset). It only gets called if you have a new sbrk() block and it's unaligned - so normally no additional memory or cpu overhead. Note: sbrk(1..7) bytes should always be internally handled by sbrk() and not do any DPMI calls. Note, I can't make it fail normally so I added some sbrk(1) and sbrk(4) calls into a test program and malloc always returned 8 byte aligned. *** malloc.c_ Wed Dec 5 14:52:52 2001 --- malloc.c Mon Feb 11 22:22:32 2002 *************** malloc(size_t size) *** 208,215 **** --- 208,222 ---- rv = (BLOCK *)((char *)rv - 4); } else { + int align_bytes = (int)rv & (ALIGN-1); + if(align_bytes) + { + align_bytes = ALIGN - align_bytes; + if(sbrk(align_bytes) == (void *)((char *)rv + chunk_size) ) + rv = (BLOCK *)((char *)rv + align_bytes); + } expected_sbrk = (BLOCK *)((char *)rv + chunk_size); #if DEBUG printf(" disconnected sbrk\n"); #endif