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
ca6991d8
Commit
ca6991d8
authored
Dec 03, 2012
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tal: add del_destructor().
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
d73447c2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
3 deletions
+52
-3
ccan/tal/tal.c
ccan/tal/tal.c
+27
-0
ccan/tal/tal.h
ccan/tal/tal.h
+12
-0
ccan/tal/test/run-destructor.c
ccan/tal/test/run-destructor.c
+13
-3
No files found.
ccan/tal/tal.c
View file @
ca6991d8
...
...
@@ -258,6 +258,28 @@ static struct destructor *add_destructor_property(struct tal_hdr *t,
return
prop
;
}
static
bool
del_destructor_property
(
struct
tal_hdr
*
t
,
void
(
*
destroy
)(
void
*
))
{
struct
prop_hdr
**
p
;
for
(
p
=
(
struct
prop_hdr
**
)
&
t
->
prop
;
*
p
;
p
=
&
(
*
p
)
->
next
)
{
struct
destructor
*
d
;
if
(
is_literal
(
*
p
))
break
;
if
((
*
p
)
->
type
!=
DESTRUCTOR
)
continue
;
d
=
(
struct
destructor
*
)
*
p
;
if
(
d
->
destroy
==
destroy
)
{
*
p
=
(
*
p
)
->
next
;
freefn
(
d
);
return
true
;
}
}
return
false
;
}
static
struct
name
*
add_name_property
(
struct
tal_hdr
*
t
,
const
char
*
name
)
{
struct
name
*
prop
;
...
...
@@ -399,6 +421,11 @@ bool tal_add_destructor_(tal_t *ctx, void (*destroy)(void *me))
return
add_destructor_property
(
debug_tal
(
to_tal_hdr
(
ctx
)),
destroy
);
}
bool
tal_del_destructor_
(
tal_t
*
ctx
,
void
(
*
destroy
)(
void
*
me
))
{
return
del_destructor_property
(
debug_tal
(
to_tal_hdr
(
ctx
)),
destroy
);
}
bool
tal_set_name_
(
tal_t
*
ctx
,
const
char
*
name
,
bool
literal
)
{
struct
tal_hdr
*
t
=
debug_tal
(
to_tal_hdr
(
ctx
));
...
...
ccan/tal/tal.h
View file @
ca6991d8
...
...
@@ -130,6 +130,17 @@ void *tal_free(const tal_t *p);
#define tal_add_destructor(ptr, function) \
tal_add_destructor_((ptr), typesafe_cb(void, void *, (function), (ptr)))
/**
* tal_del_destructor - remove a destructor callback function.
* @ptr: The tal allocated object.
* @function: the function to call before it's freed.
*
* If @function has not been successfully added as a destructor, this returns
* false.
*/
#define tal_del_destructor(ptr, function) \
tal_del_destructor_((ptr), typesafe_cb(void, void *, (function), (ptr)))
/**
* tal_set_name - attach a name to a tal pointer.
* @ptr: The tal allocated object.
...
...
@@ -324,5 +335,6 @@ tal_t *tal_steal_(const tal_t *new_parent, const tal_t *t);
bool
tal_resize_
(
tal_t
**
ctxp
,
size_t
size
);
bool
tal_add_destructor_
(
tal_t
*
ctx
,
void
(
*
destroy
)(
void
*
me
));
bool
tal_del_destructor_
(
tal_t
*
ctx
,
void
(
*
destroy
)(
void
*
me
));
#endif
/* CCAN_TAL_H */
ccan/tal/test/run-destructor.c
View file @
ca6991d8
...
...
@@ -33,16 +33,26 @@ int main(void)
{
char
*
child2
;
plan_tests
(
1
2
);
plan_tests
(
1
8
);
destroy_count
=
0
;
parent
=
tal
(
NULL
,
char
);
child
=
tal
(
parent
,
char
);
ok1
(
tal_add_destructor
(
parent
,
destroy_parent
));
ok1
(
tal_add_destructor
(
child
,
destroy_child
));
tal_free
(
parent
);
ok1
(
destroy_count
==
2
);
destroy_count
=
0
;
parent
=
tal
(
NULL
,
char
);
child
=
tal
(
parent
,
char
);
ok1
(
tal_add_destructor
(
parent
,
destroy_parent
));
ok1
(
tal_add_destructor
(
child
,
destroy_child
));
ok1
(
tal_del_destructor
(
child
,
destroy_child
));
tal_free
(
parent
);
ok1
(
destroy_count
==
1
);
destroy_count
=
0
;
parent
=
tal
(
NULL
,
char
);
child
=
tal
(
parent
,
char
);
child2
=
tal
(
parent
,
char
);
...
...
@@ -51,7 +61,7 @@ int main(void)
ok1
(
tal_add_destructor
(
child
,
destroy_inc
));
ok1
(
tal_add_destructor
(
child2
,
destroy_inc
));
tal_free
(
parent
);
ok1
(
destroy_count
==
6
);
ok1
(
destroy_count
==
4
);
return
exit_status
();
}
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