Re: patch-review



On Fri, Aug 10, 2007 at 10:03:05PM +0300, Stefan Kost wrote:
> 
> The issue is that probably lots of libs need to call some foreign init. If I
> e.g. don't do that for gst_init (gstreamer) that all my gstreamer subclassed
> types would show up as gobjects.

I think we found a way to get the code there, although it
is a bit ugly.

However, I am still curious why automatic parent type
registration and resolution does not work for you. Try the
attached program (it does not call gst_init() or anything)
and tell me where it gets the types wrong -- or explain what
`would show up as gobjects' means, they are GObject based,
aren't they?

(It prints a thread-initialization error, but that's another
matter.)

Yeti

--
http://gwyddion.net/


=====[ Makefile ]=======================================================
DEPS = gstreamer-base-0.10 gstreamer-net-0.10 gstreamer-controller-0.10 gstreamer-dataprotocol-0.10 gmodule-2.0
LIBTOOL = libtool --tag=CC
PKG_CONFIG = pkg-config
CC = gcc
CFLAGS := -Wall -W -O -ggdb $(shell $(PKG_CONFIG) --cflags $(DEPS))
LDFLAGS := $(shell $(PKG_CONFIG) --libs $(DEPS))

gsttypes: gsttypes.c
	$(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c -o gsttypes.o gsttypes.c
	$(LIBTOOL) --mode=link $(CC) $(LDFLAGS) -export-dynamic -o gsttypes gsttypes.o

clean:
	rm -f gsttypes gsttypes.o gsttypes.lo
	rm -rf .libs
=====[ gsttypes.c ]=====================================================
#include <stdlib.h>
#include <gmodule.h>
#include <glib-object.h>

static const char *typenames[] = {
    "activate_mode", "adapter", "alloc_trace_flags", "assoc_flags",
    "base_sink", "base_src", "base_transform", "bin_flags", "bin",
    "buffer_flag", "buffer", "bus_flags", "bus", "bus_sync_reply",
    "caps_flags", "caps", "child_proxy", "clock_entry_type", "clock_flags",
    "clock", "clock_return", "collect_pads", "controller", "core_error",
    "data_queue", "date", "debug_color_flags", "debug_level", "double_range",
    "dp_version", "element_factory", "element_flags", "element", "event",
    "event_type_flags", "event_type", "flow_return", "format", "fourcc",
    "fraction", "fraction_range", "g_error", "ghost_pad",
    "implements_interface", "index_certainty", "index_entry",
    "index_entry_type", "index_factory", "index_flags", "index",
    "index_lookup_method", "index_resolver_method", "int_range",
    "iterator_item", "iterator_result", "library_error", "message",
    "message_type", "mini_object_flags", "mini_object", "net_client_clock",
    "net_time_provider", "object_flags", "object", "pad_direction",
    "pad_flags", "pad", "pad_link_return", "pad_presence",
    "pad_template_flags", "pad_template", "parse_error", "pipeline_flags",
    "pipeline", "plugin_error", "plugin_feature", "plugin_flags", "plugin",
    "push_src", "query", "query_type", "rank", "registry", "resource_error",
    "seek_flags", "seek_type", "segment", "state_change",
    "state_change_return", "state", "static_caps", "static_pad_template",
    "stream_error", "structure", "system_clock", "tag_flag", "tag_list",
    "tag_merge_mode", "tag_setter", "task", "task_state", "type_find_factory",
    "type_find", "type_find_probability", "uri_handler", "uri_type",
    "value_array", "value_list", "xml",
};

typedef GType (*TypeRegistrar)(void);

static void
dump_type(GType type)
{
    guint i, j, nids, *ids;

    i = 0;
    do {
        g_print("%s%s", i ? " -> " : "", g_type_name(type));
        if (!i && (G_TYPE_IS_INSTANTIATABLE(type)
                   || G_TYPE_IS_INTERFACE(type))) {
            ids = g_signal_list_ids(type, &nids);
            for (j = 0; j < nids; j++) {
                g_print("[%s]", g_signal_name(ids[j]));
            }
            g_free(ids);
        }
        i++;
    } while ((type = g_type_parent(type)));
    g_print("\n");
}

int
main(void)
{
    TypeRegistrar typefunc;
    GString *symbolstr;
    GType type;
    GModule *handle;
    GArray *types;
    guint i;

    g_type_init();

    handle = g_module_open(NULL, G_MODULE_BIND_LAZY);
    if (!handle) {
        g_printerr("Cannot open self: %s\n", g_module_error());
        return EXIT_FAILURE;
    }

    symbolstr = g_string_new(NULL);
    types = g_array_new(FALSE, FALSE, sizeof(GType));
    for (i = 0; i < G_N_ELEMENTS(typenames); i++) {
        g_string_assign(symbolstr, "gst_");
        g_string_append(symbolstr, typenames[i]);
        g_string_append(symbolstr, "_get_type");
        if (!g_module_symbol(handle, symbolstr->str, (gpointer*)&typefunc)) {
            g_printerr("Cannot get %s: %s\n", symbolstr->str, g_module_error());
            continue;
        }
        type = typefunc();
        if (!type) {
            g_printerr("%s returns 0\n", symbolstr->str);
            continue;
        }
        g_array_append_val(types, type);
        if (G_TYPE_IS_CLASSED(type))
            g_type_class_ref(type);
        if (G_TYPE_IS_INTERFACE(type))
            g_type_default_interface_ref(type);
    }
    g_string_free(symbolstr, TRUE);

    g_print("==== INSTANTIABLE ====\n");
    for (i = 0; i < types->len; i++) {
        type = g_array_index(types, GType, i);
        if (G_TYPE_IS_INSTANTIATABLE(type) && !G_TYPE_IS_ABSTRACT(type))
            dump_type(type);
    }
    g_print("==== ABSTRACT ====\n");
    for (i = 0; i < types->len; i++) {
        type = g_array_index(types, GType, i);
        if (G_TYPE_IS_INSTANTIATABLE(type) && G_TYPE_IS_ABSTRACT(type))
            dump_type(type);
    }
    g_print("==== INTERFACES ====\n");
    for (i = 0; i < types->len; i++) {
        type = g_array_index(types, GType, i);
        if (G_TYPE_IS_INTERFACE(type))
            dump_type(type);
    }
    g_print("==== SIMPLE ====\n");
    for (i = 0; i < types->len; i++) {
        type = g_array_index(types, GType, i);
        if (!G_TYPE_IS_INTERFACE(type) && !G_TYPE_IS_INSTANTIATABLE(type)
            && g_type_parent(type))
            dump_type(type);
    }
    g_print("==== FUNDAMENTAL ====\n");
    for (i = 0; i < types->len; i++) {
        type = g_array_index(types, GType, i);
        if (!G_TYPE_IS_INTERFACE(type) && !G_TYPE_IS_INSTANTIATABLE(type)
            && !g_type_parent(type)) {
            g_assert(G_TYPE_IS_FUNDAMENTAL(type));
            dump_type(type);
        }
    }

    g_array_free(types, TRUE);
    g_module_close(handle);

    return 0;
}
========================================================================



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