const on ldb_dn in ldb

Andrew Bartlett abartlet at samba.org
Thu Dec 14 01:00:13 GMT 2006


On Wed, 2006-12-13 at 07:48 -0500, simo wrote:
> On Wed, 2006-12-13 at 18:44 +1100, Andrew Bartlett wrote:
> > Many of the ldb functions take an ldb_dn *, but this is not const in the
> > prototype.  
> > 
> > For example:
> > struct ldb_dn *ldb_dn_copy(void *mem_ctx, struct ldb_dn *dn);
> > struct ldb_dn *ldb_dn_get_parent(void *mem_ctx, struct ldb_dn *dn);
> > 
> > Is there a reason for avoiding the const here?  I have functions with
> > return a const ldb_dn, and this now causes warnings.
> 
> Yes, simply struct ldb_dn can never be const as the ldb_dn_* functions
> can always manipulate it to internally explode, linearize, casefold,
> only when really needed. The fact that we don't simply always validate
> (which means explode it) an ldb_dn is the key for the speed improvements
> of ldb. This means that users should validate ldb_dn's by themselves.
> I think it would be a bit silly to have to use discard_const() just
> everywhere in ldb_dn.c

The problem is that we now have no way to tell the difference between
'you may modify/free this result' and 'this is a const result that
should not be touched'.  I understand the manipulation of private
pointers internally makes things difficult, but it is a loss.

Andrew Bartlett
-- 
Andrew Bartlett                                http://samba.org/~abartlet/
Authentication Developer, Samba Team           http://samba.org
Samba Developer, Red Hat Inc.                  http://redhat.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.samba.org/archive/samba-technical/attachments/20061214/6080d21e/attachment.bin


More information about the samba-technical mailing list