[frogs] My First Patch: issue #1063 |
[ Thread Index |
Date Index
| More lilynet.net/frogs Archives
]
- To: frogs@xxxxxxxxxxx
- Subject: [frogs] My First Patch: issue #1063
- From: Rodolfo Zitellini <xhero.gm@xxxxxxxxx>
- Date: Wed, 19 May 2010 11:46:00 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=GAXj0anjp1oLoz93fjyWdt55zeWnAkEyEaMwxPSpdb4=; b=R7+/ZkSTlfbHgV90vSBdxRRGfY+mk8P0M2vQ58YhhOdNqQqyEyDWnGzI29CmYeD3OV rZMXj6FN5MQ5hCNi5QAQu2E3y4JyEPriodNZSzQq73N8ZBmBku7JJjSVkbfm42ICLS89 oxCTIiXFoV5i01dyQzYxEUGa0Zm/pasmztnrQ=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=WpzNBaafU1bas4iM9VLUUbAuYFxQeFBY1oR9ZaIwJYe6Ww/7qEV0LYUg4+8PcJA2Ca hbDz9qKkc72EUA3J8rfQ1nu4ldLMSVyVsxqWLQtZlE55Eqgz2ddCV4NRTG/lTBttc061 x8wNXIC++yImEgg6I996fPuzKTwYq08bvBNGU=
Hi all,
I made the little patch that should resolve #1063. Was made with diff
-n, and I tried my best to follow GNU coding standards. This is my
first attempt, so please be clement :).
The modifications work like this:
before reverting something, it makes sure another copy of the element
you are reverting is present in the alist, so that you never drop the
original value (this is what happens now when you revert a nested
property non previously overridden).
Comments are welcome! :)
Rodolfo
--- ORIG-nested-property.cc 2010-05-17 05:02:32.000000000 -0400
+++ nested-property.cc 2010-05-19 11:25:06.000000000 -0400
@@ -61,6 +61,8 @@
SCM
nested_property_revert_alist (SCM alist, SCM prop_path)
{
+ int copy_found = 0;
+ bool drop = false;
assert(scm_is_pair (prop_path));
SCM wanted_sym = scm_car (prop_path);
@@ -71,6 +73,7 @@
{
SCM sub_sym = scm_caar (s);
SCM old_val = scm_cdar (s);
+ drop = false;
if (sub_sym == wanted_sym)
{
@@ -84,22 +87,41 @@
*tail = scm_acons (sub_sym, new_val, SCM_EOL);
tail = SCM_CDRLOC(*tail);
+ *tail = scm_cdr (s);
+ return new_list;
}
else
{
- /* old value is dropped. */
+ /* old value should be dropped only if we have another copy of it in the alist */
+ copy_found++;
+ /* Only drop the first instance found.
+ * the overridden value is always the first
+ * if this was the only copy, we will return
+ * the original list anyways so it is not relevant
+ * if we drop this pair
+ */
+ if (copy_found == 1)
+ drop = true;
}
-
- *tail = scm_cdr (s);
- return new_list;
+ /* we now iterate over every item */
}
-
- *tail = scm_acons (sub_sym, old_val, SCM_EOL);
- tail = SCM_CDRLOC (*tail);
+ /* Make a new list with every item
+ * except for the eventual dropped one
+ */
+ if (!drop) {
+ *tail = scm_acons (sub_sym, old_val, SCM_EOL);
+ tail = SCM_CDRLOC (*tail);
+ }
}
- /* Wanted symbol not found: drop newly constructed list. */
- return alist;
+ /* if we find more than one copy of the property
+ * push the new list, else it means we are trying to
+ * revert the original value
+ */
+ if (copy_found > 1)
+ return new_list;
+ else
+ return alist;
}