All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karl MacMillan <kmacmillan@mentalrootkit.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: SELinux Mail List <selinux@tycho.nsa.gov>
Subject: Re: [RFC] Add list and iter data types to libsepol
Date: Wed, 17 Jan 2007 10:16:29 -0500	[thread overview]
Message-ID: <45AE3DCD.8080501@mentalrootkit.com> (raw)
In-Reply-To: <1169036139.22731.159.camel@moss-spartans.epoch.ncsc.mil>

Stephen Smalley wrote:
> On Tue, 2007-01-16 at 16:10 -0500, Karl MacMillan wrote:
>> As part of some work to improve the parser in checkpolicy and module 
>> data structures in libsepol, I have implemented doubly-linked list and 
>> iterator data types. The attached patch adds these to libsepol.
>>
>> I would appreciate feedback on these before I submit larger patches that 
>> make use of them. In particular:
>>
>> * Is the iterator concept acceptable (I plan to add iterator support to 
>> other data types including hashtabs)?
> 
> How does this compare with Kevin Carr's previous iterator proposal?

Different implementations and - as far as I remember - different design. 
Same basic idea, though.

>  How
> does it compare with the existing _iterate functions in libsepol?
> 

The iterate functions (which are basically the same as the hashtab 
callbacks) have the same basic goal of allowing external callers to 
iterate over the elements of a data structure without exposing the 
implementation of the data structure. To me, the _iterate functions and 
callbacks have a few problems solved by the iterators:

* Defining callbacks is cumbersome and ofter requires defining data 
structures for passing complex state (see link.c).

* Iterating through nested data structures using callbacks is even more 
painful (see semodule_deps.c for an example of where callbacks would 
have been almost unusable).

* Iterating through multiple, related data structures with the callbacks 
is also difficult or impossible. Think of what the equivalent callbacks 
for the example below would be like (simplified):

int reta, retb;
struct sepol_iter *itera, *iterb;
struct sepol_list *a, *b;

reta = sepol_list_begin(a, itera);
retb = sepol_list_begin(b, iterb);

while (reta == SEPOL_OK && retb == SEPOL_OK) {
	// do something with the data
	sepol_iter_next(itera);
	sepol_iter_next(iterb);
}

* Controlling the traversal (e.g., only visiting every other element or 
stopping traversal) is cumbersome.

* Inserting or removing elements into data structures via callbacks is 
also problematic. At best the performance will be worse. The iterators I 
am proposing can hold whatever state is needed for fast insertion / 
deletion while with the callbacks it is hard to connect the callback 
driver function state (e.g., hashtab_map) with the insertion / deletion 
functions. The hashtab_map_remove_on_error function does work around 
this, but mixing insertion and deletions would be very difficult. See 
test-list.c for an example of how the iterators help with this.

The summary, I think, is that these are a better model overall which is 
why it is a popular approach (at least in non-C languages). Granted, the 
situation is that the callbacks are working for our current needs. So 
I'm not asking for this to be merged without code actually using it 
(which is coming) - just if there are any fundamental objections.

>> * We've discussed dropping the use of typedefs on structs (which I do in 
>> this patch). Is this what we want to do, or should I add typedefs?
> 
> Omitting typedefs is preferred I think.
> 

Ok.

Karl


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2007-01-17 15:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-16 21:10 [RFC] Add list and iter data types to libsepol Karl MacMillan
2007-01-16 22:24 ` Karl MacMillan
2007-01-17 12:15 ` Stephen Smalley
2007-01-17 15:16   ` Karl MacMillan [this message]
2007-01-18 15:47     ` Stephen Smalley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45AE3DCD.8080501@mentalrootkit.com \
    --to=kmacmillan@mentalrootkit.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.