pypy / pypy / module / _cffi_backend /

from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.rpython.lltypesystem import lltype, rffi

from pypy.module._cffi_backend import ctypeobj, cdataobj

# ____________________________________________________________

def newp(space, ctype, w_init=None):
    return ctype.newp(w_init)

# ____________________________________________________________

def cast(space, ctype, w_ob):
    return ctype.cast(w_ob)

# ____________________________________________________________

def typeof(space, cdata):
    return cdata.ctype

# ____________________________________________________________

def sizeof(space, w_obj):
    ob = space.interpclass_w(w_obj)
    if isinstance(ob, cdataobj.W_CData):
        # xxx CT_ARRAY
        size = ob.ctype.size
    elif isinstance(ob, ctypeobj.W_CType):
        size = ob.size
        if size < 0:
            raise operationerrfmt(space.w_ValueError,
                                  "ctype '%s' is of unknown size",
        raise OperationError(space.w_TypeError,
                            space.wrap("expected a 'cdata' or 'ctype' object"))
    return space.wrap(size)

def alignof(space, ctype):
    align = ctype.alignof()
    return space.wrap(align)

@unwrap_spec(ctype=ctypeobj.W_CType, fieldname=str)
def offsetof(space, ctype, fieldname):
    ofs = ctype.offsetof(fieldname)
    return space.wrap(ofs)

def _getfields(space, ctype):
    return ctype._getfields()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.