当前位置: 首页>>代码示例>>Python>>正文


Python rffi.free_charp函数代码示例

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


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

示例1: test_ascii_codec

    def test_ascii_codec(self, space, api):
        s = 'abcdefg'
        data = rffi.str2charp(s)
        w_u = api.PyUnicode_DecodeASCII(data, len(s), lltype.nullptr(rffi.CCHARP.TO))
        assert space.eq_w(w_u, space.wrap(u"abcdefg"))
        rffi.free_charp(data)

        s = 'abcd\xFF'
        data = rffi.str2charp(s)
        self.raises(space, api, UnicodeDecodeError, api.PyUnicode_DecodeASCII,
                    data, len(s), lltype.nullptr(rffi.CCHARP.TO))
        rffi.free_charp(data)

        uni = u'abcdefg'
        data = rffi.unicode2wcharp(uni)
        w_s = api.PyUnicode_EncodeASCII(data, len(uni), lltype.nullptr(rffi.CCHARP.TO))
        assert space.eq_w(space.wrap("abcdefg"), w_s)
        rffi.free_wcharp(data)

        u = u'äbcdéfg'
        data = rffi.unicode2wcharp(u)
        w_s = api.PyUnicode_EncodeASCII(data, len(u), lltype.nullptr(rffi.CCHARP.TO))
        self.raises(space, api, UnicodeEncodeError, api.PyUnicode_EncodeASCII,
                    data, len(u), lltype.nullptr(rffi.CCHARP.TO))
        rffi.free_wcharp(data)
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_unicodeobject.py

示例2: execv_lltypeimpl

 def execv_lltypeimpl(path, args):
     l_path = rffi.str2charp(path)
     l_args = rffi.liststr2charpp(args)
     os_execv(l_path, l_args)
     rffi.free_charpp(l_args)
     rffi.free_charp(l_path)
     raise OSError(rffi.c_errno, "execv failed")
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:ll_os.py

示例3: SetPythonHome

 def SetPythonHome(self,path):
     return
     impl = self.lib.getpointer("Py_SetPythonHome",[clibffi.ffi_type_pointer],clibffi.ffi_type_void)
     buf = rffi.str2charp(path)
     impl.push_arg(buf)
     impl.call(lltype.Void)
     rffi.free_charp(buf)
开发者ID:Averroes,项目名称:esky,代码行数:7,代码来源:pypy_libpython.py

示例4: getattr

    def getattr(self, space, attr):
        try:
            attribute = self.objectType.attributesByName[attr]
        except KeyError:
            msg = "ExternalObject has no attribute '%s'" %(attr,)
            raise OperationError(space.w_AttributeError, space.wrap(msg))

        environment = self.objectType.environment

        scalarvalueindicatorptr = lltype.malloc(rffi.CArrayPtr(roci.OCIInd).TO,
                                                1, flavor='raw')
        valueindicatorptr = lltype.malloc(rffi.CArrayPtr(roci.dvoidp).TO,
                                          1, flavor='raw')
        valueptr = lltype.malloc(rffi.CArrayPtr(roci.dvoidp).TO,
                                 1, flavor='raw')
        tdoptr = lltype.malloc(rffi.CArrayPtr(roci.OCIType).TO,
                               1, flavor='raw')
        nameptr = lltype.malloc(rffi.CArrayPtr(roci.oratext).TO,
                               1, flavor='raw')
        nameptr[0] = rffi.str2charp(attr)
        namelenptr = lltype.malloc(rffi.CArrayPtr(roci.ub4).TO,
                                   1, flavor='raw')
        namelenptr[0] = rffi.cast(roci.ub4, len(attr))

        try:
            status = roci.OCIObjectGetAttr(
                environment.handle,
                environment.errorHandle,
                self.instance,
                self.indicator,
                self.objectType.tdo,
                nameptr, namelenptr, 1,
                lltype.nullptr(roci.Ptr(roci.ub4).TO), 0,
                scalarvalueindicatorptr,
                valueindicatorptr,
                valueptr,
                tdoptr)
            environment.checkForError(
                status, "ExternalObject_GetAttributeValue(): getting value")

            # determine the proper null indicator
            valueIndicator = valueindicatorptr[0]
            if not valueIndicator:
                valueIndicator = rffi.cast(roci.dvoidp,
                                           scalarvalueindicatorptr)
            value = valueptr[0]

            return convertObject(
                space, environment,
                attribute.typeCode,
                value, valueIndicator,
                self, attribute.subType)
        finally:
            lltype.free(scalarvalueindicatorptr, flavor='raw')
            lltype.free(valueindicatorptr, flavor='raw')
            lltype.free(valueptr, flavor='raw')
            lltype.free(tdoptr, flavor='raw')
            rffi.free_charp(nameptr[0])
            lltype.free(nameptr, flavor='raw')
            lltype.free(namelenptr, flavor='raw')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:60,代码来源:interp_object.py

