From: Gunnar Beutner Date: Tue, 30 Jul 2013 16:52:22 +0000 (+0200) Subject: Use nsmalloc/nsfree for channel/chanindex. X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/1a5771420d9e4f6155c79e0a16cc1392dc9d6422 Use nsmalloc/nsfree for channel/chanindex. --- diff --git a/chanindex/chanindex.c b/chanindex/chanindex.c index e610fd8e..fe4f6219 100644 --- a/chanindex/chanindex.c +++ b/chanindex/chanindex.c @@ -12,13 +12,10 @@ MODULE_VERSION("") -#define ALLOCUNIT 1000 - #define channelhash(x) (crc32i(x)%CHANNELHASHSIZE) chanindex *chantable[CHANNELHASHSIZE]; sstring *extnames[MAXCHANNELEXTS]; -chanindex *freechanindices; unsigned int channelmarker; @@ -26,7 +23,6 @@ void _init() { memset(chantable,0,sizeof(chantable)); memset(extnames,0,sizeof(extnames)); channelmarker=0; - freechanindices=NULL; } void _fini() { @@ -34,26 +30,11 @@ void _fini() { } chanindex *getchanindex() { - int i; - chanindex *cip; - - if (freechanindices==NULL) { - freechanindices=(chanindex *)nsmalloc(POOL_CHANINDEX, ALLOCUNIT*sizeof(chanindex)); - for(i=0;inext; - - return cip; + return nsmalloc(POOL_CHANINDEX, sizeof(chanindex)); } void freechanindex(chanindex *cip) { - cip->next=freechanindices; - freechanindices=cip; + nsfree(POOL_CHANINDEX, cip); } chanindex *findchanindex(const char *name) { diff --git a/channel/channel.c b/channel/channel.c index 03ae8f2b..cf875d4b 100644 --- a/channel/channel.c +++ b/channel/channel.c @@ -43,9 +43,6 @@ void channelstats(int hooknum, void *arg); void sendchanburst(int hooknum, void *arg); void _init() { - /* Initialise internal structures */ - initchannelalloc(); - /* Set up the nouser marker according to our own numeric */ nouser=(mylongnum<<18)|CU_NOUSERMASK; diff --git a/channel/channel.h b/channel/channel.h index 6c5da84a..0053682b 100644 --- a/channel/channel.h +++ b/channel/channel.h @@ -157,7 +157,6 @@ int addnumerictochanuserhash(chanuserhash *cuh, long numeric); unsigned long *getnumerichandlefromchanhash(chanuserhash *cuh, long numeric); /* functions from channelalloc.c */ -void initchannelalloc(); channel *newchan(); void freechan(channel *cp); chanuserhash *newchanuserhash(int numbuckets); diff --git a/channel/channelalloc.c b/channel/channelalloc.c index 5add18f6..a71b7457 100644 --- a/channel/channelalloc.c +++ b/channel/channelalloc.c @@ -1,85 +1,36 @@ /* channelalloc.c */ -#include #include "channel.h" -#include #include "../core/nsmalloc.h" -#define ALLOCUNIT 100 - -channel *freechans; -chanuserhash *freehash; - -void initchannelalloc() { - freechans=NULL; - freehash=NULL; -} - -/* channel records don't have next pointers. - * Overload the index pointer for chaining free channels */ - channel *newchan() { - int i; - channel *cp; - - if (freechans==NULL) { - freechans=(channel *)nsmalloc(POOL_CHANNEL,ALLOCUNIT*sizeof(channel)); - for (i=0;i<(ALLOCUNIT-1);i++) { - freechans[i].index=(struct chanindex *)&(freechans[i+1]); - } - freechans[ALLOCUNIT-1].index=NULL; - } - - cp=freechans; - freechans=(channel *)cp->index; - - return cp; + return nsmalloc(POOL_CHANNEL, sizeof(channel)); } void freechan(channel *cp) { - cp->index=(struct chanindex *)freechans; - freechans=cp; + nsfree(POOL_CHANNEL, cp); } -/* - * Free hash for all! - * - * Since these things don't naturally have a "next" pointer - * we abuse the "content" pointer to build our list of free - * structures. - * - * Hence some somewhat bizarre casts... - */ - chanuserhash *newchanuserhash(int hashsize) { int i; - chanuserhash *cuhp; - - if (freehash==NULL) { - freehash=(chanuserhash *)nsmalloc(POOL_CHANNEL,ALLOCUNIT*sizeof(chanuserhash)); - for (i=0;i<(ALLOCUNIT-1);i++) { - freehash[i].content=(unsigned long *)&(freehash[i+1]); - } - freehash[ALLOCUNIT-1].content=NULL; - } - - cuhp=freehash; - freehash=(chanuserhash *)cuhp->content; - + chanuserhash *cuhp = nsmalloc(POOL_CHANNEL, sizeof(chanuserhash)); + + if (!cuhp) + return NULL; + /* Don't use nsmalloc() here since we will free this in freechanuserhash() */ cuhp->content=(unsigned long *)malloc(hashsize*sizeof(unsigned long)); for (i=0;icontent[i]=nouser; } - + cuhp->hashsize=hashsize; cuhp->totalusers=0; - + return cuhp; } void freechanuserhash(chanuserhash *cuhp) { free(cuhp->content); - cuhp->content=(unsigned long *)freehash; - freehash=cuhp; + nsfree(POOL_CHANNEL, cuhp); }