[gjs: 27/45] [cairo] Take reference when attaching cairo structs



commit f0ac7061a36344d4f34bb1e6430213d0a68e5a19
Author: Johan Dahlin <johan gnome org>
Date:   Fri Feb 26 17:01:24 2010 -0300

    [cairo] Take reference when attaching cairo structs
    
    Take a reference when constructing a javascript wrapper
    for a cairo struct.

 modules/cairo-context.c         |    3 ++-
 modules/cairo-image-surface.c   |    2 ++
 modules/cairo-linear-gradient.c |    1 +
 modules/cairo-pattern.c         |   11 ++++++++++-
 modules/cairo-pdf-surface.c     |    1 +
 modules/cairo-ps-surface.c      |    1 +
 modules/cairo-radial-gradient.c |    1 +
 modules/cairo-surface-pattern.c |    1 +
 modules/cairo-surface.c         |   19 ++++++++++++++-----
 modules/cairo-svg-surface.c     |    3 ++-
 10 files changed, 35 insertions(+), 8 deletions(-)
---
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index 51ca334..4093da3 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -217,7 +217,7 @@ _gjs_cairo_context_construct_internal(JSContext *context,
 
     priv->context = context;
     priv->object = obj;
-    priv->cr = cr;
+    priv->cr = cairo_reference(cr);
 }
 
 static JSBool
@@ -250,6 +250,7 @@ gjs_cairo_context_constructor(JSContext *context,
         return JS_FALSE;
 
     _gjs_cairo_context_construct_internal(context, obj, cr);
+    cairo_destroy(cr);
 
     return JS_TRUE;
 }
diff --git a/modules/cairo-image-surface.c b/modules/cairo-image-surface.c
index abcf18d..1616e48 100644
--- a/modules/cairo-image-surface.c
+++ b/modules/cairo-image-surface.c
@@ -54,6 +54,7 @@ gjs_cairo_image_surface_constructor(JSContext *context,
         return JS_FALSE;
 
     gjs_cairo_surface_construct(context, obj, surface);
+    cairo_surface_destroy(surface);
 
     return JS_TRUE;
 }
@@ -95,6 +96,7 @@ createFromPNG_func(JSContext *context,
         return JS_FALSE;
     }
     gjs_cairo_surface_construct(context, surface_wrapper, surface);
+    cairo_surface_destroy(surface);
 
     *retval = OBJECT_TO_JSVAL(surface_wrapper);
     return JS_TRUE;
diff --git a/modules/cairo-linear-gradient.c b/modules/cairo-linear-gradient.c
index b37ed7d..6b3271f 100644
--- a/modules/cairo-linear-gradient.c
+++ b/modules/cairo-linear-gradient.c
@@ -54,6 +54,7 @@ gjs_cairo_linear_gradient_constructor(JSContext *context,
         return JS_FALSE;
 
     gjs_cairo_pattern_construct(context, obj, pattern);
+    cairo_pattern_destroy(pattern);
 
     return JS_TRUE;
 }
diff --git a/modules/cairo-pattern.c b/modules/cairo-pattern.c
index 7750db6..dc3ecf6 100644
--- a/modules/cairo-pattern.c
+++ b/modules/cairo-pattern.c
@@ -42,6 +42,15 @@ gjs_cairo_pattern_finalize(JSContext *context,
     g_slice_free(GjsCairoPattern, priv);
 }
 
