diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-27 10:50:59 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-27 10:50:59 -0800 |
commit | 6ad0af956bbc328c91fdb2327b43614c7ebbb000 (patch) | |
tree | ecb1625f2706772fb7071917ec91333bca4bd4df | |
parent | e5c801fbd2f8341e67600fd38b1f3ef8fc82030f (diff) |
Replace local u*alloc wrappers with direct calls to standard funcs
Includes:
- Replacing calls to uTypedCalloc with direct calloc calls
- Replacing uFree calls with free calls
- Assuming strdup is always available and uStringDup fallback function
is no longer needed
- Deleting the remainder of the forms of u*alloc which were unused
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | cfgparse.y | 9 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | utils.c | 68 | ||||
-rw-r--r-- | utils.h | 41 | ||||
-rw-r--r-- | xkbevd.c | 18 |
5 files changed, 15 insertions, 123 deletions
@@ -65,6 +65,7 @@ #endif #define DEBUG_VAR parseDebug #include "xkbevd.h" +#include <stdlib.h> %} %right EQUALS %left PLUS MINUS @@ -107,7 +108,7 @@ CfgEntry : EventDef ActionDef if (($1)&&($2)) $1->action= *($2); if ($2) - uFree($2); + free($2); $$= $1; } | VarDef { $$= $1; } @@ -116,7 +117,7 @@ CfgEntry : EventDef ActionDef VarDef : Ident EQUALS NameSpec { CfgEntryPtr cfg; - cfg= uTypedCalloc(1,CfgEntryRec); + cfg= calloc(1,sizeof(CfgEntryRec)); if (cfg) { cfg->entry_type= VariableDef; cfg->event_type= 0; @@ -133,7 +134,7 @@ VarDef : Ident EQUALS NameSpec EventDef : EventType OPAREN OptNameSpec CPAREN { CfgEntryPtr cfg; - cfg= uTypedCalloc(1,CfgEntryRec); + cfg= calloc(1,sizeof(CfgEntryRec)); if (cfg) { cfg->entry_type= EventDef; cfg->event_type= $1; @@ -155,7 +156,7 @@ EventType : BELL { $$= XkbBellNotify; } ActionDef : ActionType OptString { ActDefPtr act; - act= uTypedCalloc(1,ActDefRec); + act= calloc(1,sizeof(ActDefRec)); if (act) { act->type= $1; act->text= $2; diff --git a/configure.ac b/configure.ac index 1741ebd..588a177 100644 --- a/configure.ac +++ b/configure.ac @@ -45,7 +45,7 @@ if test ! -f "cfgparse.c"; then fi fi -AC_CHECK_FUNCS([strdup strcasecmp]) +AC_CHECK_FUNCS([strcasecmp]) # Checks for pkg-config packages PKG_CHECK_MODULES(XKBEVD, xkbfile x11) @@ -33,60 +33,6 @@ unsigned int DEBUG_VAR; /***====================================================================***/ - -Opaque -uAlloc(unsigned size) -{ - return((Opaque)malloc(size)); -} - -/***====================================================================***/ - -Opaque -uCalloc(unsigned n, unsigned size) -{ - return((Opaque)calloc(n,size)); -} - -/***====================================================================***/ - -Opaque -uRealloc(Opaque old, unsigned newSize) -{ - if (old==NULL) - return((Opaque)malloc(newSize)); - else return((Opaque)realloc((char *)old,newSize)); -} - -/***====================================================================***/ - -Opaque -uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize) -{ -char *rtrn; - - if (old==NULL) - rtrn= (char *)calloc(nNew,itemSize); - else { - rtrn= (char *)realloc((char *)old,nNew*itemSize); - if ((rtrn)&&(nNew>nOld)) { - bzero(&rtrn[nOld*itemSize],(nNew-nOld)*itemSize); - } - } - return (Opaque)rtrn; -} - -/***====================================================================***/ - -void -uFree(Opaque ptr) -{ - if (ptr!=(Opaque)NULL) - free((char *)ptr); - return; -} - -/***====================================================================***/ /*** FUNCTION ENTRY TRACKING ***/ /***====================================================================***/ @@ -302,20 +248,6 @@ uInternalError(const char *s,...) /***====================================================================***/ -#ifndef HAVE_STRDUP -char * -uStringDup(const char *str) -{ -char *rtrn; - - if (str==NULL) - return NULL; - rtrn= (char *)uAlloc(strlen(str)+1); - strcpy(rtrn,str); - return rtrn; -} -#endif - #ifndef HAVE_STRCASECMP int uStrCaseCmp(const char *str1, const char *str2) @@ -87,41 +87,6 @@ typedef union { /***====================================================================***/ -extern Opaque uAlloc( - unsigned /* size */ -); -extern Opaque uCalloc( - unsigned /* n */, - unsigned /* size */ -); -extern Opaque uRealloc( - Opaque /* old */, - unsigned /* newSize */ -); -extern Opaque uRecalloc( - Opaque /* old */, - unsigned /* nOld */, - unsigned /* nNew */, - unsigned /* newSize */ -); -extern void uFree( - Opaque /* ptr */ -); - -#define uTypedAlloc(t) ((t *)uAlloc((unsigned)sizeof(t))) -#define uTypedCalloc(n,t) ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t))) -#define uTypedRealloc(pO,n,t) ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t))) -#define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t))) -#if (defined mdHasAlloca) && (mdHasAlloca) -#define uTmpAlloc(n) ((Opaque)alloca((unsigned)n)) -#define uTmpFree(p) -#else -#define uTmpAlloc(n) uAlloc(n) -#define uTmpFree(p) uFree(p) -#endif - -/***====================================================================***/ - extern Boolean uSetErrorFile ( const char *name ); extern void uInformation ( const char *s, ...) _X_ATTRIBUTE_PRINTF(1,2); extern void uAction ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2); @@ -152,13 +117,7 @@ extern int uStrCasePrefix( const char * /* str */ ); #endif -#ifdef HAVE_STRDUP #define uStringDup(s1) (strdup(s1)) -#else -extern char *uStringDup( - const char * /* s1 */ -); -#endif /***====================================================================***/ @@ -287,7 +287,7 @@ unsigned priv= 0; case XkbBellNotify: if (name!=NULL) cfg->name.atom= XInternAtom(dpy,name,False); else cfg->name.atom= None; - if (name) uFree(name); + if (name) free(name); break; case XkbAccessXNotify: priv= 0; @@ -307,7 +307,7 @@ unsigned priv= 0; priv= XkbAXN_BKRejectMask; else if (uStrCaseEqual(name,"warning")) priv= XkbAXN_AXKWarningMask; - if (name) uFree(name); + if (name) free(name); cfg->name.priv= priv; break; case XkbActionMessage: @@ -319,12 +319,12 @@ unsigned priv= 0; } while ((config)&&(config->entry_type!=EventDef)) { CfgEntryPtr next; - if (config->name.str) uFree(config->name.str); - if (config->action.text) uFree(config->action.text); + if (config->name.str) free(config->name.str); + if (config->action.text) free(config->action.text); config->name.str= NULL; config->action.text= NULL; next= config->next; - uFree(config); + free(config); config= next; } cfg= config; @@ -332,13 +332,13 @@ unsigned priv= 0; CfgEntryPtr next; next= cfg->next; if (next->entry_type!=EventDef) { - if (next->name.str) uFree(config->name.str); - if (next->action.text) uFree(config->action.text); + if (next->name.str) free(config->name.str); + if (next->action.text) free(config->action.text); next->name.str= NULL; next->action.text= NULL; cfg->next= next->next; next->next= NULL; - uFree(next); + free(next); } else cfg= next; } @@ -401,7 +401,7 @@ int ok; char *tmp; cfg->action.type= ShellAction; tmp= uStringDup(&cfg->action.text[1]); - uFree(cfg->action.text); + free(cfg->action.text); cfg->action.text= tmp; } else cfg->action.type= SoundAction; |