[librsvg/wip/subclass: 1/3] wip: move the mkenums-generated functions to Rust



commit d4c2c600060b66efee47b0a96f89546aa98df859
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Feb 13 12:37:08 2019 -0600

    wip: move the mkenums-generated functions to Rust

 Cargo.lock                  |  2 ++
 Makefile.am                 |  3 +--
 librsvg/rsvg-handle.c       | 14 ++++++++++++++
 librsvg/rsvg.h              |  8 +++++++-
 rsvg_internals/src/c_api.rs | 37 ++++++++++++++++++++++++++++++++++++-
 rsvg_internals/src/error.rs |  2 +-
 rsvg_internals/src/lib.rs   |  6 ++++++
 7 files changed, 67 insertions(+), 5 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index eab89b29..dd00635c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,3 +1,5 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
 [[package]]
 name = "aho-corasick"
 version = "0.6.9"
diff --git a/Makefile.am b/Makefile.am
index 1d3ca9e0..b2ff7b2f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -208,8 +208,7 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_LIBADD = \
 librsvgincdir = $(includedir)/librsvg-$(RSVG_API_VERSION)/librsvg
 librsvginc_HEADERS =                   \
        $(headers)                      \
-       librsvg/librsvg-features.h      \
-       librsvg/librsvg-enum-types.h
+       librsvg/librsvg-features.h
 
 dist_man_MANS = rsvg-convert.1
 
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index de0c38e6..d0e60857 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -191,6 +191,8 @@ extern RsvgHandle *rsvg_handle_rust_new_from_data (const guint8 *data,
 
 /* Implemented in rsvg_internals/src/c_api.rs */
 extern GType rsvg_handle_rust_get_type (void);
+extern GType rsvg_rust_error_get_type (void);
+extern GType rsvg_rust_handle_flags_get_type (void);
 
 GType
 rsvg_handle_get_type (void)
@@ -892,3 +894,15 @@ rsvg_sax_error_cb (void *data, const char *msg, ...)
 
     g_free (buf);
 }
+
+GType
+rsvg_error_get_type(void)
+{
+    return rsvg_rust_error_get_type();
+}
+
+GType
+rsvg_handle_flags_get_type(void)
+{
+    return rsvg_rust_handle_flags_get_type();
+}
diff --git a/librsvg/rsvg.h b/librsvg/rsvg.h
index ed5fd297..5a1957b3 100644
--- a/librsvg/rsvg.h
+++ b/librsvg/rsvg.h
@@ -66,6 +66,9 @@ typedef enum {
 #define RSVG_ERROR (rsvg_error_quark ())
 GQuark rsvg_error_quark (void) G_GNUC_CONST;
 
+GType rsvg_error_get_type (void);
+#define RSVG_TYPE_ERROR (rsvg_error_get_type())
+
 typedef struct _RsvgHandle RsvgHandle;
 typedef struct _RsvgHandleClass RsvgHandleClass;
 typedef struct _RsvgDimensionData RsvgDimensionData;
@@ -206,6 +209,10 @@ typedef enum /*< flags >*/
     RSVG_HANDLE_FLAG_KEEP_IMAGE_DATA = 1 << 1
 } RsvgHandleFlags;
 
+GType rsvg_handle_flags_get_type (void);
+#define RSVG_TYPE_HANDLE_FLAGS (rsvg_handle_flags_get_type())
+
+
 RsvgHandle *rsvg_handle_new_with_flags (RsvgHandleFlags flags);
 
 void        rsvg_handle_set_base_gfile (RsvgHandle *handle,
@@ -294,7 +301,6 @@ const char *rsvg_handle_get_metadata    (RsvgHandle * handle);
 
 G_END_DECLS
 
-#include "librsvg-enum-types.h"
 #include "librsvg-features.h"
 #include "rsvg-cairo.h"
 
diff --git a/rsvg_internals/src/c_api.rs b/rsvg_internals/src/c_api.rs
index 297336be..d2af7786 100644
--- a/rsvg_internals/src/c_api.rs
+++ b/rsvg_internals/src/c_api.rs
@@ -1,4 +1,5 @@
 use std::ops;
+use std::sync::Once;
 use std::{f64, i32};
 
 use libc;
@@ -12,8 +13,9 @@ use glib::value::{FromValue, FromValueOptional, SetValue};
 use glib::{ParamFlags, ParamSpec, StaticType, ToValue, Type, Value};
 
 use glib_sys;
-use gobject_sys;
+use gobject_sys::{self, GEnumValue};
 
+use error::RSVG_ERROR_FAILED;
 use handle::Handle;
 
 extern "C" {
@@ -300,3 +302,36 @@ pub fn get_rust_handle<'a>(handle: *const RsvgHandle) -> &'a Handle {
 pub unsafe extern "C" fn rsvg_handle_rust_get_type() -> glib_sys::GType {
     Handle::get_type().to_glib()
 }
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_rust_error_get_type() -> glib_sys::GType {
+    static ONCE: Once = Once::new();
+    static mut etype: glib_sys::GType = gobject_sys::G_TYPE_INVALID;
+
+    static values: [GEnumValue; 2] = [
+        GEnumValue {
+            value: RSVG_ERROR_FAILED,
+            value_name: b"RSVG_ERROR_FAILED\0" as *const u8 as *const i8,
+            value_nick: b"failed\0" as *const u8 as *const i8,
+        },
+        GEnumValue {
+            value: 0,
+            value_name: 0 as *const _,
+            value_nick: 0 as *const _,
+        },
+    ];
+
+    ONCE.call_once(|| {
+        etype = gobject_sys::g_enum_register_static(
+            b"RsvgError\0" as *const u8 as *const _,
+            &values as *const _,
+        );
+    });
+
+    etype
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn rsvg_rust_handle_flags_get_type() -> glib_sys::GType {
+    unimplemented!();
+}
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index da444f79..8808f5c3 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -324,7 +324,7 @@ pub fn is_value_error<T>(r: &Result<T, ValueErrorKind>) -> bool {
 pub struct RsvgError;
 
 // Keep in sync with rsvg.h:RsvgError
-const RSVG_ERROR_FAILED: i32 = 0;
+pub const RSVG_ERROR_FAILED: i32 = 0;
 
 impl ErrorDomain for RsvgError {
     fn domain() -> glib::Quark {
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 7212d06a..b064a65e 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -40,6 +40,12 @@ extern crate bitflags;
 #[macro_use]
 extern crate glib;
 
+pub use c_api::{
+    rsvg_handle_rust_get_type,
+    rsvg_rust_error_get_type,
+    rsvg_rust_handle_flags_get_type,
+};
+
 pub use color::{rsvg_css_parse_color, ColorKind, ColorSpec};
 
 pub use dpi::rsvg_rust_set_default_dpi_x_y;


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