diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-17 06:41:53 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-17 06:41:53 +0400 |
commit | 5c6ee6b523c6a53c310683a9f7fbe5d730db6122 (patch) | |
tree | 65e90096612cac887a47ef19d27551e2e0b1cac1 /source/blender/blenlib/intern | |
parent | db6cb30941da7899ccafa44c87c17970d134a2c9 (diff) | |
parent | 994f4bb3f78a467b6c34e30a9b8868fc4d01caf0 (diff) |
svn merge ^/trunk/blender -r42670:42680
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/BLI_dynstr.c | 9 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 89 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_linklist.c | 24 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_memarena.c | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/edgehash.c | 30 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rand.c | 39 | ||||
-rw-r--r-- | source/blender/blenlib/intern/winstuff.c | 18 |
7 files changed, 162 insertions, 65 deletions
diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index 5cdadce7c01..349bc3492e7 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -94,7 +94,8 @@ void BLI_dynstr_append(DynStr *ds, const char *cstr) ds->curlen+= cstrlen; } -void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) { +void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) +{ DynStrElem *dse= malloc(sizeof(*dse)); int cstrlen= BLI_strnlen(cstr, len); @@ -225,7 +226,8 @@ int BLI_dynstr_get_len(DynStr *ds) return ds->curlen; } -char *BLI_dynstr_get_cstring(DynStr *ds) { +char *BLI_dynstr_get_cstring(DynStr *ds) +{ char *s, *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring"); DynStrElem *dse; @@ -241,7 +243,8 @@ char *BLI_dynstr_get_cstring(DynStr *ds) { return rets; } -void BLI_dynstr_free(DynStr *ds) { +void BLI_dynstr_free(DynStr *ds) +{ DynStrElem *dse; for (dse= ds->elems; dse; ) { diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 25b3da7a442..950acb21e17 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -56,7 +56,8 @@ unsigned int hashsizes[]= { /***/ -GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) { +GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) +{ GHash *gh= MEM_mallocN(sizeof(*gh), info); gh->hashfp= hashfp; gh->cmpfp= cmpfp; @@ -72,11 +73,13 @@ GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) { return gh; } -int BLI_ghash_size(GHash *gh) { +int BLI_ghash_size(GHash *gh) +{ return gh->nentries; } -void BLI_ghash_insert(GHash *gh, void *key, void *val) { +void BLI_ghash_insert(GHash *gh, void *key, void *val) +{ unsigned int hash= gh->hashfp(key)%gh->nbuckets; Entry *e= (Entry*) BLI_mempool_alloc(gh->entrypool); @@ -109,7 +112,8 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val) { } } -void *BLI_ghash_lookup(GHash *gh, const void *key) { +void *BLI_ghash_lookup(GHash *gh, const void *key) +{ if(gh) { unsigned int hash= gh->hashfp(key)%gh->nbuckets; Entry *e; @@ -151,7 +155,8 @@ int BLI_ghash_remove (GHash *gh, void *key, GHashKeyFreeFP keyfreefp, GHashValFr return 0; } -int BLI_ghash_haskey(GHash *gh, void *key) { +int BLI_ghash_haskey(GHash *gh, void *key) +{ unsigned int hash= gh->hashfp(key)%gh->nbuckets; Entry *e; @@ -162,7 +167,8 @@ int BLI_ghash_haskey(GHash *gh, void *key) { return 0; } -void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) { +void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) +{ int i; if (keyfreefp || valfreefp) { @@ -190,7 +196,8 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef /***/ -GHashIterator *BLI_ghashIterator_new(GHash *gh) { +GHashIterator *BLI_ghashIterator_new(GHash *gh) +{ GHashIterator *ghi= MEM_mallocN(sizeof(*ghi), "ghash iterator"); ghi->gh= gh; ghi->curEntry= NULL; @@ -203,7 +210,8 @@ GHashIterator *BLI_ghashIterator_new(GHash *gh) { } return ghi; } -void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) { +void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) +{ ghi->gh= gh; ghi->curEntry= NULL; ghi->curBucket= -1; @@ -214,18 +222,22 @@ void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) { ghi->curEntry= ghi->gh->buckets[ghi->curBucket]; } } -void BLI_ghashIterator_free(GHashIterator *ghi) { +void BLI_ghashIterator_free(GHashIterator *ghi) +{ MEM_freeN(ghi); } -void *BLI_ghashIterator_getKey(GHashIterator *ghi) { +void *BLI_ghashIterator_getKey(GHashIterator *ghi) +{ return ghi->curEntry?ghi->curEntry->key:NULL; } -void *BLI_ghashIterator_getValue(GHashIterator *ghi) { +void *BLI_ghashIterator_getValue(GHashIterator *ghi) +{ return ghi->curEntry?ghi->curEntry->val:NULL; } -void BLI_ghashIterator_step(GHashIterator *ghi) { +void BLI_ghashIterator_step(GHashIterator *ghi) +{ if (ghi->curEntry) { ghi->curEntry= ghi->curEntry->next; while (!ghi->curEntry) { @@ -236,23 +248,27 @@ void BLI_ghashIterator_step(GHashIterator *ghi) { } } } -int BLI_ghashIterator_isDone(GHashIterator *ghi) { +int BLI_ghashIterator_isDone(GHashIterator *ghi) +{ return !ghi->curEntry; } /***/ -unsigned int BLI_ghashutil_ptrhash(const void *key) { +unsigned int BLI_ghashutil_ptrhash(const void *key) +{ return (unsigned int)(intptr_t)key; } -int BLI_ghashutil_ptrcmp(const void *a, const void *b) { +int BLI_ghashutil_ptrcmp(const void *a, const void *b) +{ if (a==b) return 0; else return (a<b)?-1:1; } -unsigned int BLI_ghashutil_inthash(const void *ptr) { +unsigned int BLI_ghashutil_inthash(const void *ptr) +{ uintptr_t key = (uintptr_t)ptr; key += ~(key << 16); @@ -265,14 +281,16 @@ unsigned int BLI_ghashutil_inthash(const void *ptr) { return (unsigned int)(key & 0xffffffff); } -int BLI_ghashutil_intcmp(const void *a, const void *b) { +int BLI_ghashutil_intcmp(const void *a, const void *b) +{ if (a==b) return 0; else return (a<b)?-1:1; } -unsigned int BLI_ghashutil_strhash(const void *ptr) { +unsigned int BLI_ghashutil_strhash(const void *ptr) +{ const char *s= ptr; unsigned int i= 0; unsigned char c; @@ -282,6 +300,39 @@ unsigned int BLI_ghashutil_strhash(const void *ptr) { return i; } -int BLI_ghashutil_strcmp(const void *a, const void *b) { +int BLI_ghashutil_strcmp(const void *a, const void *b) +{ return strcmp(a, b); } + +GHashPair *BLI_ghashutil_pairalloc(const void *first, int second) +{ + GHashPair *pair = MEM_mallocN(sizeof(GHashPair), "GHashPair"); + pair->first = first; + pair->second = second; + return pair; +} + +unsigned int BLI_ghashutil_pairhash(const void *ptr) +{ + const GHashPair *pair = ptr; + unsigned int hash = BLI_ghashutil_ptrhash(pair->first); + return hash ^ BLI_ghashutil_inthash(SET_INT_IN_POINTER(pair->second)); +} + +int BLI_ghashutil_paircmp(const void *a, const void *b) +{ + const GHashPair *A = a; + const GHashPair *B = b; + + int cmp = BLI_ghashutil_ptrcmp(A->first, B->first); + if(cmp == 0) + return BLI_ghashutil_intcmp(SET_INT_IN_POINTER(A->second), SET_INT_IN_POINTER(B->second)); + return cmp; +} + +void BLI_ghashutil_pairfree(void *ptr) +{ + MEM_freeN((void*)ptr); +} + diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index a9b8cbb6467..6300817ec03 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -35,7 +35,8 @@ #include "BLI_linklist.h" #include "BLI_memarena.h" -int BLI_linklist_length(LinkNode *list) { +int BLI_linklist_length(LinkNode *list) +{ if (0) { return list?(1+BLI_linklist_length(list->next)):0; } else { @@ -70,7 +71,8 @@ LinkNode *BLI_linklist_find(LinkNode *list, int index) return NULL; } -void BLI_linklist_reverse(LinkNode **listp) { +void BLI_linklist_reverse(LinkNode **listp) +{ LinkNode *rhead= NULL, *cur= *listp; while (cur) { @@ -85,7 +87,8 @@ void BLI_linklist_reverse(LinkNode **listp) { *listp= rhead; } -void BLI_linklist_prepend(LinkNode **listp, void *ptr) { +void BLI_linklist_prepend(LinkNode **listp, void *ptr) +{ LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); nlink->link= ptr; @@ -93,7 +96,8 @@ void BLI_linklist_prepend(LinkNode **listp, void *ptr) { *listp= nlink; } -void BLI_linklist_append(LinkNode **listp, void *ptr) { +void BLI_linklist_append(LinkNode **listp, void *ptr) +{ LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); LinkNode *node = *listp; @@ -110,7 +114,8 @@ void BLI_linklist_append(LinkNode **listp, void *ptr) { } } -void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) { +void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) +{ LinkNode *nlink= BLI_memarena_alloc(ma, sizeof(*nlink)); nlink->link= ptr; @@ -118,7 +123,8 @@ void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) { *listp= nlink; } -void BLI_linklist_insert_after(LinkNode **listp, void *ptr) { +void BLI_linklist_insert_after(LinkNode **listp, void *ptr) +{ LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); LinkNode *node = *listp; @@ -134,7 +140,8 @@ void BLI_linklist_insert_after(LinkNode **listp, void *ptr) { } } -void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) { +void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) +{ while (list) { LinkNode *next= list->next; @@ -146,7 +153,8 @@ void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) { } } -void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata) { +void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata) +{ for (; list; list= list->next) applyfunc(list->link, userdata); } diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c index 308fc6a61e6..4debe1a4b04 100644 --- a/source/blender/blenlib/intern/BLI_memarena.c +++ b/source/blender/blenlib/intern/BLI_memarena.c @@ -48,7 +48,8 @@ struct MemArena { LinkNode *bufs; }; -MemArena *BLI_memarena_new(int bufsize, const char *name) { +MemArena *BLI_memarena_new(int bufsize, const char *name) +{ MemArena *ma= MEM_callocN(sizeof(*ma), "memarena"); ma->bufsize= bufsize; ma->align = 8; @@ -57,20 +58,24 @@ MemArena *BLI_memarena_new(int bufsize, const char *name) { return ma; } -void BLI_memarena_use_calloc(MemArena *ma) { +void BLI_memarena_use_calloc(MemArena *ma) +{ ma->use_calloc= 1; } -void BLI_memarena_use_malloc(MemArena *ma) { +void BLI_memarena_use_malloc(MemArena *ma) +{ ma->use_calloc= 0; } -void BLI_memarena_use_align(struct MemArena *ma, int align) { +void BLI_memarena_use_align(struct MemArena *ma, int align) +{ /* align should be a power of two */ ma->align = align; } -void BLI_memarena_free(MemArena *ma) { +void BLI_memarena_free(MemArena *ma) +{ BLI_linklist_free(ma->bufs, (void(*)(void*)) MEM_freeN); MEM_freeN(ma); } @@ -78,7 +83,8 @@ void BLI_memarena_free(MemArena *ma) { /* amt must be power of two */ #define PADUP(num, amt) ((num+(amt-1))&~(amt-1)) -void *BLI_memarena_alloc(MemArena *ma, int size) { +void *BLI_memarena_alloc(MemArena *ma, int size) +{ void *ptr; /* ensure proper alignment by rounding diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 4b4bff7df78..dbd138a3563 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -42,7 +42,8 @@ /***/ -EdgeHash *BLI_edgehash_new(void) { +EdgeHash *BLI_edgehash_new(void) +{ EdgeHash *eh= MEM_callocN(sizeof(*eh), "EdgeHash"); eh->cursize= 0; eh->nentries= 0; @@ -54,11 +55,13 @@ EdgeHash *BLI_edgehash_new(void) { return eh; } -int BLI_edgehash_size(EdgeHash *eh) { +int BLI_edgehash_size(EdgeHash *eh) +{ return eh->nentries; } -void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp) { +void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp) +{ int i; for (i=0; i<eh->nbuckets; i++) { @@ -78,7 +81,8 @@ void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp) { eh->nentries= 0; } -void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp) { +void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp) +{ BLI_edgehash_clear(eh, valfreefp); BLI_mempool_destroy(eh->epool); @@ -96,7 +100,8 @@ struct EdgeHashIterator { EdgeEntry *curEntry; }; -EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh) { +EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh) +{ EdgeHashIterator *ehi= MEM_mallocN(sizeof(*ehi), "eh iter"); ehi->eh= eh; ehi->curEntry= NULL; @@ -109,26 +114,31 @@ EdgeHashIterator *BLI_edgehashIterator_new(EdgeHash *eh) { } return ehi; } -void BLI_edgehashIterator_free(EdgeHashIterator *ehi) { +void BLI_edgehashIterator_free(EdgeHashIterator *ehi) +{ MEM_freeN(ehi); } -void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, int *v0_r, int *v1_r) { +void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, int *v0_r, int *v1_r) +{ if (ehi->curEntry) { *v0_r = ehi->curEntry->v0; *v1_r = ehi->curEntry->v1; } } -void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) { +void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) +{ return ehi->curEntry?ehi->curEntry->val:NULL; } -void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val) { +void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val) +{ if(ehi->curEntry) ehi->curEntry->val= val; } -void BLI_edgehashIterator_step(EdgeHashIterator *ehi) { +void BLI_edgehashIterator_step(EdgeHashIterator *ehi) +{ if (ehi->curEntry) { ehi->curEntry= ehi->curEntry->next; while (!ehi->curEntry) { diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index b1b7ebed18e..28dc5a696d5 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -78,11 +78,13 @@ void rng_free(RNG* rng) MEM_freeN(rng); } -void rng_seed(RNG *rng, unsigned int seed) { +void rng_seed(RNG *rng, unsigned int seed) +{ rng->X= (((r_uint64) seed)<<16) | LOWSEED; } -void rng_srandom(RNG *rng, unsigned int seed) { +void rng_srandom(RNG *rng, unsigned int seed) +{ rng_seed(rng, seed + hash[seed & 255]); seed= rng_getInt(rng); rng_seed(rng, seed + hash[seed & 255]); @@ -90,16 +92,19 @@ void rng_srandom(RNG *rng, unsigned int seed) { rng_seed(rng, seed + hash[seed & 255]); } -int rng_getInt(RNG *rng) { +int rng_getInt(RNG *rng) +{ rng->X= (MULTIPLIER*rng->X + ADDEND)&MASK; return (int) (rng->X>>17); } -double rng_getDouble(RNG *rng) { +double rng_getDouble(RNG *rng) +{ return (double) rng_getInt(rng)/0x80000000; } -float rng_getFloat(RNG *rng) { +float rng_getFloat(RNG *rng) +{ return (float) rng_getInt(rng)/0x80000000; } @@ -135,28 +140,34 @@ void rng_skip(RNG *rng, int n) static RNG theBLI_rng = {0}; /* note, this one creates periodical patterns */ -void BLI_srand(unsigned int seed) { +void BLI_srand(unsigned int seed) +{ rng_seed(&theBLI_rng, seed); } /* using hash table to create better seed */ -void BLI_srandom(unsigned int seed) { +void BLI_srandom(unsigned int seed) +{ rng_srandom(&theBLI_rng, seed); } -int BLI_rand(void) { +int BLI_rand(void) +{ return rng_getInt(&theBLI_rng); } -double BLI_drand(void) { +double BLI_drand(void) +{ return rng_getDouble(&theBLI_rng); } -float BLI_frand(void) { +float BLI_frand(void) +{ return rng_getFloat(&theBLI_rng); } -void BLI_fillrand(void *addr, int len) { +void BLI_fillrand(void *addr, int len) +{ RNG rng; unsigned char *p= addr; @@ -188,11 +199,13 @@ void BLI_thread_srandom(int thread, unsigned int seed) rng_seed(&rng_tab[thread], seed + hash[seed & 255]); } -int BLI_thread_rand(int thread) { +int BLI_thread_rand(int thread) +{ return rng_getInt(&rng_tab[thread]); } -float BLI_thread_frand(int thread) { +float BLI_thread_frand(int thread) +{ return rng_getFloat(&rng_tab[thread]); } diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index 1b5bb607386..b2002b63a22 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -49,7 +49,8 @@ /* FILE_MAX */ -int BLI_getInstallationDir( char * str ) { +int BLI_getInstallationDir( char * str ) +{ char dir[FILE_MAXDIR]; int a; @@ -73,7 +74,8 @@ void RegisterBlendExtension_Fail(HKEY root) TerminateProcess(GetCurrentProcess(),1); } -void RegisterBlendExtension(void) { +void RegisterBlendExtension(void) +{ LONG lresult; HKEY hkey = 0; HKEY root = 0; @@ -167,7 +169,8 @@ void RegisterBlendExtension(void) { TerminateProcess(GetCurrentProcess(),0); } -DIR *opendir (const char *path) { +DIR *opendir (const char *path) +{ if (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) { DIR *newd= MEM_mallocN(sizeof(DIR), "opendir"); @@ -185,7 +188,8 @@ DIR *opendir (const char *path) { } } -struct dirent *readdir(DIR *dp) { +struct dirent *readdir(DIR *dp) +{ if (dp->direntry.d_name) { MEM_freeN(dp->direntry.d_name); dp->direntry.d_name= NULL; @@ -208,7 +212,8 @@ struct dirent *readdir(DIR *dp) { } } -int closedir (DIR *dp) { +int closedir (DIR *dp) +{ if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name); if (dp->handle!=INVALID_HANDLE_VALUE) FindClose(dp->handle); @@ -217,7 +222,8 @@ int closedir (DIR *dp) { return 0; } -void get_default_root(char* root) { +void get_default_root(char* root) +{ char str[MAX_PATH+1]; /* the default drive to resolve a directory without a specified drive |