• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python support.cdecl函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.translator.c.support.cdecl函数的典型用法代码示例。如果您正苦于以下问题:Python cdecl函数的具体用法?Python cdecl怎么用?Python cdecl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了cdecl函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: visitor_lines

 def visitor_lines(self, prefix, on_item):
     assert self.varlength == 1
     ARRAY = self.ARRAY
     # we need a unique name for this C variable, or at least one that does
     # not collide with the expression in 'prefix'
     i = 0
     varname = 'p0'
     while prefix.find(varname) >= 0:
         i += 1
         varname = 'p%d' % i
     body = list(on_item('(*%s)' % varname, ARRAY.OF))
     if body:
         yield '{'
         yield '\t%s = %s.items;' % (cdecl(self.itemtypename, '*' + varname),
                                     prefix)
         yield '\t%s = %s + %s.length;' % (cdecl(self.itemtypename,
                                                 '*%s_end' % varname),
                                           varname,
                                           prefix)
         yield '\twhile (%s != %s_end) {' % (varname, varname)
         for line in body:
             yield '\t\t' + line
         yield '\t\t%s++;' % varname
         yield '\t}'
         yield '}'
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:node.py


示例2: get

    def get(self, obj, funcgen=None):
        if isinstance(obj, CConstant):
            return obj.c_name  # without further checks
        T = typeOf(obj)
        if isinstance(T, Primitive) or T == GCREF:
            return PrimitiveName[T](obj, self)
        elif isinstance(T, Ptr):
            if (isinstance(T.TO, OpaqueType) and
                T.TO.hints.get('c_pointer_typedef') is not None):
                if obj._obj is not None:
                    value = rffi.cast(rffi.SSIZE_T, obj)
                    return '((%s) %s)' % (cdecl(self.gettype(T), ''),
                                          self.get(value))
            if obj:   # test if the ptr is non-NULL
                try:
                    container = obj._obj
                except lltype.DelayedPointer:
                    # hack hack hack
                    name = obj._obj0
                    assert name.startswith('delayed!')
                    n = len('delayed!')
                    if len(name) == n:
                        raise
                    if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
                        if obj in self.idelayedfunctionnames:
                            return self.idelayedfunctionnames[obj][0]
                        funcname = name[n:]
                        funcname = self.namespace.uniquename('g_'+funcname)
                        self.idelayedfunctionnames[obj] = funcname, obj
                    else:
                        funcname = None      # can't use the name of a
                                             # delayed non-function ptr
                    self.delayedfunctionptrs.append(obj)
                    return funcname
                    # /hack hack hack
                else:
                    # hack hack hack
                    if obj in self.idelayedfunctionnames:
                        # this used to be a delayed function,
                        # make sure we use the same name
                        forcename = self.idelayedfunctionnames[obj][0]
                        node = self.getcontainernode(container,
                                                     forcename=forcename)
                        assert node.getptrname() == forcename
                        return forcename
                    # /hack hack hack

                if isinstance(container, int):
                    # special case for tagged odd-valued pointers
                    return '((%s) %d)' % (cdecl(self.gettype(T), ''),
                                          obj._obj)
                node = self.getcontainernode(container)
                if node._funccodegen_owner is None:
                    node._funccodegen_owner = funcgen
                return node.getptrname()
            else:
                return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
        else:
            raise Exception("don't know about %r" % (obj,))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:database.py


