[cairo] fflush in copy_page

TOKUNAGA Hiroyuki tkng at xem.jp
Thu Sep 16 12:49:31 PDT 2004


Hi,

On Thu, 16 Sep 2004 17:50:01 +0200 (CEST)
Jost Boekemeier <jost2345 at yahoo.de> wrote:

> > The binding is for Gauche, a scheme interpreter.
> 
> That's very good!  Would it possible to write the code
> so that it could be used by other scheme implementations, too?

Of course reuse of binding itself is impossible. But because the
correspondence between C api and Scheme api is straightforward, reuse of
Scheme code wouldn't be so difficult.

> > cairo_png_surface_create
> > receive a file pointer as its arguments, and file
> > pointer has a
> > buffering feature.
> 
> Assuming your users call 
> 
>  (call-with-output-file
>   (lambda (port)
>     (cairo-png-surface-create 
>      port 
>      (cairo-get-std-format) 
>      10 10)
>     ...
>    ) "/tmp/test.png")

I assumed following usage, but there's no problem with your code.

(define port (open-output-file "/tmp/test.png"))
(define surface (cairo-png-surface-create port CAIRO_FORMAT_ARGB32 10 10))
... some drawing functions ...
(cairo-show-page cr)
(close-output-port port)


> Your C code would extract the FILE pointer from the
> port and then call cairo_png_surface_create().
> It also registers a callback that is called when the
> scheme implementation wants to close the port (because
> of call/cc we cannot close the port when the user
> escapes from the above procedure).  So shortly before
> the port is gc'ed, the callback is called and the file
> is closed.

I didn't notice your idea, replacing the port closer function. ScmPort
struct is exposed in gauche.h, so surely we can choose this solution.
But with this approach, we have to have a reference to the file pointer
in somewhere, because each fdopen calling returns a new file pointer.
There would be no way to keep reference, except keeping the reference to
the file pointer as a global variable, and I think it's messy.
Personally I don't want to implement this approach, because my patch is
simpler, only 2 lines!

But if my patch is rejected, your solution would be the best and I'll
implement it.


> > We don't have a reference to file pointer in the
> 
> How do you implement ports?

I don't implement ports, I use a function Scm_PortFileNo.
Scm_PortFileNo(port) returns a file descriptor if port is connected to a
file.


Regards,

-- 
TOKUNAGA Hiroyuki
tkng at xem.jp
http://kodou.net/



More information about the cairo mailing list