xfconf update - array and struct types
Brian J. Tarricone
bjt23 at cornell.edu
Mon Oct 15 22:07:53 CEST 2007
Jasper Huijsmans wrote:
> Hey Brian,
> 2007/10/15, Brian J. Tarricone <bjt23 at cornell.edu>:
> I was reading the stuff about array types and was getting the feeling
> it might just be a little bit overengineered, but than you got to the
> structs and I must say that is really cool. It is absolutely clear
> what is going on at first glance, the use can have complex data
> structures and the backend does not need to know anything about it.
> Very nice indeed.
Thanks ^_^. I originally just wanted a simple array API that lets you
store single-type arrays. But when I started thinking about the struct
stuff, I realised that, duh, structs usually have members of different
types. I wanted the struct support to be completely client-side, so
extending the array stuff to be super-flexible seemed the way to go,
though, as I mentioned, the array API is a little harder to use now for
simpler cases, which I'd like to address at some point.
> (More comments below)
>> There's one possible issue: struct member alignment. Right now
>> libxfconf is placing values in the struct you pass it by taking into
>> account struct member alignment. If you use the gcc extension
>> __attribute__((packed)) on your structs, this won't work, and you'll
>> get segfaults in your application if your structs would normally require
>> padding. I'm tempted to just list that as a limitation and leave it
>> alone, since I think most of the time you'd use this libxfconf
>> functionality for normal aligned structs. The only time you really use
>> packed structs is when you're using structs to represent some binary
>> file format on disk or a wire protocol on the network, or something
>> like that.
>> So, that's about it. It's far past my bed time, so I should get to
>> sleep and work on this more tomorrow. Comments, criticisms, and
>> suggestions would be most welcome; it would be good to know if people
>> think I'm going in the right direction, or if I'm getting to the point
>> where I'm overengineering things.
> Well I would say if you start worrying about packed structs, you have
> reached the point of overengineering alright ;-)
> Binary or otherwise unaligned data should be saved/restored as byte arrays.
> Or let me rephrase that: If anyone should ever feel the need to use a
> packed struct anywhere in Xfce, they should instead stick their head
> in a bucket of ice cold water until they get back to their senses.
> Did that come out too strong? ;-)
Hahaha, yeah, you're probably right. I spent a good 3 hours figuring
out how to deal with the struct alignment on different platforms and
writing the code to calculate the correct struct offsets, and then
started going a little batty and wondering if anyone would need support
for packed structs. (I actually thought of a way to do this without
making things too horrible, but still... somewhat horrible.) Sooo... no
packed structs. Good.
Storing unaligned data as byte arrays is probably pretty inefficient for
the current implementation (though I guess you could store them as
uint32 or uint64 arrays, but still). For data like that I'd actually
say escape the entire thing so it's valid utf-8 (or base64 or uuencode)
and store it in a string property. Or: just write the damn thing out to
its own dedicated file and don't abuse the config store! What do people
think, it's the windows registry? ^_~
More information about the Xfce4-dev