示例3: OP_FLAVORED_MALLOC_VARSIZE

    def OP_FLAVORED_MALLOC_VARSIZE(self, op):
        # XXX this function should DIE!, at least twice over
        # XXX I know this working in just one case, probably makes
        # sense to assert it here, rest is just copied
        flavor = op.args[0].value
        assert flavor == 'raw'
        TYPE = self.lltypemap(op.result).TO
        assert isinstance(TYPE, Array)
        assert TYPE._hints.get('nolength', False)
        # </obscure hack>
        typename = self.db.gettype(TYPE)
        lenfld = 'length'
        nodedef = self.db.gettypedefnode(TYPE)
        if isinstance(TYPE, Struct):
            arfld = TYPE._arrayfld
            lenfld = "%s.length" % nodedef.c_struct_field_name(arfld)
            VARPART = TYPE._flds[TYPE._arrayfld]
        else:
            VARPART = TYPE
        assert isinstance(VARPART, Array)
        itemtypename = self.db.gettype(VARPART.OF)
        elength = self.expr(op.args[2])
        eresult = self.expr(op.result)
        erestype = cdecl(typename, '*')
        if VARPART.OF is Void:    # strange
            esize = 'sizeof(%s)' % (cdecl(typename, ''),)
            result = '{\n'
        else:
            itemtype = cdecl(itemtypename, '')
            result = 'IF_VARSIZE_OVERFLOW(%s, %s, %s)\nelse {\n' % (
                elength,
                itemtype,
                eresult)
            esize = 'sizeof(%s)-sizeof(%s)+%s*sizeof(%s)' % (
                cdecl(typename, ''),
                itemtype,
                elength,
                itemtype)

        # ctypes Arrays have no length field
        if not VARPART._hints.get('nolength', False):
            result += '\nif(%s) %s->%s = %s;' % (eresult, eresult, lenfld, elength)
        if flavor == "raw": 
            result += "OP_RAW_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
        elif flavor == "stack": 
            result += "OP_STACK_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
        elif flavor == "cpy":
            xxx # this will never work, as I don't know which arg it would be
            # tests, tests, tests....
            cpytype = self.expr(op.args[2])
            result += "OP_CPY_MALLOC(%s, %s, %s);" % (cpytype, eresult, erestype)
        else:
            raise NotImplementedError
        
        result += '\n}'
        return result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:56,代码来源:funcgen.py


示例4: get

    def get(self, obj):
        if isinstance(obj, ErrorValue):
            T = obj.TYPE
            if isinstance(T, Primitive):
                return PrimitiveErrorValue[T]
            elif isinstance(T, Ptr):
                return 'NULL'
            else:
                raise Exception("don't know about %r" % (T,))
        else:
            T = typeOf(obj)
            if isinstance(T, Primitive):
                return PrimitiveName[T](obj, self)
            elif isinstance(T, Ptr):
                if obj:   # test if the ptr is non-NULL
                    try:
                        container = obj._obj
                    except lltype.DelayedPointer:
                        # hack hack hack
                        name = obj._obj0
                        assert name.startswith('delayed!')
                        n = len('delayed!')
                        if len(name) == n:
                            raise
                        if id(obj) in self.delayedfunctionnames:
                            return self.delayedfunctionnames[id(obj)][0]
                        funcname = name[n:]
                        funcname = self.namespace.uniquename('g_' + funcname)
                        self.delayedfunctionnames[id(obj)] = funcname, obj
                        self.delayedfunctionptrs.append(obj)
                        return funcname
                        # /hack hack hack
                    else:
                        # hack hack hack
                        if id(obj) in self.delayedfunctionnames:
                            # this used to be a delayed function,
                            # make sure we use the same name
                            forcename = self.delayedfunctionnames[id(obj)][0]
                            node = self.getcontainernode(container,
                                                         forcename=forcename)
                            assert node.ptrname == forcename
                            return forcename
                        # /hack hack hack

                    if isinstance(container, int):
                        # special case for tagged odd-valued pointers
                        return '((%s) %d)' % (cdecl(self.gettype(T), ''),
                                              obj._obj)
                    node = self.getcontainernode(container)
                    return node.ptrname
                else:
                    return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
            else:
                raise Exception("don't know about %r" % (obj,))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:54,代码来源:database.py


示例5: definition

 def definition(self):
     gcpolicy = self.db.gcpolicy
     yield 'struct %s {' % self.name
     for fname, typename in self.gcfields:
         yield '\t' + cdecl(typename, fname) + ';'
     if not self.ARRAY._hints.get('nolength', False):
         yield '\tlong length;'
     line = '%s;' % cdecl(self.itemtypename, 'items[%d]'% self.varlength)
     if self.ARRAY.OF is Void:    # strange
         line = '/* %s */' % line
     yield '\t' + line
     yield '};'
开发者ID:antoine1fr,项目名称:pygirl,代码行数:12,代码来源:node.py


