Re: Standalone Pango




On Jun 29, 2008, at 10:20 AM, Torsten Schoenfeld wrote:

As far as I can tell, simply continuing to call gperl_register_* for the old names will not work: the type registry in Glib::Object is not set up to handle anything but a one-to-one relationship between package names and types.

True. But we've run into this before. Here's the last bit of the BOOT section in GType.xs:

        /* i love nasty ugly hacks for backwards compat... Glib::UInt used
         * to be misspelled as Glib::Uint.  by registering both names to the
         * same gtype, we get the mappings for two packages to one gtype, but
         * only one mapping (the last and correct one) from type to package.
         */
        G_LOCK (types_by_package);
        g_hash_table_insert (types_by_package, "Glib::Uint",
                             (gpointer) G_TYPE_UINT);
        G_UNLOCK (types_by_package);

(Please note the sarcasm in the comment.)

We can't use gperl_register_fundamental() here, because that would create the second backwards mapping, which screws up the one-to-one relationship from C to perl types. Instead, it assumes that the C code will always return exactly one name (the new name), and fixes up all references to the old name on the way from perl to C.

We can do this in GType.xs because we're inside the Glib module and have access to those private data structures. To allow Pango to do this, we'd need to create a new set of registration APIs. For example (just spewing from the top of my head):


    /**
     * Set up package_name as a perl-level alias for gtype.
     */
void gperl_register_flags_alias (GType gtype, const char * package_name);

or even get paranoid:

    /**
     * Set up package_name as a perl-level alias for gtype.
* Verifies that preferred_name is already registered as the real package mapping for gtype.
     */
void gperl_register_flags_alias (GType gtype, const char * preferred_name, const char * package_name);



Each of the register foo alias functions would simply to an unpaired insertion into types_by_package for foo.


So, this means that code that does Glib::Object::new ('Gtk2::Pango::Layout') will create a Pango::Layout, and Gtk2::TreeStore->new ('Gtk2::Pango::Weight') will create a Pango::Weight column. When perl code asks the bindings "what type is this", the bindings will respond with the non-Gtk2 names.

It should be rare, but somebody, somewhere, will be checking for exact package names, so we'll have to do extensive beta testing. We could add some @ISAs at the perl level to try to counteract this (e.g., Gtk2::Pango::Layout isa Pango::Layout), but i'm not sure how much it will help.


--
Sallah!  I said no camels!  That's five camels!  Can't you count?
  -- Indiana Jones



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