Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d9dd352b
Commit
d9dd352b
authored
Jul 24, 2010
by
Benjamin Kramer
Browse files
Remove _dictAlloc and friends
zmalloc calls abort() so _dictPanic will never be called.
parent
b1e0bd4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/dict.c
View file @
d9dd352b
...
...
@@ -52,33 +52,6 @@
* around when there is a child performing saving operations. */
static
int
dict_can_resize
=
1
;
/* ---------------------------- Utility funcitons --------------------------- */
static
void
_dictPanic
(
const
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
fprintf
(
stderr
,
"
\n
DICT LIBRARY PANIC: "
);
vfprintf
(
stderr
,
fmt
,
ap
);
fprintf
(
stderr
,
"
\n\n
"
);
va_end
(
ap
);
}
/* ------------------------- Heap Management Wrappers------------------------ */
static
void
*
_dictAlloc
(
size_t
size
)
{
void
*
p
=
zmalloc
(
size
);
if
(
p
==
NULL
)
_dictPanic
(
"Out of memory"
);
return
p
;
}
static
void
_dictFree
(
void
*
ptr
)
{
zfree
(
ptr
);
}
/* -------------------------- private prototypes ---------------------------- */
static
int
_dictExpandIfNeeded
(
dict
*
ht
);
...
...
@@ -132,7 +105,7 @@ static void _dictReset(dictht *ht)
dict
*
dictCreate
(
dictType
*
type
,
void
*
privDataPtr
)
{
dict
*
d
=
_dictA
lloc
(
sizeof
(
*
d
));
dict
*
d
=
zma
lloc
(
sizeof
(
*
d
));
_dictInit
(
d
,
type
,
privDataPtr
);
return
d
;
...
...
@@ -177,7 +150,7 @@ int dictExpand(dict *d, unsigned long size)
n
.
size
=
realsize
;
n
.
sizemask
=
realsize
-
1
;
n
.
table
=
_dictA
lloc
(
realsize
*
sizeof
(
dictEntry
*
));
n
.
table
=
zma
lloc
(
realsize
*
sizeof
(
dictEntry
*
));
n
.
used
=
0
;
/* Initialize all the pointers to NULL */
...
...
@@ -208,7 +181,7 @@ int dictRehash(dict *d, int n) {
/* Check if we already rehashed the whole table... */
if
(
d
->
ht
[
0
].
used
==
0
)
{
_dictF
ree
(
d
->
ht
[
0
].
table
);
zf
ree
(
d
->
ht
[
0
].
table
);
d
->
ht
[
0
]
=
d
->
ht
[
1
];
_dictReset
(
&
d
->
ht
[
1
]);
d
->
rehashidx
=
-
1
;
...
...
@@ -285,7 +258,7 @@ int dictAdd(dict *d, void *key, void *val)
/* Allocates the memory and stores key */
ht
=
dictIsRehashing
(
d
)
?
&
d
->
ht
[
1
]
:
&
d
->
ht
[
0
];
entry
=
_dictA
lloc
(
sizeof
(
*
entry
));
entry
=
zma
lloc
(
sizeof
(
*
entry
));
entry
->
next
=
ht
->
table
[
index
];
ht
->
table
[
index
]
=
entry
;
ht
->
used
++
;
...
...
@@ -348,7 +321,7 @@ static int dictGenericDelete(dict *d, const void *key, int nofree)
dictFreeEntryKey
(
d
,
he
);
dictFreeEntryVal
(
d
,
he
);
}
_dictF
ree
(
he
);
zf
ree
(
he
);
d
->
ht
[
table
].
used
--
;
return
DICT_OK
;
}
...
...
@@ -382,13 +355,13 @@ int _dictClear(dict *d, dictht *ht)
nextHe
=
he
->
next
;
dictFreeEntryKey
(
d
,
he
);
dictFreeEntryVal
(
d
,
he
);
_dictF
ree
(
he
);
zf
ree
(
he
);
ht
->
used
--
;
he
=
nextHe
;
}
}
/* Free the table and the allocated cache structure */
_dictF
ree
(
ht
->
table
);
zf
ree
(
ht
->
table
);
/* Re-initialize the table */
_dictReset
(
ht
);
return
DICT_OK
;
/* never fails */
...
...
@@ -399,7 +372,7 @@ void dictRelease(dict *d)
{
_dictClear
(
d
,
&
d
->
ht
[
0
]);
_dictClear
(
d
,
&
d
->
ht
[
1
]);
_dictF
ree
(
d
);
zf
ree
(
d
);
}
dictEntry
*
dictFind
(
dict
*
d
,
const
void
*
key
)
...
...
@@ -432,7 +405,7 @@ void *dictFetchValue(dict *d, const void *key) {
dictIterator
*
dictGetIterator
(
dict
*
d
)
{
dictIterator
*
iter
=
_dictA
lloc
(
sizeof
(
*
iter
));
dictIterator
*
iter
=
zma
lloc
(
sizeof
(
*
iter
));
iter
->
d
=
d
;
iter
->
table
=
0
;
...
...
@@ -475,7 +448,7 @@ dictEntry *dictNext(dictIterator *iter)
void
dictReleaseIterator
(
dictIterator
*
iter
)
{
if
(
!
(
iter
->
index
==
-
1
&&
iter
->
table
==
0
))
iter
->
d
->
iterators
--
;
_dictF
ree
(
iter
);
zf
ree
(
iter
);
}
/* Return a random entry from the hash table. Useful to
...
...
@@ -654,7 +627,7 @@ static unsigned int _dictStringCopyHTHashFunction(const void *key)
static
void
*
_dictStringDup
(
void
*
privdata
,
const
void
*
key
)
{
int
len
=
strlen
(
key
);
char
*
copy
=
_dictA
lloc
(
len
+
1
);
char
*
copy
=
zma
lloc
(
len
+
1
);
DICT_NOTUSED
(
privdata
);
memcpy
(
copy
,
key
,
len
);
...
...
@@ -674,7 +647,7 @@ static void _dictStringDestructor(void *privdata, void *key)
{
DICT_NOTUSED
(
privdata
);
_dictF
ree
(
key
);
zf
ree
(
key
);
}
dictType
dictTypeHeapStringCopyKey
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment