Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
a4478395
Commit
a4478395
authored
Jun 07, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hashtable: fix traverse typesafety.
parent
175ca4aa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
11 deletions
+124
-11
ccan/hashtable/hashtable.h
ccan/hashtable/hashtable.h
+12
-11
ccan/hashtable/test/compile_fail-traverse-arg1.c
ccan/hashtable/test/compile_fail-traverse-arg1.c
+32
-0
ccan/hashtable/test/compile_fail-traverse-arg2.c
ccan/hashtable/test/compile_fail-traverse-arg2.c
+31
-0
ccan/hashtable/test/compile_ok-traverse.c
ccan/hashtable/test/compile_ok-traverse.c
+49
-0
No files found.
ccan/hashtable/hashtable.h
View file @
a4478395
...
@@ -73,17 +73,18 @@ bool hashtable_del(struct hashtable *ht, unsigned long hash, const void *p);
...
@@ -73,17 +73,18 @@ bool hashtable_del(struct hashtable *ht, unsigned long hash, const void *p);
*/
*/
#define hashtable_traverse(ht, type, cb, cbarg) \
#define hashtable_traverse(ht, type, cb, cbarg) \
_hashtable_traverse(ht, cast_if_type(bool (*)(void *, void *), \
_hashtable_traverse(ht, cast_if_type(bool (*)(void *, void *), \
cast_if_any(bool (*)(void *, \
cast_if_any(bool (*)(void *, \
void *), (cb), \
void *), \
bool (*)(const type *, \
(cb), (cb), \
const typeof(*cbarg) *), \
bool (*)(const type *, \
bool (*)(type *, \
const typeof(*cbarg) *), \
const typeof(*cbarg) *), \
bool (*)(type *, \
bool (*)(const type *, \
const typeof(*cbarg) *), \
typeof(*cbarg) *)), \
bool (*)(const type *, \
bool (*)(type *, \
typeof(*cbarg) *)), \
typeof(*cbarg) *)), \
(cb), \
cbarg)
bool (*)(type *, typeof(*cbarg) *)), \
(cbarg))
void
_hashtable_traverse
(
struct
hashtable
*
ht
,
void
_hashtable_traverse
(
struct
hashtable
*
ht
,
bool
(
*
cb
)(
void
*
p
,
void
*
cbarg
),
void
*
cbarg
);
bool
(
*
cb
)(
void
*
p
,
void
*
cbarg
),
void
*
cbarg
);
...
...
ccan/hashtable/test/compile_fail-traverse-arg1.c
0 → 100644
View file @
a4478395
#include <ccan/hashtable/hashtable.h>
#include <ccan/hashtable/hashtable.c>
#include <stdlib.h>
struct
foo
{
int
i
;
};
struct
bar
{
int
i
;
};
static
bool
fn_bar_bar
(
#ifdef FAIL
struct
bar
*
#else
struct
foo
*
#endif
foo
,
struct
bar
*
bar
)
{
return
true
;
}
int
main
(
void
)
{
struct
hashtable
*
ht
=
NULL
;
struct
bar
*
bar
=
NULL
;
hashtable_traverse
(
ht
,
struct
foo
,
fn_bar_bar
,
bar
);
return
0
;
}
ccan/hashtable/test/compile_fail-traverse-arg2.c
0 → 100644
View file @
a4478395
#include <ccan/hashtable/hashtable.h>
#include <ccan/hashtable/hashtable.c>
#include <stdlib.h>
struct
foo
{
int
i
;
};
struct
bar
{
int
i
;
};
static
bool
fn_foo_foo
(
struct
foo
*
foo
,
#ifdef FAIL
struct
foo
*
#else
struct
bar
*
#endif
bar
)
{
return
true
;
}
int
main
(
void
)
{
struct
hashtable
*
ht
=
NULL
;
struct
bar
*
bar
=
NULL
;
hashtable_traverse
(
ht
,
struct
foo
,
fn_foo_foo
,
bar
);
return
0
;
}
ccan/hashtable/test/compile_ok-traverse.c
0 → 100644
View file @
a4478395
#include <ccan/hashtable/hashtable.h>
#include <ccan/hashtable/hashtable.c>
struct
foo
{
int
i
;
};
struct
bar
{
int
i
;
};
static
bool
fn_foo_bar
(
struct
foo
*
foo
,
struct
bar
*
bar
)
{
return
true
;
}
static
bool
fn_const_foo_bar
(
const
struct
foo
*
foo
,
struct
bar
*
bar
)
{
return
true
;
}
static
bool
fn_foo_const_bar
(
struct
foo
*
foo
,
const
struct
bar
*
bar
)
{
return
true
;
}
static
bool
fn_const_foo_const_bar
(
const
struct
foo
*
foo
,
const
struct
bar
*
bar
)
{
return
true
;
}
static
bool
fn_void_void
(
void
*
foo
,
void
*
bar
)
{
return
true
;
}
int
main
(
void
)
{
struct
hashtable
*
ht
=
NULL
;
struct
bar
*
bar
=
NULL
;
hashtable_traverse
(
ht
,
struct
foo
,
fn_foo_bar
,
bar
);
hashtable_traverse
(
ht
,
struct
foo
,
fn_const_foo_bar
,
bar
);
hashtable_traverse
(
ht
,
struct
foo
,
fn_foo_const_bar
,
bar
);
hashtable_traverse
(
ht
,
struct
foo
,
fn_const_foo_const_bar
,
bar
);
hashtable_traverse
(
ht
,
struct
foo
,
fn_void_void
,
bar
);
return
0
;
}
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