'Register type *gty* for value *gv*.  Only a weak reference
to *gv* is kept, if possible.'

def _insert_global(self, gv, gty):

    def on_disposal(wr, pop=self._globals.pop):
        pop(wr)
    try:
        gv = weakref.ref(gv, on_disposal)
    except TypeError:
        pass
    self._globals[gv] = gty
