def parseBridgeSupport(xmldata, globals, frameworkName, dylib_path=None, inlineTab=None):

    if dylib_path:
        lib = ctypes.cdll.LoadLibrary(dylib_path)
        _libraries.append(lib)

    objc._updatingMetadata(True)
    try:
        prs = _BridgeSupportParser(xmldata, frameworkName)

        globals.update(prs.values)
        for entry in prs.cftypes:
            tp = objc.registerCFSignature(*entry)

            globals[entry[0]] = tp

        for name, typestr in prs.opaque:
            globals[name] = objc.createOpaquePointerType(name, typestr)

        for name, typestr, alias in prs.structs:
            if alias is not None:
                globals[name] = alias
                objc.createStructAlias(name, typestr, alias)
            else:
                globals[name] = value = objc.createStructType(name, typestr, None)


        for name, typestr, magic in prs.constants:
            try:
                value = objc._loadConstant(name, _as_string(typestr), magic)
            except AttributeError:
                continue

            globals[name] = value

        for class_name, sel_name, is_class in prs.meta:
            objc.registerMetaDataForSelector(class_name, sel_name, prs.meta[(class_name, sel_name, is_class)])

        if prs.functions:
            objc.loadBundleFunctions(None, globals, prs.functions)

            if inlineTab is not None:
                objc.loadFunctionList(inlineTab, globals, prs.functions)

        for name, orig in prs.func_aliases:
            try:
                globals[name] = globals[orig]
            except KeyError:
                pass

    finally:
        objc._updatingMetadata(False)
Ejemplo n.º 2
0
    def __get_constant(self, name):
        if self.__varmap_dct:
            if name in self.__varmap_dct:
                tp = self.__varmap_dct.pop(name)
                if tp.startswith('='):
                    tp = tp[1:]
                    magic = True
                else:
                    magic = False
                result = objc._loadConstant(name, tp, magic)
                return result

        if self.__varmap:
            m = re.search(r"\$%s(@[^$]*)?\$"%(name,), self.__varmap)
            if m is not None:
                tp = m.group(1)
                if not tp:
                    tp = '@'
                else:
                    tp = tp[1:]

                d = {}
                if tp.startswith('='):
                    tp = tp[1:]
                    magic = True
                else:
                    magic = False

                return objc._loadConstant(name, tp, magic)

        if self.__enummap:
            m = re.search(r"\$%[email protected]([^$]*)\$"%(name,), self.__enummap)
            if m is not None:
                return self.__prs_enum(m.group(1))

        if self.__funcmap:
            if name in self.__funcmap:
                # NOTE: Remove 'name' from funcmap because
                #       it won't be needed anymore (either the
                #       function doesn't exist, or it is loaded)
                #       Should use slightly less memory.
                info = self.__funcmap.pop(name)

                func_list = [ (name,) + info ]

                d = {}
                objc.loadBundleFunctions(self.__bundle, d, func_list)
                if name in d:
                    return d[name]

                if self.__inlinelist is not None:
                    objc.loadFunctionList(
                        self.__inlinelist, d, func_list, skip_undefined=True)
                    if name in d:
                        return d[name]

        if self.__expressions:
            if name in self.__expressions:
                # NOTE: 'name' is popped because it is no longer needed
                #       in the metadata and popping should slightly reduce
                #       memory usage.
                info = self.__expressions.pop(name)
                try:
                    return eval(info, {}, self.__expressions_mapping)
                except: # Ignore all errors in evaluation the expression.
                    pass

        if self.__aliases:
            if name in self.__aliases:
                alias = self.__aliases.pop(name)
                if alias == 'ULONG_MAX':
                    return (sys.maxsize * 2) + 1
                elif alias == 'LONG_MAX':
                    return sys.maxsize
                elif alias == 'LONG_MIN':
                    return -sys.maxsize-1

                return getattr(self, alias)

        raise AttributeError(name)
