From 2b4cf35206f78d4150abc4ce791415e862f3c622 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Tue, 31 Oct 2000 09:50:46 +0000 Subject: [PATCH] Remove crufty macros and memory routines. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3104 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/SplitLedger.c | 2 +- src/engine/Queue.c | 11 +++--- src/engine/util.c | 69 +++++++----------------------------- src/engine/util.h | 19 ---------- src/gnome/reconcile-list.c | 6 ++-- src/gnome/window-reconcile.c | 10 +++--- 6 files changed, 27 insertions(+), 90 deletions(-) diff --git a/src/SplitLedger.c b/src/SplitLedger.c index 5318bb7398..6e9e8473bc 100644 --- a/src/SplitLedger.c +++ b/src/SplitLedger.c @@ -2903,7 +2903,7 @@ xaccSRGetEntryHandler (gpointer vcell_data, short _cell_type, if ((amount > 0.0) && (cell_type == CRED_CELL)) return ""; - amount = DABS (amount); + amount = ABS (amount); return DxaccPrintAmount (amount, PRTSEP, NULL); } diff --git a/src/engine/Queue.c b/src/engine/Queue.c index 0ce02456f1..a61fc3ad28 100644 --- a/src/engine/Queue.c +++ b/src/engine/Queue.c @@ -34,6 +34,7 @@ * Copyright (c) 1999, 2000 Linas Vepstas */ +#include #include #include #include @@ -73,7 +74,7 @@ Queue * xaccMallocQueue (void) { Queue * ret; - ret = (Queue *) _malloc (sizeof (Queue)); + ret = g_new(Queue, 1); xaccInitQueue (ret); return ret; } @@ -86,7 +87,7 @@ xaccInitQueue (Queue *q) { if (!q) return; - q->split_list = (Split **) malloc (INITIAL_LENGTH * sizeof (Split *)); + q->split_list = (Split **) g_malloc (INITIAL_LENGTH * sizeof (Split *)); q->list_len = INITIAL_LENGTH; q->head_split = -1; q->tail_split = 0; @@ -108,7 +109,7 @@ xaccFreeQueue (Queue *q) { if (!q) return; - if (q->split_list) _free (q->split_list); + if (q->split_list) g_free (q->split_list); q->split_list = 0x0; q->list_len = -1; q->head_split = -1; @@ -118,7 +119,7 @@ xaccFreeQueue (Queue *q) q->head_price = 0.0; q->tail_price = 0.0; - _free (q); + g_free (q); } /* ================================================== */ @@ -149,7 +150,7 @@ ExtendHead (Queue * q) } /* if we got to here, we need to malloc more memory. */ - newlist = (Split **) malloc (2*(q->list_len)*sizeof (Split *)); + newlist = (Split **) g_malloc (2*(q->list_len)*sizeof (Split *)); q->list_len *= 2; len = q->head_split - q->tail_split + 1; diff --git a/src/engine/util.c b/src/engine/util.c index 99a61aa7a7..ccce97b171 100644 --- a/src/engine/util.c +++ b/src/engine/util.c @@ -163,51 +163,6 @@ gnc_set_auto_decimal_places( int places ) /********************************************************************\ \********************************************************************/ -/********************************************************************\ - * DEBUGGING MEMORY ALLOCATION STUFF * -\********************************************************************/ -#if DEBUG_MEMORY - -/* #if defined (__NetBSD__) || defined(__FreeBSD__) */ - -#ifndef HAVE_MALLOC_USABLE_SIZE -#define malloc_usable_size(ptr) 0 -#endif - -size_t core=0; - -void -dfree( void *ptr ) -{ - core -= malloc_usable_size(ptr); - free(ptr); -} - -void* -dmalloc( size_t size ) -{ - int i; - char *ptr; - ptr = (char *)malloc(size); - for( i=0; i= 'a' && (c) <= 'z') ? (c) + 'A' - 'a' : (c)) - /* Search for str2 in first nchar chars of str1, ignore case.. * Return pointer to first match, or null. */ @@ -215,18 +170,18 @@ dcoresize(void) char * strncasestr(const char *str1, const char *str2, size_t len) { - while (*str1 && len--) - { - if (UPPER(*str1) == UPPER(*str2)) + while (*str1 && len--) + { + if (toupper(*str1) == toupper(*str2)) + { + if (strncasecmp(str1,str2,strlen(str2)) == 0) { - if (strncasecmp(str1,str2,strlen(str2)) == 0) - { - return (char *) str1; - } + return (char *) str1; } - str1++; - } - return NULL; + } + str1++; + } + return NULL; } /* Search for str2 in str1, ignore case. @@ -567,7 +522,7 @@ PrintAmt(char *buf, double val, int prec, /* print the absolute value */ if (val < 0.0) - val = DABS(val); + val = ABS(val); /* print the value without separators */ util_fptostr(temp_buf, val, prec); @@ -788,7 +743,7 @@ DxaccSPrintAmountGeneral (char * bufp, double val, bufp = stpcpy(bufp, "("); /* Now print the value */ - bufp += PrintAmt(bufp, DABS(val), precision, flags & PRTSEP, + bufp += PrintAmt(bufp, ABS(val), precision, flags & PRTSEP, !(flags & PRTNMN), min_trailing_zeros); /* Now see if we print parentheses */ diff --git a/src/engine/util.h b/src/engine/util.h index e9c2cb84b4..278bea6aef 100644 --- a/src/engine/util.h +++ b/src/engine/util.h @@ -107,27 +107,8 @@ void gnc_log (gncModuleType module, gncLogLevel log_level, #define ERROR() fprintf(stderr,"%s: Line %d, error = %s\n", \ __FILE__, __LINE__, strerror(errno)); -#if DEBUG_MEMORY -void *dmalloc( size_t size ); -void dfree( void *ptr ); -size_t dcoresize(void); -# define _malloc(x) dmalloc(x) -# define _free(x) dfree(x) -# define _coresize() dcoresize() -#else -# define _malloc(x) malloc(x) -# define _free(x) free(x) -# define _coresize() 0 -#endif /** COOL MACROS *****************************************************/ -#ifndef ABS -#define ABS(x) ((x)>=0) ? (x) : (-1*(x)) -#endif -#define DABS(x) ((x)>=0.0) ? (x) : (-1.0*(x)) -#define DMAX(x,y) ((x)>(y)) ? (x) : (y) -#define isNum(x) (((x)-0x30) < 0) ? 0 : (((x)-0x30) > 9) ? 0 : 1 - #define EPS (1.0e-6) #define DEQEPS(x,y,eps) (((((x)+(eps))>(y)) ? 1 : 0) && ((((x)-(eps))<(y)) ? 1 : 0)) #define DEQ(x,y) DEQEPS(x,y,EPS) diff --git a/src/gnome/reconcile-list.c b/src/gnome/reconcile-list.c index 00efc95782..68372c3753 100644 --- a/src/gnome/reconcile-list.c +++ b/src/gnome/reconcile-list.c @@ -518,7 +518,7 @@ gnc_reconcile_list_reconciled_balance(GNCReconcileList *list) total += DxaccSplitGetValue(split); } - return DABS(total); + return ABS(total); } @@ -677,8 +677,8 @@ gnc_reconcile_list_fill(GNCReconcileList *list) strings[0] = gnc_print_date(ts); strings[1] = xaccTransGetNum(trans); strings[2] = xaccTransGetDescription(trans); - strings[3] = DxaccPrintAmount(DABS(amount), flags, - gnc_commodity_get_mnemonic(currency)); + strings[3] = DxaccPrintAmount(ABS(amount), flags, + gnc_commodity_get_mnemonic(currency)); reconciled = g_hash_table_lookup(list->reconciled, split) != NULL; recn = reconciled ? YREC : recn; diff --git a/src/gnome/window-reconcile.c b/src/gnome/window-reconcile.c index e444040ca4..46225faff5 100644 --- a/src/gnome/window-reconcile.c +++ b/src/gnome/window-reconcile.c @@ -223,12 +223,12 @@ recnRecalculateBalance(RecnWindow *recnData) (GNC_RECONCILE_LIST(recnData->credit)); /* Update the total debit and credit fields */ - amount = DxaccPrintAmount(DABS(debit), flags, - gnc_commodity_get_mnemonic(currency)); + amount = DxaccPrintAmount(ABS(debit), flags, + gnc_commodity_get_mnemonic(currency)); gtk_label_set_text(GTK_LABEL(recnData->total_debit), amount); amount = DxaccPrintAmount(credit, flags, - gnc_commodity_get_mnemonic(currency)); + gnc_commodity_get_mnemonic(currency)); gtk_label_set_text(GTK_LABEL(recnData->total_credit), amount); @@ -237,7 +237,7 @@ recnRecalculateBalance(RecnWindow *recnData) if (reverse_balance) reconciled = -reconciled; amount = DxaccPrintAmount(reconciled, flags, - gnc_commodity_get_mnemonic(currency)); + gnc_commodity_get_mnemonic(currency)); gnc_set_label_color(recnData->reconciled, reconciled); gtk_label_set_text(GTK_LABEL(recnData->reconciled), amount); if (reverse_balance) @@ -248,7 +248,7 @@ recnRecalculateBalance(RecnWindow *recnData) if (reverse_balance) diff = -diff; amount = DxaccPrintAmount(diff, flags, - gnc_commodity_get_mnemonic(currency)); + gnc_commodity_get_mnemonic(currency)); gnc_set_label_color(recnData->difference, diff); gtk_label_set_text(GTK_LABEL(recnData->difference), amount); if (reverse_balance)