From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15939 invoked by alias); 18 Jun 2009 18:07:05 -0000 Received: (qmail 15930 invoked by uid 22791); 18 Jun 2009 18:07:04 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_44,SPF_PASS X-Spam-Check-By: sourceware.org Received: from blu0-omc3-s30.blu0.hotmail.com (HELO blu0-omc3-s30.blu0.hotmail.com) (65.55.116.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Jun 2009 18:06:54 +0000 Received: from BLU0-SMTP30 ([65.55.116.72]) by blu0-omc3-s30.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 18 Jun 2009 11:06:50 -0700 Message-ID: Received: from GAMMAXP5 ([174.18.200.98]) by BLU0-SMTP30.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 18 Jun 2009 11:06:49 -0700 From: "BGB" To: "abhishek desai" , References: <898285d30906180800q3b5bd3b2h1d4a11d6a8245e34@mail.gmail.com> Subject: Re: problem when mapping malloc to GC_malloc. Date: Thu, 18 Jun 2009 18:07:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2009-06/txt/msg00042.txt.bz2 ----- Original Message ----- From: "abhishek desai" To: Sent: Thursday, June 18, 2009 8:00 AM Subject: problem when mapping malloc to GC_malloc. > Hi, > > My JNI code includes redefinitions to the malloc, free and realloc > functions (shown below). These functions call GC_malloc, GC_free and > GC_realloc respectively. This is done so that any calls to the malloc > get allocated through the garbage collector. However this is failing > with segfault. Any clues why this does not work ? > I am using this code along with the libgcj library linked dynamically > with my application. > > void *malloc(size_t size) > { > return GC_malloc(size); > } > > void *realloc(void *ptr, size_t size) > { > return GC_realloc(ptr, size); > } > > void free(void *ptr) > { > GC_free(ptr); > } > IMO, this is a very bad way to try to use a GC, and that it is blowing up when something like this is tried is no real surprise... (very likely you will end up with code calling GC_malloc in some places, and the real malloc in others, and in-all creating a horrible mess...). a much better (although IMO still not very good) way to do this would be to instead use macros to rename your functions: #define malloc(x) GC_malloc(x) ... which will apply locally to whatever code is in question (and, if used with caution, should resist blowing up...). however, my personal recommendation is to NOT use a GC implicitly in this way, rather one should make use of the GC explicit (AKA: actually go and rename their function calls, and keep track of how they use pointers so that GC memory and malloc memory don't get mixed up, ...). > > regards > abhishek >