[nanomsg] Re: [PATCH 3/3] Add the list test module

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: <nanomsg@xxxxxxxxxxxxx>
  • Date: Sat, 09 Mar 2013 12:17:51 +0100

Hi Nir,

As for the different patches to nn_list, I see where you are heading to: having uninitialised data (nn_list_item) inside otherwise fully functional objects is a problem just waiting to bite you (or some other innocent developer).

You are right that we should fix that.

However, I would like two rules to apply to nn_list:

1. All operations have O(1) complexity.
2. All list manipulation is explicit. E.g. nn_list_item_term() should not automatically remove the element from the list. Rather, it should assert if the element is in the list. The rationale is that the list may be, for example, guarded by a critical section, and thus it should not be accessed invisibly to the user. The user should lock the CS, remove the element, then unlock the CS.

So, my proposal is as follows: Let's modify the code in such a way the each nn_list_item is properly initialised (nn_list_item_init) and properly terminated (nn_list_item_term). That would allow us to implement following list semantics:

1. Freshly initialised list item is set to nil.
2. If terminating non-nil list item, assert.
3. When inserting a non-nil item to a list, assert.
4. When removing a nil item from a list, assert.
5. When terminating a non-empty list, assert.

That should give us some basic safety when handling the lists.

Thoughts?
Martin



Other related posts: