[02:12]  * Keybuk finally gets around to proving some of the bugs sadmac fixed in 0.5
[02:49] <sadmac> Keybuk: which ones?
[02:52] <Keybuk> $ENV's replacement being the same length as the variable name+$ for example
[02:53] <sadmac> oh yes
[02:53] <Keybuk> I'm going to be strict from now on ;) all bug fixes must come with test cases
[02:54] <sadmac> not a problem
[02:54]  * sadmac goes back to writing tests
[02:58] <sadmac> Keybuk: test_com.netsplit.Nih.Test_object: tests/com.netsplit.Nih.Test_impl.c:766: my_setup: Assertion `server != ((void *)0)' failed.
[02:58] <sadmac> Keybuk: I started getting these failures writing my testcases, but reverting my changes doesn't fix them
[02:58] <Keybuk> err
[02:58] <Keybuk> that implies your test d-bus server isn't running?
[02:58] <Keybuk> have you checked it got killed ok before?
[02:58] <Keybuk> usually it's test_dbus-daemon
[02:59] <sadmac> I see a test_com.netspli
[02:59] <sadmac> that's probably it
[03:00] <sadmac> ahh, segmentation fault
[03:00] <sadmac> something strangely comforting about knowing its your own fault after one of those phantom errors.
[03:05] <sadmac> Keybuk: how much later will you be around?
[03:06] <Keybuk> not much
[03:06] <Keybuk> why?
[03:07] <sadmac> Keybuk: I have the async api and one test case. I want to show it to you before I write more so I know if the API as at least right. But I have a segfault left to scrub out so its not quite ready :)
[03:11] <Keybuk> cool
[03:11] <Keybuk> I may be around long enough ;)
[03:12] <sadmac> Keybuk: dbus_shutdown is triggering the segfault. Its being called from the teardown function (which I haven't touched). Only thing I can think of that would do it is a call to dbus_connection_read_write_dispatch (conn, -1);
[03:12] <sadmac> seems like without that it didn't segfault (though the test didn't really run)
[03:23] <Keybuk> that implies you've got your references mixed up somewhere
[03:24] <sadmac> ah
[03:24] <sadmac> what's happening then?
[03:25]  * sadmac sees definite double-deref
[03:26] <sadmac> dunno how that could do this, but its a bug
[03:26] <sadmac> Keybuk: \o/
[03:27] <sadmac> Keybuk: how do you want this then?
[03:35] <Keybuk> got a bzr tree?
[03:37] <sadmac> Keybuk: yeah, writing the commit notes now...
[03:37] <sadmac> I had more outstanding than I thought.
[03:46] <sadmac> Keybuk: https://code.launchpad.net/~cjdahlin/libnih/async
[03:50] <Keybuk> ok, give me a few minutes to finish up this bit
[03:50] <Keybuk> and I'll take a look
[03:52] <sadmac> k
[04:08] <Keybuk> urgh
[04:08] <Keybuk> the valgrind attacks.  you die
[04:09] <Keybuk> (not your code, mine)
[04:09] <Keybuk> http://rafb.net/p/EzdMTh82.html
[04:10] <Keybuk> nothing worse than an invalid write into a freed block where the write and free are inside the same function
[04:10] <Keybuk> (and that function is "free" :p)
[04:10] <sadmac> ot
[04:10] <sadmac> *oy
[04:16] <sadmac> isn't it 4am over there?
[04:22] <Keybuk> yes
[04:22] <Keybuk> don't you ever stay up all night hacking? :)
[04:25] <Keybuk> why names?
[04:28] <Keybuk> unless I'm missing something, the dispatch function doesn't take the method call arguments
[04:31] <Keybuk> I'd generate a typedef for the callback function and put it in the .h file
[04:31] <Keybuk> and use that
[04:31] <Keybuk> if callback is NULL, should send without expected reply
[04:32] <Keybuk> NihAsyncNotifyData should be in the .c file, since it should never be exposed
[04:32] <Keybuk> should be typedef'd to that name
[04:32] <Keybuk> member names should line up
[04:33] <Keybuk> userdata -> data
[04:33] <Keybuk> proxy should probably go first too
[04:33] <sadmac> Keybuk: for which callback?
[04:34] <Keybuk> argument to the async dispatch function
[04:34] <sadmac> Keybuk: ah, nm, I misunderstood for a moment
[04:34] <Keybuk> struct nih_blah_blah -> NihBlahBlah
[04:34] <Keybuk> I wouldn't call it that though
[04:34] <Keybuk> make it similar to the DBus Name
[04:34] <Keybuk> NihDBusPendingCall or something
[04:34] <sadmac> Keybuk: you omit the CamelCase form on another struct in dbus.h
[04:35] <Keybuk> do I?
[04:35] <sadmac> pretty sure
[04:35] <Keybuk> I bet I typedef'd it first ;)
[04:35] <Keybuk> NihDBusInterface?
[04:35] <Keybuk> line 44: typedef struct nih_dbus_interface NihDBusInterface;
[04:36] <sadmac> Keybuk: ah. so it is.
[04:36] <Keybuk> I can't quite work out what you're doing with the callback definition in asyncDispatchPrototype() - a typdef would definitely help here
[04:37] <Keybuk> and then it'd be obvious you've forgotten all about in_args ;)
[04:37] <sadmac> Keybuk: line 1283
[04:37] <Keybuk> oh
[04:37] <Keybuk> they should go first
[04:38] <sadmac> Keybuk: I figured put the consistent-between-all stuff first
[04:38] <Keybuk> proxy, input arguments, callback, data
[04:38] <Keybuk> my_str_to_int (proxy, "foo", get_int, NULL);
[04:38] <Keybuk> reads the right way then
[04:39] <sadmac> yeah, I can see that..
[04:40] <Keybuk> you don't actually check whether the pending call completed?
[04:40] <Keybuk> in fact
[04:40] <Keybuk> dbus_pending_call_steal_reply doesn't return NULL to indicate out of memory
[04:41] <Keybuk> it returns NULL to indicate no reply received yet
[04:41] <Keybuk> in case of timeout, dbus_pending_call_steal_reply returns an error
[04:42] <Keybuk> in fact, how do we deal with errors at all? :)
[04:42] <sadmac> oh yeah, I hadn't done that yet had I?
[04:42] <Keybuk>         # FIXME: Reply isn't the best parent for this, but proxy isn't here. 
[04:42] <Keybuk> comment doesn't make sense given you use proxy ;)
[04:42] <sadmac> oh, fixed it
[04:43] <Keybuk> should the proxy be passed to the callback function?
[04:43] <Keybuk> I think it makes sense for it to be
[04:43] <Keybuk> in case the callback wants to make more calls
[04:43] <Keybuk> an error handler is going to look like  void (*error_handler) (void *data, NihDBusProxy *proxy;
[04:44] <Keybuk> which I guess means you have to provide both
[04:44] <Keybuk> my_str_to_int (proxy, "foo", get_int, deal_with_error, NULL);
[04:44] <Keybuk> but it's probably ok for the error handler to be NULL
[04:44] <Keybuk> actually
[04:45] <Keybuk> no it's not, let's make that required if a callback is givne
[04:45] <Keybuk> nih_alloc (..., struct) -> nih_new ()!
[04:46] <Keybuk> you don't provide a free function for the pending call
[04:46] <Keybuk> that's kinda important, since otherwise you'll leak the async data structures
[04:46] <Keybuk> the free call might want to do something like call the error handler
[04:46] <Keybuk> setting some useful error
[04:47] <sadmac> ok
[04:47] <Keybuk> so for str_to_int, that'd look something like
[04:47] <Keybuk>   my_str_to_int (proxy, "1234", int_reply, error_handler, data);
[04:47] <Keybuk> with the others being
[04:48] <Keybuk> void int_reply (void *data, NihDBusProxy *proxy, int num);
[04:48] <Keybuk> void error_handler (void *data, NihDBusProxy *proxy);
[04:48] <Keybuk> ( the error would be retrieved with nih_error_get() )
[04:55] <sadmac> Keybuk: we could save a function pointer by just adding an "int succeeded" to the callback
[04:57] <Keybuk> error_handler would be more consistent with other functions
[04:57] <Keybuk> e.g. nih_io
[04:59] <sadmac> Keybuk: did you look at the testcase?
[04:59] <sadmac> there's a bit of conventional intrigue there too
[04:59] <Keybuk> I did, my eyes have not recovered ;)
[05:00] <sadmac> Keybuk: I do like gcc's mandate of the auto keyword in that context
[05:00] <sadmac> "hey, we need to break a grammar ambiguity. Know any keywords that aren't busy?"
[05:06] <Keybuk> hah
[05:07] <sadmac> Keybuk: if you have a better way to structure those I'm open to it. What I like about this method is that the tests still read in the order they're run.
[05:07] <Keybuk> I'll either hate it ...
[05:07] <Keybuk> or convert everything else to use them ;)
[05:08] <Keybuk> ngggarrrrgh
[05:08] <sadmac> huh?
[05:08] <Keybuk> the valgrind error can be replicated with the absolute simplest of code
[05:08] <Keybuk> c = job_class_new (NULL, "foo");
[05:09] <Keybuk> j = job_new (c, NULL);
[05:09] <Keybuk> nih_free (c)
[05:09] <sadmac> that's ugly
[05:09] <Keybuk> the strange thing is that this should all just work now
[05:10] <Keybuk> the whole point of refs is that if you have a pointer, you have a ref
[05:10] <Keybuk> so they should collapse cleanly *sigh*
[05:11] <sadmac> one thing I wish we could do (and I'm nearly certain we can't) is have a NIH_FRAME macro instead of nih_local, and you simply parented things to it to make them have a reference held by the current stack frame
[05:11] <Keybuk> I considered that approach
[05:11] <Keybuk> I decided nih_local was nicer
[05:12] <sadmac> I like having the frame parent, but the things you'd have to do to make it work would offset any nicety.
[05:12] <sadmac> you'd have to hide a var somewhere in the function somehow to run your cleanup
[05:13] <sadmac> or pillage the stack manually
[05:13] <Keybuk> having the frame parent feels a bit like assembler
[05:13] <sadmac> or keep a costack and call everything that uses it through wrappers
[05:13] <Keybuk> just saying "this is local" feels a bit like python ;)
[05:13] <sadmac> I think its the word "frame"
[05:13] <Keybuk> the aim is to simplify the code
[05:14] <Keybuk> you'd have to do something like:
[05:14] <Keybuk>   {
[05:14] <Keybuk>     NIH_LOCAL local;
[05:14] <Keybuk>     char *str;
[05:14] <Keybuk> ...
[05:14] <Keybuk>      str = nih_strdup (local, "foo");
[05:14] <Keybuk>   }
[05:14] <Keybuk> it kinda gets lost in the fog a bit
[05:14] <sadmac> the need to declare it is what kills it
[05:14] <sadmac> and that's what I can't factor out
[05:15] <Keybuk> yeah
[05:15] <Keybuk> if that were
[05:15] <Keybuk>   {
[05:15] <Keybuk>     char *str;
[05:15] <Keybuk> ...
[05:15] <Keybuk>     str = nih_strdup (NIH_LOCAL, "foo");
[05:15] <Keybuk> that would be ok
[05:15] <Keybuk> but I don't think you can declare variables right there ;)
[05:15] <Keybuk> and even if you could, the second use of NIH_LOCAL would break it
[05:15] <sadmac> what I /really/ wish is that you could do this:
[05:15] <Keybuk> (and I see what causes this valgrind bug now ...
[05:16] <Keybuk>  it's the ancient thing-is-in-a-hash-table bug)
[05:16] <sadmac> void foo (char nih_local *bar) {...
[05:16] <Keybuk> class->jobs is a hash table
[05:16] <Keybuk> job is in that
[05:16] <sadmac> and it would make bar nih_local and /ref/ it
[05:16] <Keybuk> when you free job, it removes itself from the hash
[05:16] <Keybuk> but if you free class, the hash should be freed first
[05:16] <Keybuk> sadmac: huh?
[05:17] <Keybuk> how does that work
[05:17] <Keybuk> it's an arg passed in, it's inherently already ref'd by something and you don't need to care
[05:17] <sadmac> Keybuk: pthread_create()
[05:17]  * Keybuk wonders why this valgrind bug doesn't affect old nih_alloc
[05:18] <Keybuk> timestamp: Thu 2006-12-21 00:24:05 +0000
[05:18] <Keybuk> message:
[05:18] <Keybuk>   * nih/io.c (nih_io_message_new): Do not assign a default list
[05:18] <Keybuk>   destructor, it's not in a hidden list and there are bad consequences
[05:18] <Keybuk>   of freeing a child with a default destructor if the list its in gets
[05:18] <Keybuk>   freed first; new rule - default destructors only if the list is hidden
[05:18] <Keybuk>   and never freed!
[05:18] <Keybuk> ...
[05:18] <Keybuk> especially since I apparently hit it over 2 years ago :p
[05:19] <sadmac> Keybuk: if we go thread-safe, stack references are more important, because a piece of code referencing a function doesn't tell us as much about other pieces of code that might be dealing with the memory area
[05:19] <sadmac> that's when things like this become interesting
[05:19] <sadmac> but back to your valgrind issue... have a fix?
[05:26] <Keybuk> no, not yet
[05:26] <Keybuk> I'm trying to understand why it's breaking now first
[05:28] <sadmac> Keybuk: while we're here, I had a hypothesis: why do you put the function types on the line above the name when defining and on the same line when declaring?
[05:29] <Keybuk> common C practice
[05:29] <Keybuk> grep ^function_your_looking_for *.c
[05:29] <Keybuk> as a way of locating the code
[05:30] <sadmac> part A confirmed
[05:30] <sadmac> Keybuk: part B: do you use cscope?
[05:31] <Keybuk> nope
[05:31] <sadmac> mhm
[05:31] <Keybuk> why?
[05:32] <sadmac> Keybuk: the theory is that if you used cscope you wouldn't put the function definition on two lines'
[05:32] <sadmac> Keybuk: because you'd be able to find the function no matter how it was formatted
[05:33] <Keybuk> I use ctags, which are pretty much the same thing
[05:33] <Keybuk> but it's something I find useful in other people's code
[05:33] <Keybuk> so I do it too
[05:33] <Keybuk> and it has the advantage of making a function definition really obvious
[05:35] <sadmac> gives you more space for arguments too
[05:35]  * sadmac used to pride himself on the distant right margin of his VB code
[05:35] <sadmac> ah was I ever that young?
[05:37] <Keybuk> heh
[05:37] <Keybuk> my C coding style is kinda wacky really
[05:37] <Keybuk> like the way I line up argument and variable names
[05:38] <Keybuk> and if (! foo)
[05:39] <sadmac> Keybuk: the putting spaces between function names and open parens kills me. especially now that I'm paid to be in kernel code
[05:39] <Keybuk> haha
[05:39] <Keybuk> someone once said that there are only two types of programmers
[05:40] <Keybuk> those that put a space between function names and their parameters, and those that don;t
[05:40] <sadmac> Keybuk: and the guys who wrote procmail
[05:40] <sadmac> that's definitely a new species
[05:41] <sadmac> fd.o's C style guidelines are pretty backward too
[05:41] <sadmac> 2-space tabs? doing it wrong.
[05:41] <Keybuk> here's a question for you then
[05:42] <Keybuk> if you don't like foo(...)
[05:42] <Keybuk> do you do for(...) ?
[05:42] <sadmac> Keybuk: no, because for is yellow in vim
[05:42] <sadmac> yellow things get a space before the args
[05:43] <sadmac> except for sizeof
[05:43] <sadmac> because linus says so
[05:45] <Keybuk> sizeof shouldn't have ()s
[05:45] <Keybuk> sizeof int
[05:46] <sadmac> you take the size of nicer things than I do
[05:46] <sadmac> sizeof(typeof(**x))
[05:46] <Keybuk> typeof doesn't have ()s either
[05:47] <Keybuk> besideswhich
[05:47] <Keybuk> sizeof/typeof is meaningless
[05:47] <Keybuk> sizeof **x
[05:47] <Keybuk> is the same
[05:47] <sadmac> ...whoa...
[05:47] <sadmac> you're right
[05:49] <sadmac> Keybuk: what about those people that name the function arguments outside of the declaration header?
[05:50] <Keybuk> those people need to stop denying the 80s happened
[05:50] <sadmac> or go code COBOL in a hole somewhere
[05:51] <sadmac> HOLBOL?
[05:51] <Keybuk> arguments outside the header is old-style K&R C
[05:51] <Keybuk> we program in ANSI C nowadays
[05:51] <sadmac> sort of
[05:55] <sadmac> Keybuk: can we add cscope.out to the ignorefile?
[05:57] <Keybuk> no ;)
[05:57] <Keybuk> for the same reason I don't put TAGS in there
[05:58] <Keybuk> (you should only ignore output expected to be generated by the ordinary build process)
[05:59] <sadmac> Keybuk: does bzr have a local ignore?
[06:01] <Keybuk> I don't think so
[06:01] <sadmac> damn
[06:01]  * sadmac misses git
[06:02] <Keybuk> oh, yes
[06:02] <Keybuk> ~/.bazaar/ignore
[06:04] <sadmac> cool
[06:04] <sadmac> bug!
[06:05] <sadmac> as soon as I added a line to ~/.bazaar/ignore, all the object files showed up in bzr status
[06:05] <Keybuk> oh, I think that's deliberate
[06:05] <Keybuk> bzr has a built-in global ignore
[06:05] <Keybuk> if you make a new one, it overrides bzr
[06:06] <sadmac> can I source the normal one?
[06:06] <Keybuk> hmm
[06:06] <Keybuk> did you not have a .bazaar/ignore already ?
[06:06] <Keybuk> you just did echo > .bazaar/ignore
[06:06] <Keybuk> didn't you?
[06:06] <sadmac> FUUUUUUUUUUUUUUUUUUUUUUUUUUUU
[06:06] <Keybuk> rm it
[06:07] <Keybuk> run bzr ignored
[06:07] <Keybuk> then edit it ;)
[06:07] <sadmac> superior usability!
[06:08] <Keybuk> you can't use that word
[06:08] <Keybuk> you like git
[06:09] <sadmac> I /can/ however use my vcs
[06:09]  * sadmac uses interactive rebase to do obscure things you can't even imagine in O(1)
[06:09] <Keybuk> I can use git too, I just strongly dislike it
[06:09] <Keybuk> Linus tells you not to rebase
[06:09] <Keybuk> he says every time someone rebases, he kills a kitten
[06:09] <sadmac> interactive rebase is better than rebase
[06:10] <sadmac> it basically lets you put everything in the repo in any order you want.
[06:10] <sadmac> its like using ed on the object files, but you can play louder techno music
[06:11] <Keybuk> you're not supposed to fuck with the repo
[06:11] <sadmac> I don't get much other action, and the repo understands my needs
[06:11] <sadmac> don't judge me, what we do is beautiful
[06:13] <Keybuk> :D
[06:13] <sadmac> oh /repo/. I thought you said horses.
[06:13] <Keybuk> how equus of you
[06:14] <sadmac> I don't think he actually fucked the horse.
[06:14] <sadmac> He stabbed the horse. He rode the horse naked.
[06:14] <sadmac> Not sure you could stage a fucking in the way that play was supposed to be staged
[06:18] <Keybuk> no idea
[06:18] <sadmac> its kind of a funny image actually...
[06:18] <sadmac> http://www.asiaarts.ucla.edu/media/images/EQUUS%201.jpg
[06:19] <sadmac> that's pretty funny already. If that broke down into some hardcore I'd be seriously amused.
[06:20] <Keybuk> heh
[06:20]  * Keybuk spots the basic difference between old nih_alloc and new nih_alloc
[06:21] <sadmac> o yeah?
[06:21] <Keybuk> revno: 455
[06:21] <Keybuk> committer: Scott James Remnant <scott@netsplit.com>
[06:21] <Keybuk> branch nick: libnih
[06:21] <Keybuk> timestamp: Mon 2007-10-15 23:14:14 +0100
[06:21] <Keybuk> message:
[06:21] <Keybuk>   * nih/alloc.c (nih_alloc_using, nih_alloc_reparent, nih_realloc):
[06:21] <Keybuk>   Change the order in which children allocations are stored in the
[06:21] <Keybuk>   list such that the last allocation is freed first rather than
[06:21] <Keybuk>   the other way around.  This solves issues of children being stored
[06:21] <Keybuk>   inside an allocated hash table which will be freed first.
[06:23] <Keybuk> in other words, old nih_alloc frees things in the opposite order to that they are allocated in
[06:23] <sadmac> that working implies that the parenting ordering is a subset of the allocation ordering
[06:24] <sadmac> its perfectly possible to:
[06:24] <sadmac> 1) allocate item with no parent
[06:24] <sadmac> 2) allocate hash table
[06:24] <sadmac> 3) stick item in hash table
[06:24] <sadmac> in which case this would break
[06:24] <Keybuk> yeah I never really fixed the original bug
[06:24] <Keybuk> I just kept moving it around every time I noticed it ;)
[06:25] <sadmac> what you should do is not free the memory right away but put it into some kind of list, and then free everything in the list only when its know that all the references are stable.
[06:27] <sadmac> nih_free (void *item)
[06:27] <sadmac> {
[06:28] <sadmac>         static int rec_depth = 0;
[06:28] <sadmac>         ...
[06:28] <sadmac>         rec_depth++;
[06:28] <sadmac>         ...
[06:28] <sadmac>         nih_insert_item_into_free_list(item);
[06:29] <sadmac>         if (! --rec_depth) {
[06:29] <sadmac>                 nih_free_all_free_list();
[06:29] <Keybuk> yeah, that's the plan
[06:29] <Keybuk> finalise the object first
[06:37] <sadmac> Keybuk: where do I move the NihAsyncNotifyData struct so it shows up in the C files?
[06:38] <Keybuk> you might have to define something to do that
[06:39] <sadmac> mmh
[06:39]  * sadmac thinks about rewriting all this with a templating engine again
[06:41] <Keybuk> ...with child in older sibling list
[06:41] <Keybuk> BAD: block 0xacd108 (child->entry.next) freed unexpectedly
[06:41] <Keybuk> 	at tests/test_alloc.c:243 (child_destructor_test).
[06:41] <Keybuk> sweet
[06:41] <sadmac> have a testcase then?
[06:42] <Keybuk> I think so
[06:42] <Keybuk> though one passes but fails valgrind
[06:42] <Keybuk> oh, hah
[06:42] <Keybuk> because I'm an idiot
[06:42] <Keybuk> my test case uses TEST_FREE_TAG ... which uses nih_alloc
[06:42] <Keybuk> can't test nih_alloc with TEST_FREE_TAG you dolt
[06:56] <Keybuk> right
[06:57] <Keybuk> I now have two test cases
[06:57] <Keybuk> that both work
[06:57] <Keybuk> if you use _add () the first test case fails
[06:57] <Keybuk> if I change it to _add_after () the second test case fails
[07:01] <sadmac> Keybuk: ok, last I saw I asked about typedefs
[07:06] <Keybuk> I didn't see that
 Keybuk: is there a place to put the typedefs for the callbacks
[07:07] <Keybuk> anything above that?
[07:07] <sadmac> 01:43  * sadmac fixes a longstanding problem with his vimrc
[07:07] <sadmac> then before that you said you were an idiot
[07:08] <Keybuk> heh
[07:08] <Keybuk> not sure if there's a place in the python code
[07:08] <Keybuk> I certainly meant to have one, but may not have added that func
[07:09] <Keybuk> should go at the top, before externPrototypes
[07:38] <sadmac> I'm sleeping now.
[07:47] <Keybuk> heh
[07:47] <Keybuk> I'm just about to do that
[07:47] <Keybuk> I'm worried
[07:47] <Keybuk> my code worked first time
[07:54] <Keybuk> Upstart's test suite largely works too
[07:54] <Keybuk> there's a few failures, but I don't _think_ they are related
[08:07] <Keybuk> (and frankly, the d-bus stuff works - and that really abuses nih_alloc :p)
[08:08] <Keybuk> http://bazaar.launchpad.net/%7Escott/libnih/trunk/revision/639
[08:09] <Keybuk> in summary: first call all the destructors, then free them all
[08:09] <Keybuk> but rather more efficient without the need to recurse ;)
[21:23] <Keybuk> right
[21:23] <Keybuk> you and me, valgrind...
[21:25] <sadmac> Keybuk: what about you, him, and valgrind?
[21:26] <Keybuk> going to fix these remaining test case failures
[21:26] <Keybuk> I'm also trying to decide whether it's a bug to call nih_free () on an object with a parent
[21:26] <Keybuk> ion_: what do you think?
[21:27] <ion_> I’d lean on only allowing to free by unrefing.
[21:27] <ion_> uh, towards
[21:27] <Keybuk> what if you never allocated it with a reference in the first place? :)
[21:28] <sadmac> Keybuk: I'd lean toward /that/ being a bug
[21:28] <sadmac> or rather impossible
[21:28] <Keybuk> well, you have to start somewhere?
[21:28] <ion_> Ah, right, parentless objects don’t have a reference.
[21:28] <ion_> Hmm
[21:28] <Keybuk> otherwise you'd need a global reference, which is basically the same as NULL ;)
[21:28] <sadmac> Keybuk: exactly
[21:28] <Keybuk> so why not use NULL?
[21:29] <Keybuk> the disadvantage of a global reference, and the reason nih_alloc doesn't have one, is that valgrind thinks the object is in use ;)
[21:29] <sadmac> Keybuk: yes. Use NULL by all means.
[21:29] <Keybuk> so doesn't bitch if you forget to free
[21:29] <Keybuk> that was the other main reason I opted for "nih_local" and NULL rather than NIH_LOCAL as the parent
[21:30] <sadmac> Keybuk: you could have a debug mode where you htonl() the refs that are from the root object
[21:32] <Keybuk> huh?
[21:32] <sadmac> Keybuk: "encrypt" references from the root object when -DDEBUG so valgrind can't read them
[21:33] <ion_> How about just making unref() free parentless objects, and behave as before with objects with parents?
[21:35] <Keybuk> that involves having a debug mode though ;)
[21:35] <Keybuk> ion_: nih_unref (ptr, NULL) type thing?
[21:38] <ion_> Or maybe make nih_free barf if the object has parents?
[21:40] <Keybuk> or make nih_free only do something if the object has parents?
[21:46] <ion_> How should it be used then?
[21:46] <ion_> If you nih_new() without a parent and nih_free() it, nothing would happen, right?
[21:47] <Keybuk> I mean if the object hasn't parents
[21:47] <Keybuk> so nih_free() matches nih_new(NULL, ...)
[21:47] <sadmac> Keybuk: what's the difference between what you get from nih_alloc(NULL, ...) and what you have in nih_unref() when you've removed the last ref and its about to be freed
[21:47] <Keybuk> and nih_unref() matches nih_ref() or nih_new(ptr, ...)
[21:47] <Keybuk> sadmac: none
[21:47] <Keybuk> if you like, nih_alloc (NULL, ...) gives you something that's unreferenced, but not free
[21:47] <Keybuk> a bit like gobject's sunken ref ;)
[21:47] <sadmac> Keybuk: that's my issue. its identical to the dead state
[21:48] <Keybuk> it means you can allocate something, add a reference, and then not worry about it
[21:48] <Keybuk> you don't have to drop your own
[21:49] <sadmac> Keybuk: IMHO such an object persisting for any amount of time is as bad as a pointer to already freed memory persisting for any amount of time.
[21:51] <Keybuk> it varies
[21:51] <Keybuk> some reference-counting systems are strict
[21:51] <Keybuk> when you allocate, what you have returned has a single reference
[21:52] <Keybuk> if you pass that to anything and it takes a reference, it must add *another* reference
[21:52] <Keybuk> and if you don't want it anymore, you *must* drop the single reference you had when it was allocated
[21:52] <Keybuk> D-Bus's is like that
[21:52] <sadmac> Keybuk: why does nih_unref() free the object then?
[21:52] <Keybuk> the problem with these is that it's easy to forget to drop the reference you got when you allocated it, or easy to forget to take one when you want it
[21:52] <sadmac> Keybuk: its a valid object still
[21:52] <Keybuk> so others have the concept of a floating reference
[21:53] <Keybuk> when you allocate, what you have has only a floating reference
[21:53] <Keybuk> if anything references it, the floating reference is sunk and turned into a real reference
[21:53] <Keybuk> so when you pass it to things that take a reference, it gets turned into a real one
[21:53] <Keybuk> and since that happens, you don't need to worry about unrefing when you don't want it anymore
[21:53] <Keybuk> ...
[21:53] <Keybuk> non-deliberately, nih_alloc turns out to be a bit like the last one
[21:54] <Keybuk> you can allocate with a reference, or without
[21:54] <Keybuk> if you allocate without, it kinda behaves like a non-explicit floating reference
[21:54] <Keybuk> in reality, it's an unreferenced objetc
[21:54] <Keybuk> this works nicely for things like nih_local
[21:54] <Keybuk> since that only discards unreferenced objects
[21:55] <Keybuk> indeed, there's a call for - nih_discard() - which is a safety "I'm done with an unreferenced object, but am not sure that anyone else took a reference" call
[21:55] <Keybuk> and you can return an object to unrefernced as well - nih_unref_only ()
[21:56] <Keybuk> this is all a bit ... strange really ;)
[21:56] <Keybuk> it's what happens when you design an API by evolution
[21:56] <sadmac> Keybuk: I can see the argument for it existing, but I don't like it as a long-term condition
[21:56] <Keybuk> especially when you turn a simple halloc rip-off, into a talloc rip-off into something that afaik is unique
[21:56] <sadmac> Keybuk: I'd like to think of it as mid-transaction database inconsistency
[21:57] <sadmac> Keybuk: its an error for such a thing to exist, but we defer the error on the grounds of "it'll not be that way anymore in a few lines"
[21:57] <ion_> Perhaps rename nih_free as nih_discard (deleting the present nih_discard) to avoid confusion and make it free the object if it has no parents.
[21:57] <Keybuk> ion_: err, that would be exactly what nih_discard does right now, no? :p
[21:57] <ion_> Indeed.
[21:58] <Keybuk> though would it error if it has parents?
[21:58] <sadmac> Keybuk: so rather rename nih_discard to nih_free, and kill the current nih_free
[21:58] <Keybuk> (nih_discard doesn't)
[21:58] <ion_> No, ignore it if it has parents.
[21:58] <ion_> It shouldn’t be called nih_free if it might not free the object IMO.
[21:59] <Keybuk> nih_free always frees right now
[21:59] <Keybuk> even if it has parents
[21:59] <Keybuk> I tend to agree there though, nih_free would be a bit odd if it didn't always free
[21:59] <ion_> Yes, i suggest getting rid of it. :-)
[21:59] <sadmac> Keybuk: nih_free not always freeing is weird
[22:00] <sadmac> Keybuk: but if you have an interest in API consistency (and it /is/ kind of convenient that we don't have to rewrite all that much right now) it might be better to keep the old symbol/
[22:00] <ion_> So the norm would be to nih_discard anything you allocated without a parent, and nih_unref anything you referenced. No nih_free.
[22:00] <Keybuk> heh
[22:01] <Keybuk> I just made nih_free assert
[22:01] <Keybuk> (if there were parents left)
[22:01] <Keybuk> lots of things broke
[22:01] <ion_> :-)
[22:01] <Keybuk> mostly test cases, by the looks of it
[22:01] <sadmac> Keybuk: what I would prefer is that if you are going to allocate without a parent, you /must/ assign the pointer to an nih_local. dunno what C gives us to enforce that though.
[22:03] <Keybuk> dunno, dig through the gcc ref manual ;)
[22:03] <sadmac> I've learned to like that thing
[22:04] <sadmac> Keybuk: I wonder what happens if you do void * nih_local my_func () {...
[22:05] <Keybuk> the attribute will apply to the function instead of the return value
[22:05] <sadmac> Keybuk: but it can't because its not a function attribute
[22:06] <Keybuk> so gcc will error
[22:06] <Keybuk> return types don't have variable attributes ;)
[22:06] <sadmac> probably
[22:06] <Keybuk> the __attribute__ binds right