[cairo-commit] rcairo/src rb_cairo_surface.c,1.1,1.2

Kouhei Sutou commit at pdx.freedesktop.org
Sat Apr 7 23:04:11 PDT 2007


Committed by: kou

Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv13606/src

Modified Files:
	rb_cairo_surface.c 
Log Message:
* src/rb_cairo_surface.c (ensure_finish_proc): supported
  Cairo::Surface.new with block. If block is exited, a surface is
  finished automatically.
* sample/*.rb: followed the above change.


Index: rb_cairo_surface.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_surface.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_cairo_surface.c	6 Mar 2007 12:17:34 -0000	1.1
+++ rb_cairo_surface.c	8 Apr 2007 06:04:02 -0000	1.2
@@ -294,6 +294,33 @@
 }
 
 static VALUE
+ensure_finish_proc (VALUE self)
+{
+  cairo_surface_t *surface;
+  cairo_status_t status;
+
+  surface = _SELF;
+
+  if (cairo_surface_status (surface))
+    return Qnil;
+
+  cairo_surface_finish (surface);
+
+  status = cairo_surface_status (surface);
+  if (status == CAIRO_STATUS_SUCCESS || status == CAIRO_STATUS_SURFACE_FINISHED)
+    return Qnil;
+
+  cr_surface_check_status (surface);
+  return Qnil;
+}
+
+static void
+ensure_finish (VALUE surface)
+{
+  rb_ensure (rb_yield, surface, ensure_finish_proc, surface);
+}
+
+static VALUE
 cr_surface_get_type (VALUE self)
 {
   return INT2NUM (cairo_surface_get_type (_SELF));
@@ -518,6 +545,8 @@
 
   cr_surface_check_status (surface);
   DATA_PTR (self) = surface;
+  if (rb_block_given_p ())
+    ensure_finish (self);
   return Qnil;
 }
 
@@ -609,6 +638,8 @@
                                                                         \
   cr_surface_check_status (surface);                                    \
   DATA_PTR (self) = surface;                                            \
+  if (rb_block_given_p ())                                              \
+    ensure_finish (self);                                               \
   return Qnil;                                                          \
 }
 



More information about the cairo-commit mailing list