[cairo-commit] rcairo/packages/svgcairo/ext extconf.rb, 1.1, 1.2 rb_svgcairo.c, 1.1, 1.2

Oeyvind Kolaas commit at pdx.freedesktop.org
Thu Feb 10 05:48:35 PST 2005


Committed by: pippin

Update of /cvs/cairo/rcairo/packages/svgcairo/ext
In directory gabe:/tmp/cvs-serv4127/packages/svgcairo/ext

Modified Files:
	extconf.rb rb_svgcairo.c 
Log Message:
added exception handling, and proper passing of FILE*

Index: extconf.rb
===================================================================
RCS file: /cvs/cairo/rcairo/packages/svgcairo/ext/extconf.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- extconf.rb	9 Feb 2005 23:23:24 -0000	1.1
+++ extconf.rb	10 Feb 2005 13:48:33 -0000	1.2
@@ -3,7 +3,7 @@
 
 require 'mkmf'
 
-$CFLAGS = " -I ../../cairo/ext "
+$CFLAGS = " -W -I ../../cairo/ext "
 $CFLAGS  += `pkg-config --cflags libsvg-cairo`
 $LDFLAGS += `pkg-config --libs   libsvg-cairo`
 

Index: rb_svgcairo.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/svgcairo/ext/rb_svgcairo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rb_svgcairo.c	9 Feb 2005 23:23:24 -0000	1.1
+++ rb_svgcairo.c	10 Feb 2005 13:48:33 -0000	1.2
@@ -10,10 +10,63 @@
 
 #include <svg-cairo.h>
 #include <ruby.h>
+#include <rubyio.h>
 #include "rb_cairo.h"
 
-VALUE rb_mSVG_Cairo;
-VALUE rb_cSVG_Cairo_Context;
+static VALUE rb_mSVG_Cairo;
+static VALUE rb_cSVG_Cairo_Context;
+
+static VALUE rb_eSVG_Cairo_FileNotFound;
+static VALUE rb_eSVG_Cairo_InvalidValue;
+static VALUE rb_eSVG_Cairo_InvalidCall;
+static VALUE rb_eSVG_Cairo_ParseError;
+
+static void
+check_status (svg_cairo_status_t  status)
+{
+  switch (status)
+    {
+    case SVG_CAIRO_STATUS_SUCCESS:
+      /* no exception */
+      break;
+    case SVG_CAIRO_STATUS_NO_MEMORY:
+      rb_raise (rb_eNoMemError, "svgcairo out of memory");
+      break;
+    case SVG_CAIRO_STATUS_IO_ERROR:
+      rb_raise (rb_eIOError, "svgcairo IO error");
+      break;
+    case SVG_CAIRO_STATUS_FILE_NOT_FOUND:
+      rb_raise (rb_eSVG_Cairo_FileNotFound, "svgcairo file not found");
+      break;
+    case SVG_CAIRO_STATUS_INVALID_VALUE:
+      rb_raise (rb_eSVG_Cairo_InvalidValue, "svgcairo invalid value");
+      break;
+    case SVG_CAIRO_STATUS_INVALID_CALL:
+      rb_raise (rb_eSVG_Cairo_InvalidCall, "svgcairo invalid call");
+      break;
+    case SVG_CAIRO_STATUS_PARSE_ERROR:
+      rb_raise (rb_eSVG_Cairo_ParseError, "svgcairo parse error");
+      break;
+    }
+   
+}
+
+void
+Init_svgcairo_exception (void)
+{
+  rb_eSVG_Cairo_FileNotFound=
+    rb_define_class_under (rb_mSVG_Cairo, "FileNotFound",
+     rb_eRuntimeError);
+  rb_eSVG_Cairo_InvalidValue=
+    rb_define_class_under (rb_mSVG_Cairo, "InvalidValue",
+     rb_eRuntimeError);
+  rb_eSVG_Cairo_InvalidCall=
+    rb_define_class_under (rb_mSVG_Cairo, "InvalidCall",
+     rb_eRuntimeError);
+  rb_eSVG_Cairo_ParseError=
+    rb_define_class_under (rb_mSVG_Cairo, "ParseError",
+     rb_eRuntimeError);
+}
 
 #define _SELF  ((svg_cairo_t *)DATA_PTR(self))
 
@@ -23,7 +76,7 @@
   svg_cairo_t *xform;
   if (CLASS_OF (value) != rb_cSVG_Cairo_Context)
     {
-      rb_raise (rb_eTypeError, "not a cairo glyph");
+      rb_raise (rb_eTypeError, "not a svgcairo context");
     }
   Data_Get_Struct (value, svg_cairo_t, xform);
   return xform;
@@ -51,7 +104,17 @@
 static    VALUE
 rb_svgcairo_context_parse (VALUE self, VALUE filename_v)
 {
-  svg_cairo_parse (_SELF, STR2CSTR (filename_v));
+  check_status (svg_cairo_parse (_SELF, STR2CSTR (filename_v)));
+  return self;
+}
+
+static    VALUE
+rb_svgcairo_context_parse_file (VALUE self, VALUE port)
+{
+  Check_Type (port, T_FILE);
+  rb_io_check_readable (RFILE (port)->fptr);
+  
+  check_status (svg_cairo_parse_file (_SELF, GetReadFile (RFILE (port)->fptr)));
   return self;
 }
 
@@ -59,14 +122,14 @@
 rb_svgcairo_context_parse_buffer (VALUE self, VALUE buffer_v)
 {
   int len = strlen (STR2CSTR (buffer_v));
-  svg_cairo_parse_buffer (_SELF, STR2CSTR (buffer_v), len);
+  check_status (svg_cairo_parse_buffer (_SELF, STR2CSTR (buffer_v), len));
   return self;
 }
 
 static    VALUE
 rb_svgcairo_context_render (VALUE self, VALUE cairo_context_v)
 {
-  svg_cairo_render (_SELF, rb_v_to_cairo_t (cairo_context_v));
+  check_status (svg_cairo_render (_SELF, rb_v_to_cairo_t (cairo_context_v)));
   return self;
 }
 
@@ -93,8 +156,10 @@
      rb_define_class_under (rb_mSVG_Cairo, "Context", rb_cObject);
   rb_define_singleton_method (rb_cSVG_Cairo_Context, "new",
                               RUBY_METHOD_FUNC (rb_svgcairo_context_new), 0);
-  rb_define_method (rb_cSVG_Cairo_Context, "parse_file",
+  rb_define_method (rb_cSVG_Cairo_Context, "parse",
                     RUBY_METHOD_FUNC (rb_svgcairo_context_parse), 1);
+  rb_define_method (rb_cSVG_Cairo_Context, "parse_file",
+                    RUBY_METHOD_FUNC (rb_svgcairo_context_parse_file), 1);
   rb_define_method (rb_cSVG_Cairo_Context, "parse_string",
                     RUBY_METHOD_FUNC (rb_svgcairo_context_parse_buffer), 1);
   rb_define_method (rb_cSVG_Cairo_Context, "render",
@@ -111,4 +176,5 @@
   rb_mSVG_Cairo = rb_define_module ("SVG_Cairo");
 
   Init_svgcairo_context ();
+  Init_svgcairo_exception ();
 }




More information about the cairo-commit mailing list