[pygobject/invoke-rewrite: 1/3] first checkin of the new caching branch



commit f554cf62848104d31518138ae85bc51acaafda67
Author: John (J5) Palmieri <johnp redhat com>
Date:   Tue Jan 4 18:49:53 2011 -0500

    first checkin of the new caching branch
    
    * this does not compile and is not hooked up to the build system
    * lays out the caching data structures and some skeleton functions

 gi/pygi-cache.c |  480 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 gi/pygi-cache.h |  104 ++++++++++++
 2 files changed, 584 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
new file mode 100644
index 0000000..4c73816
--- /dev/null
+++ b/gi/pygi-cache.c
@@ -0,0 +1,480 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2011 John (J5) Palmieri <johnp redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+
+/* cleanup */
+static inline void
+_pygi_interface_cache_free (PyGIInterfaceCache *cache)
+{
+    if (cache != NULL) {
+        Py_XDECREF(cache->py_type);
+        g_slice_free(PyGIInterfaceCache, cache);
+    }
+}
+
+static inline void
+_pygi_hash_cache_free (PyGIHashCache *cache)
+{
+    if (cache != NULL)
+        g_slice_free(PyGIHashCache, cache);
+}
+
+static inline void
+_pygi_sequence_cache_free (PyGISequenceCache *cache)
+{
+    if (cache != NULL)
+        g_slice_free(PyGISequenceCache, cache);
+}
+
+static inline void
+_pygi_callback_cache_free (PyGICallbackCache *cache)
+{
+    if (cache != NULL)
+        g_slice_free(PyGICallbackCache, cache);
+}
+
+void
+_pygi_arg_cache_clear (PyGIArgCache *cache);
+{
+    cache->is_aux = FALSE;
+    cache->is_pointer = FALSE;
+    cache->direction = 0;
+    g_base_info_unref(cache->arg_info);
+    
+    cache->in_validator = NULL; 
+    cache->in_marshaler = NULL; 
+    cache->out_marshaler = NULL; 
+    cache->cleanup = NULL; 
+
+    _pygi_sequence_cache_free(cache->sequence_cache);
+    cache->sequence_cache = NULL;
+    _pygi_interface_cache_free(cache->interface_cache);
+    cache->interface_cache = NULL;
+    _pygi_hash_cache_free(cache->hash_cache);
+    cache->hash_cache = NULL; 
+    _pygi_callback_cache_free(cache->callback_cache);
+    cache->callback_cache = NULL;
+
+    gint c_arg_index = -1;
+    gint py_arg_index = -1;
+}
+
+void
+_pygi_function_cache_free (PyGIFunctionCache *cache)
+{
+    int i;
+
+    g_slist_free(cache->in_args);
+    g_slist_free(cache->out_args);
+    for (i = 0; i < cache->n_args; i++) {
+        PyGIArgCache *tmp = cache->args_cache[i];
+        _pygi_arg_cache_clear(tmp);
+        g_slice_free(PyGIArgCache, tmp); 
+    }
+
+    g_slice_free(PyGIFunctionCache, cache);
+}
+
+/* cache generation */
+static inline PyGIFunctionCache *
+_function_cache_init(GIFunctionInfo *function_info)
+{
+    PyGIFunctionCache *fc;
+    GIFunctionInfoFlags flags;
+
+    fc = g_slice_new0(PyGIFunctionCache);
+    flags = g_function_info_get_flags(function_info);
+    fc->is_method = flags & GI_FUNCTION_IS_METHOD;
+    fc->is_constructor = flags & GI_FUNCTION_IS_CONSTRUCTOR;
+    fc->n_args = g_callable_info_get_n_args ( (GICallableInfo *) function_info);
+    fc->args_cache = g_slice_alloc0(fc->n_args * sizeof(PyGIArgInfo *));
+
+    return fc;
+}
+
+/* process in args */
+
+static inline boolean
+_arg_cache_generate_metadata_in_void(PyGIArgCache *arg_cache,
+                                     PyGIFunctionCache *function_cache,
+                                     GIArgInfo *arg_info)
+{
+     ac->in_validator = <type validation function pointer>
+     ac->in_marshaler = <type marshaling function pointer>
+     ac->cleanup = <type cleanup function pointer>
+
+     return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_boolean(PyGIArgCache *arg_cache,
+                                        PyGIFunctionCache *function_cache,
+                                        GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_int8(PyGIArgCache *arg_cache,
+                                     PyGIFunctionCache *function_cache,
+                                     GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_uint8(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_int16(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_uint16(PyGIArgCache *arg_cache,
+                                       PyGIFunctionCache *function_cache,
+                                       GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_int32(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_uint32(PyGIArgCache *arg_cache,
+                                       PyGIFunctionCache *function_cache,
+                                       GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_int64(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_uint64(PyGIArgCache *arg_cache,
+                                       PyGIFunctionCache *function_cache,
+                                       GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_float(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_double(PyGIArgCache *arg_cache,
+                                       PyGIFunctionCache *function_cache,
+                                       GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_unichar(PyGIArgCache *arg_cache,
+                                        PyGIFunctionCache *function_cache,
+                                        GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_gtype(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_utf8(PyGIArgCache *arg_cache,
+                                     PyGIFunctionCache *function_cache,
+                                     GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_filename(PyGIArgCache *arg_cache,
+                                         PyGIFunctionCache *function_cache,
+                                         GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_array(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_interface(PyGIArgCache *arg_cache,
+                                          PyGIFunctionCache *function_cache,
+                                          GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_glist(PyGIArgCache *arg_cache,
+                                     PyGIFunctionCache *function_cache,
+                                     GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_gslist(PyGIArgCache *arg_cache,
+                                     PyGIFunctionCache *function_cache,
+                                     GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_ghash(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in_error(PyGIArgCache *arg_cache,
+                                      PyGIFunctionCache *function_cache,
+                                      GIArgInfo *arg_info)
+{
+    return TRUE;
+}
+
+static inline boolean
+_arg_cache_generate_metadata_in(PyGIArgCache *arg_cache,
+                                PyGIFunctionCache *function_cache,
+                                GIArgInfo *arg_info,
+                                GITypeTag type_tag,
+                                gint arg_index)
+{
+    gboolean success = True;
+
+    function_info->n_in_args++; 
+    switch (type_tag) {
+       case GI_TYPE_TAG_VOID:
+           success = _arg_cache_generate_metadata_in_void(arg_cache,
+                                                          function_cache,
+                                                          arg_info);
+           break;
+       case GI_TYPE_TAG_BOOLEAN:
+           success = _arg_cache_generate_metadata_in_boolean(arg_cache,
+                                                             function_cache,
+                                                             arg_info);
+           break;
+       case GI_TYPE_TAG_INT8:
+           success = _arg_cache_generate_metadata_in_int8(arg_cache,
+                                                          function_cache,
+                                                          arg_info);
+           break;
+       case GI_TYPE_TAG_UINT8:
+           success = _arg_cache_generate_metadata_in_uint8(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_INT16:
+           success = _arg_cache_generate_metadata_in_uint16(arg_cache,
+                                                            function_cache,
+                                                            arg_info);
+           break;
+       case GI_TYPE_TAG_UINT16:
+           success = _arg_cache_generate_metadata_in_uint16(arg_cache,
+                                                            function_cache,
+                                                            arg_info);
+           break;
+       case GI_TYPE_TAG_INT32:
+           success = _arg_cache_generate_metadata_in_int32(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_UINT32:
+           success = _arg_cache_generate_metadata_in_uint32(arg_cache,
+                                                            function_cache,
+                                                            arg_info);
+           break;
+       case GI_TYPE_TAG_INT64:
+           success = _arg_cache_generate_metadata_in_int64(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_UINT64:
+           success = _arg_cache_generate_metadata_in_uint64(arg_cache,
+                                                            function_cache,
+                                                            arg_info);
+           break;
+       case GI_TYPE_TAG_FLOAT:
+           success = _arg_cache_generate_metadata_in_float(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_DOUBLE:
+           success = _arg_cache_generate_metadata_in_double(arg_cache,
+                                                            function_cache,
+                                                            arg_info);
+           break;
+       case GI_TYPE_TAG_UNICHAR:
+           success = _arg_cache_generate_metadata_in_unichar(arg_cache,
+                                                             function_cache,
+                                                             arg_info);
+           break;
+       case GI_TYPE_TAG_GTYPE:
+           success = _arg_cache_generate_metadata_in_gtype(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_UTF8:
+           success = _arg_cache_generate_metadata_in_utf8(arg_cache,
+                                                          function_cache,
+                                                          arg_info);
+           break;
+       case GI_TYPE_TAG_FILENAME:
+           success = _arg_cache_generate_metadata_in_filename(arg_cache,
+                                                              function_cache,
+                                                              arg_info);
+           break;
+       case GI_TYPE_TAG_ARRAY:
+           success = _arg_cache_generate_metadata_in_array(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_INTERFACE:
+           success = _arg_cache_generate_metadata_in_interface(arg_cache,
+                                                               function_cache,
+                                                               arg_info);
+           break;
+       case GI_TYPE_TAG_GLIST:
+           success = _arg_cache_generate_metadata_in_glist(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_GSLIST:
+           success = _arg_cache_generate_metadata_in_gslist(arg_cache,
+                                                            function_cache,
+                                                            arg_info);
+           break;
+       case GI_TYPE_TAG_GHASH:
+           success = _arg_cache_generate_metadata_in_ghash(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+       case GI_TYPE_TAG_ERROR:
+           success = _arg_cache_generate_metadata_in_error(arg_cache,
+                                                           function_cache,
+                                                           arg_info);
+           break;
+    }
+
+    function_cache->in_args = 
+        g_slist_append(function_cache->in_args, arg_cache);
+
+    return success;
+}
+
+static inline boolean
+_args_cache_generate(GIFunctionInfo *function_info, 
+                     PyGIFunctionCache *function_cache)
+{
+    for (i = 0; i < function_cache->n_args; i++) {
+        PyGIArgCache *arg_cache;
+        GIArgInfo *arg_info;
+
+        /* must be an aux arg filled in by its owner so skip */
+        if (function_cache->args_cache[i] != NULL)
+            continue;
+
+        arg_info = 
+            g_callable_info_get_arg ( (GICallableInfo *) function_info, i);
+
+        arg_cache = function_cache->args_cache[i] = g_slice_new0(PyGIArgCache);
+        arg_cache->direction = g_arg_info_get_direction (arg_info);
+        type_info = g_base_info_get_type ( (GIBaseInfo *) arg_info);
+        type_tag = g_type_info_get_tag (type_info);
+
+        switch(direction) {
+            case GI_DIRECTION_IN:
+                function_info->n_in_args++;
+                switch (type_tag) {
+                    case GI_TYPE_TAG_...:
+                        ac->in_validator = <type validation function pointer>
+                        ac->in_marshaler = <type marshaling function pointer>
+                        ac->cleanup = <type cleanup function pointer>
+
+                        fc->in_args = g_slist_append(fc->in_args, ac);
+                        break;
+                
+            case GI_DIRECTION_OUT:
+                function_info->n_out_args++;
+ 		    switch (type_tag) {
+                    case GI_TYPE_TAG_...:
+                   
+                        ac->out_marshaler = <type marshaling function pointer>
+                        ac->cleanup = <type cleanup function pointer>
+                        fc->out_args = g_slist_append(fc->out_args, ac);
+                        break;
+           }
+        }
+    }
+}
+
+PyGIFunctionCache *
+_pygi_function_cache_new (GIFunctionInfo *function_info)
+{
+    PyGIFunction *fc = _init_function_cache(function_info);
+    if (!_args_cache_generate(function_info, fc))
+        goto err;
+
+err:
+    _pygi_function_cache_free(fc);
+    return NULL; 
+}
diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h
new file mode 100644
index 0000000..7f98688
--- /dev/null
+++ b/gi/pygi-cache.h
@@ -0,0 +1,104 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ *
+ * Copyright (C) 2011 John (J5) Palmieri <johnp redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+/* placeholders for now */
+typedef gboolean (*PyGIValidateInFunc) (void);
+typedef gboolean (*PyGIMarshalInFunc) (void);
+typedef gboolean (*PyGIMarshalOutFunc) (void);
+typedef gboolean (*PyGIArgCleanupFunc) (gpointer data);
+
+typedef struct _PyGISequenceCache
+{
+    gssize fixed_size; 
+    PyGIValidateFunc *item_validate_func;
+    PyGIMarshalFunc *item_marshal_func;
+    gint len_arg_index;
+    gboolean is_zero_terminated; 
+    gsize item_size;
+    GITypeTag item_tag_type; 
+}
+
+typedef struct _PyGIInterfaceCache
+{
+    gboolean is_foreign; 
+    GType g_type; 
+    PyObject *py_type; 
+} PyGIInterfaceCache;
+
+typedef struct _PyGIHashCache
+{
+    GITypeTag key_type_tag;
+    PyGIValidateFunc *key_validate_func;
+    PyGIMarshalFunc *key_marshal_func;
+    GITypeTag value_type_tag; 
+    PyGIValidateFunc *value_validate_func;
+    PyGIValidateFunc *value_marshal_func;
+} PyGIHashCache;
+
+typedef struct _PyGICallbackCache  
+{
+    gint py_user_data_index;
+    gint user_data_index;
+    gint destroy_notify_index; 
+    GScope scope;
+} PyGICallbackCache; 
+
+typedef struct _PyGIArgCache
+{
+    gboolean is_aux; 
+    gboolean is_pointer; 
+    GIDirection direction; 
+    GIArgInfo *arg_info;
+
+    PyGIValidateInFunc in_validator; 
+    PyGIMashalInFunc in_marshaler; 
+    PyGIMarshalOutFunc out_marshaler; 
+    PyGIArgCleanupFunc cleanup; 
+
+    PyGISequenceCache *sequence_cache; 
+    PyGIInterfaceCache *interface_cache; 
+    PyGIHashCache *hash_cache; 
+    PyCallbackCache *callback_cache;
+
+    gint c_arg_index;
+    gint py_arg_index;
+} PyGIArgCache;
+
+typedef struct _PyGIFunctionCache
+{
+    gboolean is_method;
+    gboolean is_constructor;
+
+    PyGIArgCache **args_cache; 
+    GSList *in_args;
+    GSList *out_arg;
+
+    /* counts */
+    guint n_in_args;
+    guint n_out_args;
+    guint n_args;   
+} PyGIFunctionCache;
+
+void _pygi_arg_cache_clear	(PyGIArgCache *cache);
+void _pygi_function_cache_free	(PyGIFunctionCache *cache);
+
+PyGIFunctionCache *_pygi_generate_function_cache (GIFunctionInfo *function_info);
+



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