[Gnucash-changes] r13390 - gnucash/trunk/lib/libqof/qof - Implement QOF_COMMIT_EDIT_PART2 as a function instead of a macro.

Derek Atkins warlord at MIT.EDU
Sun Feb 26 11:57:19 EST 2006


This patch could break a lot of code in lots of places because there
is code that expects that QOF_COMMIT_EDIT_PART2() could return
(exiting the /caller/ of the macro), but the new macro wont return
out of the caller anymore.

A simple fix would be to change the new macro to auto-return:

  #define QOF_COMMIT_EDIT_PART2(inst, on_error, on_done, on_free)         \
    if (qof_commit_edit_part2((inst), (on_error), (on_done), (on_free))) { \
        return; \
    }

However even THAT doesn't quite give you the same behavior as
the old macro.

I'm majorly concerned about this change.

-derek

Chris Shoemaker <chris at cvs.gnucash.org> writes:

> Author: chris
> Date: 2006-02-25 23:56:47 -0500 (Sat, 25 Feb 2006)
> New Revision: 13390
> Trac: http://svn.gnucash.org/trac/changeset/13390
>
> Modified:
>    gnucash/trunk/lib/libqof/qof/qof-be-utils.h
>    gnucash/trunk/lib/libqof/qof/qofbackend.c
> Log:
>    Implement QOF_COMMIT_EDIT_PART2 as a function instead of a macro.
>    Any of the callbacks passed to this function may be NULL to decline the 
>    use of that callback.  Also, the three callbacks are now called in three
>    mutually exclusive cases, corresponding to: 
>       1) a failed commit, ('on_error')
>       2) a successful commit where the object remains valid, ('on_done'), and 
>       3) a successful commit where the object has been destroyed, ('on_free').
>
>
> Modified: gnucash/trunk/lib/libqof/qof/qof-be-utils.h
> ===================================================================
> --- gnucash/trunk/lib/libqof/qof/qof-be-utils.h	2006-02-26 03:30:02 UTC (rev 13389)
> +++ gnucash/trunk/lib/libqof/qof/qof-be-utils.h	2006-02-26 04:56:47 UTC (rev 13390)
> @@ -138,51 +138,28 @@
>   * @param inst: an instance of QofInstance
>   * @param on_error: a function called if there is a backend error.
>   *                void (*on_error)(inst, QofBackendError)
> - * @param on_done: a function called after the commit is complete 
> - *                but before the instect is freed. Perform any other 
> - *                operations after the commit.
> + * @param on_done: a function called after the commit is completed 
> + *                successfully for an object which remained valid.
>   *                void (*on_done)(inst)
> - * @param on_free: a function called if inst->do_free is TRUE. 
> + * @param on_free: a function called if the commit succeeded and the instance
> + *                 is to be freed. 
>   *                void (*on_free)(inst)
> + * 
> + * Note that only *one* callback will be called (or zero, if that
> + * callback is NULL).  In particular, 'on_done' will not be called for
> + * an object which is to be freed.
> + *
> + * Returns TRUE, if the commit succeeded, FALSE otherwise.
>   */
> -#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;                                                     \
> -  }                                                              \
> -}
> +gboolean
> +qof_commit_edit_part2(QofInstance *inst, 
> +                      void (*on_error)(QofInstance *, QofBackendError), 
> +                      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))
> +
>  #endif /* QOF_BE_UTILS_H */
>  /** @} */
>  /** @} */
>
> Modified: gnucash/trunk/lib/libqof/qof/qofbackend.c
> ===================================================================
> --- gnucash/trunk/lib/libqof/qof/qofbackend.c	2006-02-26 03:30:02 UTC (rev 13389)
> +++ gnucash/trunk/lib/libqof/qof/qofbackend.c	2006-02-26 04:56:47 UTC (rev 13390)
> @@ -382,7 +382,51 @@
>    return TRUE;
>  }
>  
> +
>  gboolean
> +qof_commit_edit_part2(QofInstance *inst, 
> +                      void (*on_error)(QofInstance *, QofBackendError), 
> +                      void (*on_done)(QofInstance *), 
> +                      void (*on_free)(QofInstance *)) 
> +{
> +    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);
> +            if (on_error)
> +                on_error(inst, errcode);
> +            return FALSE;
> +        }   
> +        /* XXX the backend commit code should clear dirty!! */
> +        inst->dirty = FALSE;
> +    }
> +    if (inst->do_free) {
> +        if (on_free)
> +            on_free(inst);
> +        return TRUE;
> +    }
> +    if (on_done)
> +        on_done(inst);
> +    return TRUE;
> +}
> +
> +gboolean
>  qof_load_backend_library (const char *directory, 
>  				const char* filename, const char* init_fcn)
>  {
>
> _______________________________________________
> gnucash-changes mailing list
> gnucash-changes at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-changes
>
>

-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available


More information about the gnucash-devel mailing list