[Gnucash-changes] r13394 - gnucash/trunk/lib/libqof/qof - replacing the macro to restore programme flow

Neil Williams codehelp at cvs.gnucash.org
Sun Feb 26 13:06:53 EST 2006


Author: codehelp
Date: 2006-02-26 13:06:52 -0500 (Sun, 26 Feb 2006)
New Revision: 13394
Trac: http://svn.gnucash.org/trac/changeset/13394

Modified:
   gnucash/trunk/lib/libqof/qof/qof-be-utils.h
Log:
replacing the macro to restore programme flow

Modified: gnucash/trunk/lib/libqof/qof/qof-be-utils.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qof-be-utils.h	2006-02-26 15:18:55 UTC (rev 13393)
+++ gnucash/trunk/lib/libqof/qof/qof-be-utils.h	2006-02-26 18:06:52 UTC (rev 13394)
@@ -157,9 +157,48 @@
                       void (*on_done)(QofInstance *), 
                       void (*on_free)(QofInstance *));
 
-#define QOF_COMMIT_EDIT_PART2(inst, on_error, on_done, on_free)         \
-    qof_commit_edit_part2((inst), (on_error), (on_done), (on_free))
+/** \brief Macro version of ::qof_commit_edit_part2
 
+\note This macro changes programme flow if the instance is freed.
+*/
+#define QOF_COMMIT_EDIT_PART2(inst,on_error,on_done,on_free) {   \
+  QofBackend * be;                                               \
+                                                                 \
+  /* See if there's a backend.  If there is, invoke it. */       \
+  be = qof_book_get_backend ((inst)->book);                      \
+  if (be && qof_backend_commit_exists(be))                       \
+  {                                                              \
+    QofBackendError errcode;                                     \
+                                                                 \
+    /* clear errors */                                           \
+    do {                                                         \
+      errcode = qof_backend_get_error (be);                      \
+    } while (ERR_BACKEND_NO_ERR != errcode);                     \
+                                                                 \
+    qof_backend_run_commit(be, (inst));                          \
+    errcode = qof_backend_get_error (be);                        \
+    if (ERR_BACKEND_NO_ERR != errcode)                           \
+    {                                                            \
+      /* XXX Should perform a rollback here */                   \
+      (inst)->do_free = FALSE;                                   \
+                                                                 \
+      /* Push error back onto the stack */                       \
+      qof_backend_set_error (be, errcode);                       \
+      (on_error)((inst), errcode);                               \
+    }                                                            \
+    /* XXX the backend commit code should clear dirty!! */       \
+    (inst)->dirty = FALSE;                                       \
+  }                                                              \
+  (on_done)(inst);                                               \
+                                                                 \
+  LEAVE ("inst=%p, dirty=%d do-free=%d",                         \
+            (inst), (inst)->dirty, (inst)->do_free);             \
+  if ((inst)->do_free) {                                         \
+     (on_free)(inst);                                            \
+     return;                                                     \
+  }                                                              \
+}
+
 #endif /* QOF_BE_UTILS_H */
 /** @} */
 /** @} */



More information about the gnucash-changes mailing list