Files
gnucash/README.guile-hackers
Linas Vepstas c60fa5190a patches from rob browning
1999-08-25  Rob Browning  <rlb@cs.utexas.edu>

        * Add this file (./ChangeLog).  I'm planning to add change
        information here, and I invite others to do the same.  For those
        that use emacs, 'C-x 4 a' adds a new entry.  If people don't like
        this idea, we can drop it.

        * Add new scheme function gnc:choose-item-from-list-dialog.  There
        is C side code, but it's only meant to be called from scheme.
        This function is quite flexible in handles selections.  Eventually
        we might want to generalize this even more, but there are some GC
        issues to consider.  See src/gnome/query-user.c and gnc.gwp for
        details, and see src/scm/extensions.scm for an example usage.

        * IMPORTANT: queryBox signature has changed.  See the docs in
        src/gnome/query-user.c and in gnc.gwp for details.

        * Remove queryBox stubs from Motif side.  Motif doesn't support it
        (yet), and with gnc.gwp conditional inclusion we can just ignore
        it on the motif side.

        * Add function (current-gnc-compile-flavor) to gnc.gwp so that we
        can have conditional blocks.  Possible return values are 'gnome
        and 'motif.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1930 57a11ea4-9604-0410-9ed3-97b8803252fd
1999-08-27 05:06:27 +00:00

70 lines
3.0 KiB
Plaintext

-*-text-*-
This file is intended to contain information for those interested in
working on the guile bits of GnuCash.
I've recently added some GUI functions callable from scheme. This is
generally pretty straightforward, and you can look in the code to see
how I did it, but there are a few bits you have to be careful about.
One of the main sources of useful information is "info guile-ref".
This contains the documentation for all the guile C-side functions
like gh_car(), gh_append(), etc. that manipulate opaque SCM objects
from the guile side.
Given that and a reasonable understanding of GTK/GNOME, you should be
able to follow what I've done.
Garbage collection:
-------------------
One issue to keep in mind is that of garbage collection. You cannot
pass a scheme side item to the C side (through a SCM) and then store
that object off somewhere on the C side such that it lives longer than
all of it's guile side references. If you do, you're likely to get a
crash. The problem is that guile's garbage collector only knows to
save guile items that still have guile side pointers, or that are
found somewhere on the current C side stack. If you store a SCM item
off in a C data structure (say a callback pointer), and then return to
the guile side and drop the guile-side reference to the item, guile
may garbage collect it before it's used by the C side.
For example, this psudeo-code is a problem:
void gnc_some_function(SCM scm_thunk) {
gnc_set_push_button_callback(some_button, scm_thunk);
}
(define (unsafe-guile-function)
(let ((my-callback (lambda () (display "Hello\n"))))
(gnc:some-function my-callback)))
The problem here is that if you call unsafe-guile-function, it
registers the pointer to the anonymous lambda created in the let
construct with the button on the C-side and then returns. As soon as
it returns, guile has no more references to the anonymous lambda, and
it's not on the C stack, so guile thinks it's OK to garbage collect
the function even though the C side has a pointer to it and may still
use it.
The moral of this story is that if you need to have the C side ferret
away a scheme item for later, you must also keep at least one
reference to that item on the guile side until the C side is finished
with it. I believe that the guile people have recently come up with a
nice general solution to this problem, but until that's generally
available, there are a number of ways you can solve this.
If nothing else, you can just create a global hash on the guile side,
place the object in question in the hash table, and then have the
C-side delete that item from the hash when it's finished with it.
Guile Interrupts:
-----------------
Another issue that I'm not quite sure of myself yet is that of
interrupts. Guile has the ability to protect certain segments of code
with SCM_DEFER_INTS/SCM_ALLOW_INTS, but at the moment I'm not sure
when this is required. If anyone gets the chance to check this out
before I do, then please edit this file and put your findings here.