示例6: get

    def get(self, obj):
        # XXX extra indent is preserve svn blame - kind of important IMHO (rxe)
        if 1:
            if isinstance(obj, CConstant):
                return obj.c_name  # without further checks
            T = typeOf(obj)
            if isinstance(T, Primitive) or T == GCREF:
                return PrimitiveName[T](obj, self)
            elif isinstance(T, Ptr):
                if obj:   # test if the ptr is non-NULL
                    try:
                        container = obj._obj
                    except lltype.DelayedPointer:
                        # hack hack hack
                        name = obj._obj0
                        assert name.startswith('delayed!')
                        n = len('delayed!')
                        if len(name) == n:
                            raise
                        if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
                            if id(obj) in self.delayedfunctionnames:
                                return self.delayedfunctionnames[id(obj)][0]
                            funcname = name[n:]
                            funcname = self.namespace.uniquename('g_'+funcname)
                            self.delayedfunctionnames[id(obj)] = funcname, obj
                        else:
                            funcname = None      # can't use the name of a
                                                 # delayed non-function ptr
                        self.delayedfunctionptrs.append(obj)
                        return funcname
                        # /hack hack hack
                    else:
                        # hack hack hack
                        if id(obj) in self.delayedfunctionnames:
                            # this used to be a delayed function,
                            # make sure we use the same name
                            forcename = self.delayedfunctionnames[id(obj)][0]
                            node = self.getcontainernode(container,
                                                         forcename=forcename)
                            assert node.ptrname == forcename
                            return forcename
                        # /hack hack hack

                    if isinstance(container, int):
                        # special case for tagged odd-valued pointers
                        return '((%s) %d)' % (cdecl(self.gettype(T), ''),
                                              obj._obj)
                    node = self.getcontainernode(container)
                    return node.ptrname
                else:
                    return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
            else:
                raise Exception("don't know about %r" % (obj,))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:53,代码来源:database.py


示例7: forward_declaration

 def forward_declaration(self):
     hash_typename = self.get_hash_typename()
     hash_offset = self.db.gctransformer.get_hash_offset(self.T)
     yield '%s {' % cdecl(hash_typename, '')
     yield '\tunion {'
     yield '\t\t%s;' % cdecl(self.implementationtypename, 'head')
     yield '\t\tchar pad[%s];' % name_signed(hash_offset, self.db)
     yield '\t} u;'
     yield '\tlong hash;'
     yield '};'
     yield '%s;' % (
         forward_cdecl(hash_typename, '_hash_' + self.name,
                       self.db.standalone, self.is_thread_local()),)
     yield '#define %s _hash_%s.u.head' % (self.name, self.name)
开发者ID:enyst,项目名称:plexnet,代码行数:14,代码来源:node.py


示例8: forward_declaration

 def forward_declaration(self):
     T = self.getTYPE()
     assert self.typename == self.implementationtypename  # no array part
     hash_typename = self.get_hash_typename()
     hash_offset = self.db.gctransformer.get_hash_offset(T)
     yield "%s {" % cdecl(hash_typename, "")
     yield "\tunion {"
     yield "\t\t%s;" % cdecl(self.implementationtypename, "head")
     yield "\t\tchar pad[%s];" % name_signed(hash_offset, self.db)
     yield "\t} u;"
     yield "\tlong hash;"
     yield "};"
     yield "%s;" % (forward_cdecl(hash_typename, "_hash_" + self.name, self.db.standalone, self.is_thread_local()),)
     yield "#define %s _hash_%s.u.head" % (self.name, self.name)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:14,代码来源:node.py


示例9: definition

 def definition(self):
     gcpolicy = self.db.gcpolicy
     yield "struct %s {" % self.name
     for fname, typename in self.gcfields:
         yield "\t" + cdecl(typename, fname) + ";"
     if not self.ARRAY._hints.get("nolength", False):
         yield "\tlong length;"
     line = "%s;" % cdecl(self.itemtypename, "items[%d]" % self.varlength)
     if self.ARRAY.OF is Void:  # strange
         line = "/* array of void */"
         if self.ARRAY._hints.get("nolength", False):
             line = "char _dummy; " + line
     yield "\t" + line
     yield "};"
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:14,代码来源:node.py


示例10: OP_DEBUG_LLINTERPCALL

 def OP_DEBUG_LLINTERPCALL(self, op):
     result = "abort();  /* debug_llinterpcall should be unreachable */"
     TYPE = self.lltypemap(op.result)
     if TYPE is not Void:
         typename = self.db.gettype(TYPE)
         result += "\n%s = (%s)0;" % (self.expr(op.result), cdecl(typename, ""))
     return result
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:7,代码来源:funcgen.py


