svn commit: samba r18436 - in branches/SAMBA_4_0/source/lib/ldb: common ldb_ildap ldb_sqlite3 ldb_tdb modules tools

tridge at tridge at
Wed Sep 13 02:09:59 GMT 2006


Sorry, I should have run this change past you first.

 > I find the fact that talloc_move() is really a macro that transforms the
 > second argument in a pointer to itself a bit deceiving.

yes, thats the downside of the API. When looking at the prototype it
is not clear that the 2nd argument changes. I guess the defence
against that argument is that the whole point of talloc_move() is to
change the 2nd argument, so it shouldn't be unexpected :-)

 > talloc_move(ac->store->last, ares);
 > which translates to _talloc_move(ac->store->last, &ares);

If you call talloc_move() without assigning the result then you lose
the pointer completely. Don't do that :-)

Notice I've left the cases like that as talloc_steal() in the ldb

 > So what do we gain by doing it?
 > Or is there something I don't get and should wait after I digested my
 > dinner to realized what it is? :-)

What we gain is that the common pattern of moving pointers between
structures becomes safer. Jeremy told me that his primary complaint
about talloc_steal() was that after you steal from one structure to
another, you can still access it in the first structure. What he
wanted was like the SAFE_FREE() macro that Samba3 uses, where the
pointer is guaranteed to be zero after it is no longer valid.

So, when you want to move a pointer to a new place in the heirarchy,
and also to a new place in your data structures, talloc_move() will do
both at once. I think Jeremy did have a point about this as I think it
was a potential source of error. I don't think it was a common error,
but we might as well have an API that avoids it.

When you are only moving the pointer to a new place in the hierarchy,
then use talloc_steal(). When moving to only a new place in the data
structures, use pointer assignment. When you are doing both, use
talloc_move() and you can be sure that nobody accesses the pointer via
the old structure again.

Cheers, Tridge

More information about the samba-technical mailing list