示例5: strcoll

def strcoll(space, w_s1, w_s2):
    "string,string -> int. Compares two strings according to the locale."

    if space.is_true(space.isinstance(w_s1, space.w_str)) and \
       space.is_true(space.isinstance(w_s2, space.w_str)):

        s1, s2 = space.str_w(w_s1), space.str_w(w_s2)
        s1_c = rffi.str2charp(s1)
        s2_c = rffi.str2charp(s2)
        try:
            return space.wrap(_strcoll(s1_c, s2_c))
        finally:
            rffi.free_charp(s1_c)
            rffi.free_charp(s2_c)

    #if not space.is_true(space.isinstance(w_s1, space.w_unicode)) and \
    #   not space.is_true(space.isinstance(w_s2, space.w_unicode)):
    #    raise OperationError(space.w_ValueError,
    #                         space.wrap("strcoll arguments must be strings"))

    s1, s2 = space.unicode_w(w_s1), space.unicode_w(w_s2)

    s1_c = rffi.unicode2wcharp(s1)
    s2_c = rffi.unicode2wcharp(s2)
    try:
        result = _wcscoll(s1_c, s2_c)
    finally:
        rffi.free_wcharp(s1_c)
        rffi.free_wcharp(s2_c)

    return space.wrap(result)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:interp_locale.py

示例6: strxfrm

def strxfrm(space, s):
    "string -> string. Returns a string that behaves for cmp locale-aware."
    n1 = len(s) + 1

    buf = lltype.malloc(rffi.CCHARP.TO, n1, flavor="raw", zero=True)
    s_c = rffi.str2charp(s)
    try:
        n2 = _strxfrm(buf, s_c, n1) + 1
    finally:
        rffi.free_charp(s_c)
    if n2 > n1:
        # more space needed
        lltype.free(buf, flavor="raw")
        buf = lltype.malloc(rffi.CCHARP.TO, intmask(n2),
                            flavor="raw", zero=True)
        s_c = rffi.str2charp(s)
        try:
            _strxfrm(buf, s_c, n2)
        finally:
            rffi.free_charp(s_c)

    val = rffi.charp2str(buf)
    lltype.free(buf, flavor="raw")

    return space.wrap(val)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:interp_locale.py

示例7: test_overflow_neg

 def test_overflow_neg(self, api):
     s = rffi.str2charp('-1e500')
     null = lltype.nullptr(rffi.CCHARPP.TO)
     r = api.PyOS_string_to_double(s, null, None)
     assert math.isinf(r)
     assert r < 0
     rffi.free_charp(s)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_pystrtod.py

示例8: demo

def demo(filename):
    width = 800
    height = 600
    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,width,height)
    cr = cairo_create(surface)
    cairo_scale(cr, width, height)
    cairo_set_line_width(cr, 0.04)

    
    cairo_arc(cr, 0.5, 0.5, 0.3, 0, 2 * pi)
    cairo_clip(cr)
    
    cairo_new_path(cr) # current path is not
                       # consumed by cairo_clip()
    cairo_rectangle(cr, 0, 0, 1, 1)
    cairo_fill(cr)
    cairo_set_source_rgb(cr, 0, 1, 0)
    cairo_move_to(cr, 0, 0)
    cairo_line_to(cr, 1, 1)
    cairo_move_to(cr, 1, 0)
    cairo_line_to(cr, 0, 1)
    cairo_stroke(cr)

    #_cairo_surface_write_to_png(surface, 'foo.png') # XXX why does this fail to compile ??
    path = rffi.str2charp(filename)
    cairo_surface_write_to_png(surface, path)
    rffi.free_charp(path)

    cairo_destroy(cr)
    cairo_surface_destroy(surface)
    return 0
开发者ID:antoine1fr,项目名称:pygirl,代码行数:31,代码来源:test_ll_cairo.py

示例9: SetValue