示例11: OP_CAST_WEAKADR_TO_PTR

 def OP_CAST_WEAKADR_TO_PTR(self, op):
     TYPE = self.lltypemap(op.result)
     assert TYPE != PyObjPtr
     typename = self.db.gettype(TYPE)
     return '%s = (%s)REVEAL_POINTER(%s);' % (self.expr(op.result),
                                                cdecl(typename, ''),
                                                self.expr(op.args[0]))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:funcgen.py


示例12: implementation

 def implementation(self):
     hash_typename = self.get_hash_typename()
     hash = self.db.gcpolicy.get_prebuilt_hash(self.obj)
     assert hash is not None
     lines = list(self.initializationexpr())
     lines.insert(0, "%s = { {" % (cdecl(hash_typename, "_hash_" + self.name, self.is_thread_local()),))
     lines.append("}, %s /* hash */ };" % name_signed(hash, self.db))
     return lines
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:8,代码来源:node.py


示例13: name_signed

def name_signed(value, db):
    if isinstance(value, Symbolic):
        if isinstance(value, FieldOffset):
            structnode = db.gettypedefnode(value.TYPE)
            return 'offsetof(%s, %s)'%(
                cdecl(db.gettype(value.TYPE), ''),
                structnode.c_struct_field_name(value.fldname))
        elif isinstance(value, ItemOffset):
            if value.TYPE != Void:
                return '(sizeof(%s) * %s)'%(
                    cdecl(db.gettype(value.TYPE), ''), value.repeat)
            else:
                return '0'
        elif isinstance(value, ArrayItemsOffset):
            if isinstance(value.TYPE, FixedSizeArray):
                return '0'
            elif value.TYPE.OF != Void:
                return 'offsetof(%s, items)'%(
                    cdecl(db.gettype(value.TYPE), ''))
            else:
                return 'sizeof(%s)'%(cdecl(db.gettype(value.TYPE), ''),)
        elif isinstance(value, ArrayLengthOffset):
            return 'offsetof(%s, length)'%(
                cdecl(db.gettype(value.TYPE), ''))
        elif isinstance(value, CompositeOffset):
            names = [name_signed(item, db) for item in value.offsets]
            return '(%s)' % (' + '.join(names),)
        elif type(value) == AddressOffset:
            return '0'
        elif type(value) == GCHeaderOffset:
            return '0'
        elif isinstance(value, CDefinedIntSymbolic):
            return str(value.expr)
        elif isinstance(value, ComputedIntSymbolic):
            value = value.compute_fn()
        elif isinstance(value, CConstant):
            return value.c_name
        else:
            raise Exception("unimplemented symbolic %r"%value)
    if value is None:
        assert not db.completed
        return None
    if value == -sys.maxint-1:   # blame C
        return '(-%dL-1L)' % sys.maxint
    else:
        return '%dL' % value
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:46,代码来源:primitive.py


示例14: OP_FLAVORED_MALLOC

 def OP_FLAVORED_MALLOC(self, op):
     # XXX this function should DIE!
     TYPE = self.lltypemap(op.result).TO
     typename = self.db.gettype(TYPE)
     eresult = self.expr(op.result)
     esize = 'sizeof(%s)' % cdecl(typename, '')
     erestype = cdecl(typename, '*')
     flavor = op.args[0].value
     if flavor == "raw": 
         return "OP_RAW_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
     elif flavor == "stack": 
         return "OP_STACK_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
     elif flavor == "cpy":
         cpytype = self.expr(op.args[2])
         return "OP_CPY_MALLOC(%s, %s, %s);" % (cpytype, eresult, erestype)
     else:
         raise NotImplementedError
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:17,代码来源:funcgen.py


示例15: implementation

 def implementation(self):
     if llgroup.member_of_group(self.obj):
         return []
     lines = list(self.initializationexpr())
     lines[0] = '%s = %s' % (
         cdecl(self.implementationtypename, self.name, self.is_thread_local()),
         lines[0])
     lines[-1] += ';'
     return lines
开发者ID:enyst,项目名称:plexnet,代码行数:9,代码来源:node.py


示例16: ptr_access_expr

 def ptr_access_expr(self, baseexpr, fldname):
     if self.STRUCT._hints.get("inline_head"):
         first, FIRST = self.STRUCT._first_struct()
         if fldname == first:
             # "invalid" cast according to C99 but that's what CPython
             # requires and does all the time :-/
             return "(*(%s) %s)" % (cdecl(self.db.gettype(FIRST), "*"), baseexpr)
     fldname = self.c_struct_field_name(fldname)
     return "RPyField(%s, %s)" % (baseexpr, fldname)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:node.py


