[cairo-commit] rcairo/src rb_cairo_context.c, 1.14, 1.15 rb_cairo_private.c, 1.3, 1.4 rb_cairo_private.h, 1.3, 1.4 rb_cairo_scaled_font.c, 1.2, 1.3

Kouhei Sutou commit at pdx.freedesktop.org
Fri May 18 07:07:59 PDT 2007


Committed by: kou

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

Modified Files:
	rb_cairo_context.c rb_cairo_private.c rb_cairo_private.h 
	rb_cairo_scaled_font.c 
Log Message:
* src/rb_cairo_private.[ch] (rb_cairo__glyphs_to_array,
  RB_CAIRO__GLYPHS_TO_ARRAY): fixed wrong memory allocation.
* src/rb_cairo_context.c, src/rb_cairo_scaled_font.c: used
  RB_CAIRO__GLYPHS_TO_ARRAY instead of rb_cairo__glyphs_to_array().


Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_context.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- rb_cairo_context.c	18 May 2007 12:24:59 -0000	1.14
+++ rb_cairo_context.c	18 May 2007 14:07:48 -0000	1.15
@@ -398,7 +398,7 @@
 
   rb_scan_args(argc, argv, "11", &dash_array, &rb_offset);
 
-  is_num = rb_cairo__is_kind_of (dash_array, rb_cNumeric));
+  is_num = rb_cairo__is_kind_of (dash_array, rb_cNumeric);
   if (!(NIL_P (dash_array) || is_num))
     {
       Check_Type (dash_array, T_ARRAY);
@@ -1100,10 +1100,7 @@
   int count;
   cairo_glyph_t *glyphs;
 
-  if (!rb_cairo__is_kind_of (rb_glyphs, rb_cArray))
-     rb_raise (rb_eTypeError, "expected array");
-
-  rb_cairo__glyphs_to_array (rb_glyphs, &glyphs, &count);
+  RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
   cairo_show_glyphs (_SELF, glyphs, count);
   cr_check_status (_SELF);
   return self;
@@ -1152,7 +1149,7 @@
   cairo_glyph_t *glyphs;
   int length;
 
-  rb_cairo__glyphs_to_array (rb_glyphs, &glyphs, &length);
+  RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, length);
   cairo_glyph_extents (_SELF, glyphs, length, &extents);
   cr_check_status (_SELF);
   return CRTEXTEXTENTS2RVAL (&extents);
@@ -1172,7 +1169,7 @@
   int count;
   cairo_glyph_t *glyphs;
 
-  rb_cairo__glyphs_to_array (rb_glyphs, &glyphs, &count);
+  RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
   cairo_glyph_path (_SELF, glyphs, count);
   cr_check_status (_SELF);
 

Index: rb_cairo_private.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rb_cairo_private.c	3 May 2007 02:47:39 -0000	1.3
+++ rb_cairo_private.c	18 May 2007 14:07:48 -0000	1.4
@@ -31,22 +31,13 @@
 }
 
 void
-rb_cairo__glyphs_to_array (VALUE rb_array, cairo_glyph_t **glyphs, int *length)
+rb_cairo__glyphs_to_array (VALUE rb_array, cairo_glyph_t *glyphs, int length)
 {
   int i;
-  
-  if (!rb_cairo__is_kind_of (rb_array, rb_cArray))
-     rb_raise (rb_eTypeError, "expected array");
-
-  *length = RARRAY(rb_array)->len;
-  *glyphs = ALLOCA_N (cairo_glyph_t, *length);
 
-  if (!*glyphs)
-    rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY);
-
-  for (i = 0; i < *length; i++)
+  for (i = 0; i < length; i++)
     {
-      memcpy ((char *) &(*glyphs)[i],
+      memcpy ((char *) &glyphs[i],
               (char *) RVAL2CRGLYPH (rb_ary_entry (rb_array, i)),
               sizeof (cairo_glyph_t));
     }

Index: rb_cairo_private.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_private.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rb_cairo_private.h	3 May 2007 02:47:39 -0000	1.3
+++ rb_cairo_private.h	18 May 2007 14:07:48 -0000	1.4
@@ -39,8 +39,21 @@
 extern void Init_cairo_pattern (void);
 extern void Init_cairo_glyph (void);
 
+#define RB_CAIRO__GLYPHS_TO_ARRAY(rb_array, glyphs, length)     \
+do                                                              \
+  {                                                             \
+    Check_Type (rb_array, T_ARRAY);                             \
+    length = RARRAY (rb_array)->len;                            \
+    glyphs = ALLOCA_N (cairo_glyph_t, length);                  \
+                                                                \
+    if (!glyphs)                                                \
+      rb_cairo_check_status (CAIRO_STATUS_NO_MEMORY);           \
+                                                                \
+    rb_cairo__glyphs_to_array (rb_array, glyphs, length);       \
+  } while (0)
+
 VALUE rb_cairo__float_array (double *values, unsigned count);
-void rb_cairo__glyphs_to_array (VALUE rb_array, cairo_glyph_t **glyphs, int *length);
+void rb_cairo__glyphs_to_array (VALUE rb_array, cairo_glyph_t *glyphs, int length);
 
 VALUE rb_cairo__const_get (VALUE name, const char *prefix);
 cairo_bool_t rb_cairo__is_kind_of (VALUE object, VALUE klass);

Index: rb_cairo_scaled_font.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_scaled_font.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rb_cairo_scaled_font.c	3 May 2007 02:47:39 -0000	1.2
+++ rb_cairo_scaled_font.c	18 May 2007 14:07:48 -0000	1.3
@@ -114,7 +114,7 @@
   cairo_glyph_t *glyphs;
   int count;
 
-  rb_cairo__glyphs_to_array (rb_glyphs, &glyphs, &count);
+  RB_CAIRO__GLYPHS_TO_ARRAY (rb_glyphs, glyphs, count);
   cairo_scaled_font_glyph_extents (_SELF (self), glyphs, count, &extents);
   cr_scaled_font_check_status (_SELF (self));
   return CRTEXTEXTENTS2RVAL (&extents);



More information about the cairo-commit mailing list