General purpose library for name/value pairs.

Teske, Devin Devin.Teske at fisglobal.com
Tue Aug 6 00:33:54 UTC 2013


On Jul 16, 2013, at 3:49 PM, Teske, Devin wrote:

> 
> On Jul 16, 2013, at 3:39 PM, Teske, Devin wrote:
> 
>> 
>> On Jul 16, 2013, at 3:06 PM, Steve Kiernan wrote:
>> 
>>> On Mon, 8 Jul 2013 10:57:17 -0700
>>> Jordan Hubbard <jkh at mail.turbofuzz.com> wrote:
>>> 
>>>> 
>>>> On Jul 8, 2013, at 8:03 AM, Pawel Jakub Dawidek <pjd at freebsd.org> wrote:
>>>> 
>>>>> How about instead of supporting int8, uint8, int16, uint16, int32,
>>>>> uint32, int64 and uint64 I'd just support 'number' type, which would be
>>>>> uint64_t. This shouldn't break transporting signed values and because I
>>>>> don't support basic types like int, long, etc. casting or conversion has
>>>>> to be done anyway. This would reduce number of supported types to:
>>>> 
>>>> That's a good idea.  Since you're re-inventing Apple's XML property list API (but without serialization and quite a few other things), keeping the number of supported types down is much better than the converse - exposing the details of 16/32/64 bit numbers and their signedness will hang you over the long term, and you can always provide explicit conversion functions to/from Number for those who actually care.
>>>> 
>>>> String, Number, Boolean, Data, Date, Array and Dictionary are all plists support, and Apple developers have gotten along pretty well for many years with that set (not supporting Dictionaries, btw, is a pretty fundamental loss IMHO - it means you have to always iterate through lists to find your stuff, which is meh!).
>>>> 
>>>> When Apple extended the Plist metaphor for IPC (to create XPC), they also added out-of-band types like file and shared memory descriptors.  You have file descriptors, but not shared memory.  The latter is kind of important if you want to do larger IPCs with this mechanism someday and want to support "big payloads" transparently without passing the burden of the data management to the application programmer.
>>>> 
>>>> Before you also come back with "but but this is a kernel API!  For just one purpose!" let me just say that it's absolutely achievable to have ONE API for talking userland<->kernel and userland<->userland with the same types and the transport mechanism(s) largely abstracted away.  You don't need two - it's already been done with one, just look next door. :)
>>>> 
>>>> If you add file serialization of this format to your picture (and add the dictionary type) , bingo, now you have a preferences API that FreeBSD has lacked from day one ("just roll your own format and stick the file in /etc" being the canonical response to that need).
>>> 
>>> What about looking at NetBSD's libprop?
>>> 
>>> PROPLIB(3)             FreeBSD Library Functions Manual             PROPLIB(3)
>>> 
>>> NAME
>>>     proplib -- property container object library
>>> 
>>> LIBRARY
>>>     library ``libprop''
>>> 
>>> SYNOPSIS
>>>     #include <prop/proplib.h>
>>> 
>>> DESCRIPTION
>>>     The proplib library provides an abstract interface for creating and
>>>     manipulating property lists.  Property lists have object types for
>>>     boolean values, opaque data, numbers, and strings.  Structure is provided
>>>     by the array and dictionary collection types.
>>> 
>>>     Property lists can be passed across protection boundaries by translating
>>>     them to an external representation.  This external representation is an
>>>     XML document whose format is described by the following DTD:
>>> 
>>>                 http://www.apple.com/DTDs/PropertyList-1.0.dtd
>>> 
>>>     Property container objects are reference counted.  When an object is cre-
>>>     ated, its reference count is set to 1.  Any code that keeps a reference
>>>     to an object, including the collection types (arrays and dictionaries),
>>>     must ``retain'' the object (increment its reference count).  When that
>>>     reference is dropped, the object must be ``released'' (reference count
>>>     decremented).  When an object's reference count drops to 0, it is auto-
>>>     matically freed.
>>> 
>>>     The rules for managing reference counts are very simple:
>>> 
>>>     o   If you create an object and do not explicitly maintain a reference to
>>>         it, you must release it.
>>> 
>>>     o   If you get a reference to an object from other code and wish to main-
>>>         tain a reference to it, you must retain the object.  You are respon-
>>>         sible for releasing the object once you drop that reference.
>>> 
>>>     o   You must never release an object unless you create it or retain it.
>>> 
>>>     Object collections may be iterated by creating a special iterator object.
>>>     Iterator objects are special; they may not be retained, and they are
>>>     released using an iterator-specific release function.
>>> 
>> 
>> There's also my own "figpar" free for the taking...
>> 

I don't know if I was off the mark with my suggesting figpar for the job... but... I realized that some examples are necessary to actually bring it home as a contender.

I recently needed to be able to read the key/value pairs stored in ~/.dialogrc (generated by "dialog --create-rc ~/.dialogrc"). The format of which is simple enough... (from the head of a freshly-generated ~/.dialogrc):

# Types of values:
#
# Number     -  <number>
# String     -  "string"
# Boolean    -  <ON|OFF>
# Attribute  -  (foreground,background,highlight?)

Simple enough... figpar did the job wonderfully.

Check it out...

http://druidbsd.cvs.sf.net/viewvc/druidbsd/fdpv/dialogrc.h?revision=1.4&view=markup&pathrev=fdpv_0_4
http://druidbsd.cvs.sf.net/viewvc/druidbsd/fdpv/dialogrc.c?revision=1.12&view=markup&pathrev=fdpv_0_4

NOTE: If you looked at figpar before, have another look. I made it style(9) compatible and enhanced it slightly.

http://druidbsd.cvs.sf.net/viewvc/druidbsd/fdpv/figpar.h?revision=1.11&view=markup&pathrev=fdpv_0_4
http://druidbsd.cvs.sf.net/viewvc/druidbsd/fdpv/figpar.c?revision=1.7&view=markup&pathrev=fdpv_0_4

-- 
Cheers,
Devin

_____________
The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.


More information about the freebsd-arch mailing list