+/**
+ * gjs_cairo_pattern_construct:
+ * @context: the context
+ * @object: object to construct
+ * @pattern: cairo_pattern to attach to the object
+ *
+ * Constructs a pattern wrapper giving an empty JSObject and a
+ * cairo pattern. A reference to @pattern will be taken.
+ */
 void
 gjs_cairo_pattern_construct(JSContext       *context,
                             JSObject        *obj,
@@ -56,7 +65,7 @@ gjs_cairo_pattern_construct(JSContext       *context,
 
     priv->context = context;
     priv->object = obj;
-    priv->pattern = pattern;
+    priv->pattern = cairo_pattern_reference(pattern);
 }
 
 /* Properties */
diff --git a/modules/cairo-pdf-surface.c b/modules/cairo-pdf-surface.c
index 26838bd..cef856f 100644
--- a/modules/cairo-pdf-surface.c
+++ b/modules/cairo-pdf-surface.c
@@ -60,6 +60,7 @@ gjs_cairo_pdf_surface_constructor(JSContext *context,
     }
 
     gjs_cairo_surface_construct(context, obj, surface);
+    cairo_surface_destroy(surface);
     g_free(filename);
 
     return JS_TRUE;
diff --git a/modules/cairo-ps-surface.c b/modules/cairo-ps-surface.c
index 8f58f7a..fb1fb2f 100644
--- a/modules/cairo-ps-surface.c
+++ b/modules/cairo-ps-surface.c
@@ -60,6 +60,7 @@ gjs_cairo_ps_surface_constructor(JSContext *context,
     }
 
     gjs_cairo_surface_construct(context, obj, surface);
+    cairo_surface_destroy(surface);
     g_free(filename);
 
     return JS_TRUE;
diff --git a/modules/cairo-radial-gradient.c b/modules/cairo-radial-gradient.c
index 3c24166..fdfad23 100644
--- a/modules/cairo-radial-gradient.c
+++ b/modules/cairo-radial-gradient.c
@@ -56,6 +56,7 @@ gjs_cairo_radial_gradient_constructor(JSContext *context,
         return JS_FALSE;
 
     gjs_cairo_pattern_construct(context, obj, pattern);
+    cairo_pattern_destroy(pattern);
 
     return JS_TRUE;
 }
diff --git a/modules/cairo-surface-pattern.c b/modules/cairo-surface-pattern.c
index 841f715..c679137 100644
--- a/modules/cairo-surface-pattern.c
+++ b/modules/cairo-surface-pattern.c
@@ -58,6 +58,7 @@ gjs_cairo_surface_pattern_constructor(JSContext *context,
         return JS_FALSE;
 
     gjs_cairo_pattern_construct(context, obj, pattern);
+    cairo_pattern_destroy(pattern);
 
     return JS_TRUE;
 }
diff --git a/modules/cairo-surface.c b/modules/cairo-surface.c
index 2847826..23e829f 100644
--- a/modules/cairo-surface.c
+++ b/modules/cairo-surface.c
@@ -42,21 +42,30 @@ gjs_cairo_surface_finalize(JSContext *context,
     g_slice_free(GjsCairoSurface, priv);
 }
 
+/**
+ * gjs_cairo_surface_construct:
+ * @context: the context
+ * @object: object to construct
+ * @surface: cairo_surface to attach to the object
+ *
+ * Constructs a surface wrapper giving an empty JSObject and a
+ * cairo surface. A reference to @surface will be taken.
+ */
 void
 gjs_cairo_surface_construct(JSContext       *context,
-                            JSObject        *obj,
+                            JSObject        *object,
                             cairo_surface_t *surface)
 {
     GjsCairoSurface *priv;
 
     priv = g_slice_new0(GjsCairoSurface);
 
-    g_assert(priv_from_js(context, obj) == NULL);
-    JS_SetPrivate(context, obj, priv);
+    g_assert(priv_from_js(context, object) == NULL);
+    JS_SetPrivate(context, object, priv);
 
     priv->context = context;
-    priv->object = obj;
-    priv->surface = surface;
+    priv->object = object;
+    priv->surface = cairo_surface_reference(surface);
 }
 
 /* Properties */
diff --git a/modules/cairo-svg-surface.c b/modules/cairo-svg-surface.c
index 854cc53..93d46f3 100644
--- a/modules/cairo-svg-surface.c
+++ b/modules/cairo-svg-surface.c
@@ -60,8 +60,9 @@ gjs_cairo_svg_surface_constructor(JSContext *context,
     }
 
     gjs_cairo_surface_construct(context, obj, surface);
-
+    cairo_surface_destroy(surface);
     g_free(filename);
+
     return JS_TRUE;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]