Ejemplo n.º 3
0
def parseBridgeSupport(xmldata, globals, frameworkName, dylib_path=None, inlineTab=None):

    if dylib_path:
        lib = ctypes.cdll.LoadLibrary(dylib_path)
        _libraries.append(lib)

    objc._updatingMetadata(True)
    try:
        prs = _BridgeSupportParser(xmldata, frameworkName)

        globals.update(prs.values)
        for entry in prs.cftypes:
            tp = objc.registerCFSignature(*entry)

            globals[entry[0]] = tp

        for name, typestr in prs.opaque:
            globals[name] = objc.createOpaquePointerType(name, typestr)

        for name, typestr, alias in prs.structs:
            if alias is not None:
                globals[name] = alias
                objc.createStructAlias(name, typestr, alias)
            else:
                globals[name] = value = objc.createStructType(name, typestr, None)


        for name, typestr, magic in prs.constants:
            try:
                value = objc._loadConstant(name, typestr, magic)
            except AttributeError:
                continue

            globals[name] = value

        for class_name, sel_name, is_class in prs.meta:
            objc.registerMetaDataForSelector(class_name, sel_name, prs.meta[(class_name, sel_name, is_class)])

        for name, method_list in prs.informal_protocols:
            proto = objc.informal_protocol(name, method_list)

            # XXX: protocols submodule should be deprecated
            if "protocols" not in globals:
                mod_name = "%s.protocols"%(frameworkName,)
                m = globals["protocols"] = type(objc)(mod_name)
                sys.modules[mod_name] = m

            else:
                m = globals["protocols"]

            setattr(m, name, proto)

        if prs.functions:
            objc.loadBundleFunctions(None, globals, prs.functions)

            if inlineTab is not None:
                objc.loadFunctionList(inlineTab, globals, prs.functions)

        for name, orig in prs.func_aliases:
            try:
                globals[name] = globals[orig]
            except KeyError:
                pass

    finally:
        objc._updatingMetadata(False)
Ejemplo n.º 4
0
    def __calc_all(self):

        # Ensure that all dynamic entries get loaded
        if self.__varmap_dct:
            dct = {}
            objc.loadBundleVariables(self.__bundle, dct,
                    [ (nm, self.__varmap_dct[nm].encode('ascii'))
                        for nm in self.__varmap_dct if not self.__varmap_dct[nm].startswith('=')])
            for nm in dct:
                if nm not in self.__dict__:
                    self.__dict__[nm] = dct[nm]

            for nm, tp in self.__varmap_dct.items():
                if tp.startswith('='):
                    try:
                        self.__dict__[nm] = objc._loadConstant(nm, tp[1:], True)
                    except AttributeError:
                        pass


            self.__varmap_dct = {}

        if self.__varmap:
            varmap = []
            specials = []
            for nm, tp in re.findall(r"\$([A-Z0-9a-z_]*)(@[^$]*)?(?=\$)", self.__varmap):
                if tp and tp.startswith('@='):
                    specials.append((nm, tp[2:]))
                else:
                    varmap.append((nm, b'@' if not tp else tp[1:].encode('ascii')))

            dct = {}
            objc.loadBundleVariables(self.__bundle, dct, varmap)

            for nm in dct:
                if nm not in self.__dict__:
                    self.__dict__[nm] = dct[nm]

            for nm, tp in specials:
                try:
                    self.__dict__[nm] = objc._loadConstant(nm, tp, True)
                except AttributeError:
                    pass

            self.__varmap = ""

        if self.__enummap:
            for nm, val in re.findall(r"\$([A-Z0-9a-z_]*)@([^$]*)(?=\$)", self.__enummap):
                if nm not in self.__dict__:
                    self.__dict__[nm] = self.__prs_enum(val)

            self.__enummap = ""

        if self.__funcmap:
            func_list = []
            for nm in self.__funcmap:
                if nm not in self.__dict__:
                    func_list.append((nm,) + self.__funcmap[nm])

            dct = {}
            objc.loadBundleFunctions(self.__bundle, dct, func_list)
            for nm in dct:
                if nm not in self.__dict__:
                    self.__dict__[nm] = dct[nm]

            if self.__inlinelist is not None:
                dct = {}
                objc.loadFunctionList(
                    self.__inlinelist, dct, func_list, skip_undefined=True)
                for nm in dct:
                    if nm not in self.__dict__:
                        self.__dict__[nm] = dct[nm]

            self.__funcmap = {}

        if self.__expressions:
            for nm in list(self.__expressions):
                try:
                    getattr(self, nm)
                except AttributeError:
                    pass

        if self.__aliases:
            for nm in list(self.__aliases):
                try:
                    getattr(self, nm)
                except AttributeError:
                    pass

        all_names = set()

        # Add all names that are already in our __dict__
        all_names.update(self.__dict__)

        # Merge __all__of parents ('from parent import *')
        for p in self.__parents:
            try:
                all_names.update(p.__all__)
            except AttributeError:
                all_names.update(dir(p))

        # Add all class names
        all_names.update(cls.__name__ for cls in getClassList())

        return [ v for v in all_names if not v.startswith('_') ]