[asterisk-dev] [Code Review]: Add ability to clone ao2 containers.

Mark Michelson reviewboard at asterisk.org
Thu Feb 16 10:48:03 CST 2012



> On Feb. 16, 2012, 10:16 a.m., Mark Michelson wrote:
> > /trunk/tests/test_astobj2.c, lines 165-169
> > <https://reviewboard.asterisk.org/r/1746/diff/2/?file=24248#file24248line165>
> >
> >     I think it would be good to make sure that the the cloned container has the same contents as the original container.
> 
> rmudgett wrote:
>     Is there a good way to do that on unsorted containers?

If the clone is truly a clone of the original, then elements should be ordered the same. I'd suspect that you could have a loop where two iterators iterate over their respective containers. In the body of the loop, make sure that each iterator is currently pointing to the same value.


> On Feb. 16, 2012, 10:16 a.m., Mark Michelson wrote:
> > /trunk/tests/test_astobj2.c, lines 170-171
> > <https://reviewboard.asterisk.org/r/1746/diff/2/?file=24248#file24248line170>
> >
> >     Why do you do this here instead of letting the cleanup label handle this at the end of the function?
> 
> rmudgett wrote:
>     So the destructor_count will be in line with the remaining tests.  If the c3 container still has objects then the destructor_count will be off.

Understood.


- Mark


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1746/#review5526
-----------------------------------------------------------


On Feb. 16, 2012, 2:38 a.m., rmudgett wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1746/
> -----------------------------------------------------------
> 
> (Updated Feb. 16, 2012, 2:38 a.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> Occasionally there is a need to put all objects in one container also into another container.
> 
> Some reasons you might need to do this:
> 1) You need to reconfigure a container.   You would do this by creating a new container with the new configuration and ao2_container_dup the old container into it.  Then replace the old container with the new.  Then destroy the old container.
> 
> 2) You need the contents of a container to remain stable while operating on all of the objects.  You would do this by creating a cloned container of the original with ao2_container_clone.  The cloned container is a snapshot of the objects at the time of the cloning.  When done, just destroy the cloned container.
> 
> 
> Diffs
> -----
> 
>   /trunk/include/asterisk/astobj2.h 355447 
>   /trunk/main/astobj2.c 355447 
>   /trunk/tests/test_astobj2.c 355447 
> 
> Diff: https://reviewboard.asterisk.org/r/1746/diff
> 
> 
> Testing
> -------
> 
> Added unit testing code to test the new ao2_container_clone and ao2_container_dup functions.
> 
> Tests still pass.
> 
> 
> Thanks,
> 
> rmudgett
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120216/8c0023c4/attachment.htm>


More information about the asterisk-dev mailing list