def SetValue(space, w_hkey, w_subkey, typ, value):
    """SetValue(key, sub_key, type, value) - Associates a value with a specified key.

key is an already open key, or any one of the predefined HKEY_* constants.
sub_key is a string that names the subkey with which the value is associated.
type is an integer that specifies the type of the data.  Currently this
 must be REG_SZ, meaning only strings are supported.
value is a string that specifies the new value.

If the key specified by the sub_key parameter does not exist, the SetValue
function creates it.

Value lengths are limited by available memory. Long values (more than
2048 bytes) should be stored as files with the filenames stored in
the configuration registry.  This helps the registry perform efficiently.

The key identified by the key parameter must have been opened with
KEY_SET_VALUE access."""
    if typ != rwinreg.REG_SZ:
        errstring = space.wrap("Type must be _winreg.REG_SZ")
        raise OperationError(space.w_ValueError, errstring)
    hkey = hkey_w(w_hkey, space)
    if space.is_w(w_subkey, space.w_None):
        subkey = None
    else:
        subkey = space.str_w(w_subkey)
    dataptr = rffi.str2charp(value)
    try:
        ret = rwinreg.RegSetValue(hkey, subkey, rwinreg.REG_SZ, dataptr, len(value))
    finally:
        rffi.free_charp(dataptr)
    if ret != 0:
        raiseWindowsError(space, ret, "RegSetValue")
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:interp_winreg.py

示例10: test_setitemstring

 def test_setitemstring(self, space, api):
     w_d = space.newdict()
     key = rffi.str2charp("key")
     api.PyMapping_SetItemString(w_d, key, space.wrap(42))
     assert 42 == space.unwrap(
         api.PyMapping_GetItemString(w_d, key))
     rffi.free_charp(key)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_mapping.py

示例11: test

        def test(encoded, endian, realendian=None):
            encoded_charp = rffi.str2charp(encoded)
            strict_charp = rffi.str2charp("strict")
            if endian is not None:
                if endian < 0:
                    value = -1
                elif endian > 0:
                    value = 1
                else:
                    value = 0
                pendian = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
                pendian[0] = rffi.cast(rffi.INT, value)
            else:
                pendian = None

            w_ustr = api.PyUnicode_DecodeUTF16(encoded_charp, len(encoded), strict_charp, pendian)
            assert space.eq_w(space.call_method(w_ustr, 'encode', space.wrap('ascii')),
                              space.wrap("abcd"))

            rffi.free_charp(encoded_charp)
            rffi.free_charp(strict_charp)
            if pendian:
                if realendian is not None:
                    assert rffi.cast(rffi.INT, realendian) == pendian[0]
                lltype.free(pendian, flavor='raw')
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:test_unicodeobject.py

示例12: Run_SimpleString

 def Run_SimpleString(self,string):
     impl = self.lib.getpointer("PyRun_SimpleString",[libffi.ffi_type_pointer],libffi.ffi_type_sint)
     buf = rffi.str2charp(string)
     impl.push_arg(buf)
     res = impl.call(rffi.INT)
     rffi.free_charp(buf)
     if res < 0:
         self._error()
开发者ID:AndrewIsaac,项目名称:mastr-ms,代码行数:8,代码来源:pypy_libpython.py

示例13: test_incremental

 def test_incremental(self, space, api):
     utf8 = rffi.str2charp('utf-8')
     w_encoder = api.PyCodec_IncrementalEncoder(utf8, None)
     w_encoded = space.call_method(w_encoder, 'encode', space.wrap(u'späm'))
     w_decoder = api.PyCodec_IncrementalDecoder(utf8, None)
     w_decoded = space.call_method(w_decoder, 'decode', w_encoded)
     assert space.unwrap(w_decoded) == u'späm'
     rffi.free_charp(utf8)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_codecs.py

示例14: buffer_dealloc

def buffer_dealloc(space, py_obj):
    py_buf = rffi.cast(PyBufferObject, py_obj)
    if py_buf.c_b_base:
        Py_DecRef(space, py_buf.c_b_base)
    else:
        rffi.free_charp(rffi.cast(rffi.CCHARP, py_buf.c_b_ptr))
    from pypy.module.cpyext.object import PyObject_dealloc
    PyObject_dealloc(space, py_obj)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:bufferobject.py

示例15: test_overflow_exc

 def test_overflow_exc(self, space, api):
     s = rffi.str2charp('1e500')
     null = lltype.nullptr(rffi.CCHARPP.TO)
     r = api.PyOS_string_to_double(s, null, space.w_ValueError)
     assert r == -1.0
     raises(ValueError)
     api.PyErr_Clear()
     rffi.free_charp(s)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_pystrtod.py


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