示例17: gettype

 def gettype(self, T, varlength=1, who_asks=None, argnames=[]):
     if isinstance(T, Primitive) or T == GCREF:
         return PrimitiveType[T]
     elif isinstance(T, Typedef):
         return '%s @' % T.c_name
     elif isinstance(T, Ptr):
         if (isinstance(T.TO, OpaqueType) and
             T.TO.hints.get('c_pointer_typedef') is not None):
             return '%s @' % T.TO.hints['c_pointer_typedef']
         try:
             node = self.gettypedefnode(T.TO)
         except NoCorrespondingNode:
             pass
         else:
             if hasattr(node, 'getptrtype'):
                 return node.getptrtype()   # special-casing because of C
         typename = self.gettype(T.TO)   # who_asks not propagated
         return typename.replace('@', '*@')
     elif isinstance(T, (Struct, Array, _WeakRefType)):
         node = self.gettypedefnode(T, varlength=varlength)
         if who_asks is not None:
             who_asks.dependencies[node] = True
         return node.gettype()
     elif T == PyObject:
         return 'PyObject @'
     elif isinstance(T, FuncType):
         resulttype = self.gettype(T.RESULT)
         argtypes = []
         for i in range(len(T.ARGS)):
             if T.ARGS[i] is not Void:
                 argtype = self.gettype(T.ARGS[i])
                 try:
                     argname = argnames[i]
                 except IndexError:
                     argname = ''
                 argtypes.append(cdecl(argtype, argname))
         argtypes = ', '.join(argtypes) or 'void'
         return resulttype.replace('@', '(@)(%s)' % argtypes)
     elif isinstance(T, OpaqueType):
         if T == RuntimeTypeInfo:
             return  self.gcpolicy.rtti_type()
         elif T.hints.get("render_structure", False):
             node = self.gettypedefnode(T, varlength=varlength)
             if who_asks is not None:
                 who_asks.dependencies[node] = True
             return 'struct %s @' % node.name
         elif T.hints.get('external', None) == 'C':
             return '%s @' % T.hints['c_name']
         else:
             #raise Exception("don't know about opaque type %r" % (T,))
             return 'struct %s @' % (
                 valid_identifier('pypy_opaque_' + T.tag),)
     elif isinstance(T, llgroup.GroupType):
         return "/*don't use me*/ void @"
     else:
         raise Exception("don't know about type %r" % (T,))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:56,代码来源:database.py


示例18: definition

 def definition(self):
     gcpolicy = self.db.gcpolicy
     yield 'struct %s {' % self.name
     for fname, typename in self.gcfields:
         yield '\t' + cdecl(typename, fname) + ';'
     if not self.ARRAY._hints.get('nolength', False):
         yield '\tlong length;'
     line = '%s;' % cdecl(self.itemtypename, 'items[%d]'% self.varlength)
     if self.ARRAY.OF is Void:    # strange
         line = '/* array of void */'
         if self.ARRAY._hints.get('nolength', False):
             line = 'char _dummy; ' + line
     yield '\t' + line
     yield '};'
     if self.varlength != 1:
         yield 'union %su {' % self.name
         yield '  struct %s a;' % self.name
         yield '  %s;' % cdecl(self.normalizedtypename, 'b')
         yield '};'
开发者ID:ieure,项目名称:pypy,代码行数:19,代码来源:node.py


示例19: OP_CAST_PRIMITIVE

 def OP_CAST_PRIMITIVE(self, op):
     TYPE = self.lltypemap(op.result)
     val =  self.expr(op.args[0])
     ORIG = self.lltypemap(op.args[0])
     if ORIG is Char:
         val = "(unsigned char)%s" % val
     elif ORIG is UniChar:
         val = "(unsigned long)%s" % val
     result = self.expr(op.result)
     typename = cdecl(self.db.gettype(TYPE), '')        
     return "%(result)s = (%(typename)s)(%(val)s);" % locals()
开发者ID:ieure,项目名称:pypy,代码行数:11,代码来源:funcgen.py



注:本文中的pypy.translator.c.support.cdecl函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_genc.compile函数代码示例发布时间:2022-05-27
下一篇:
Python genc.CStandaloneBuilder类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap