[pypy-svn] r32404 - pypy/dist/pypy/rpython/rctypes
arigo at codespeak.net
arigo at codespeak.net
Sun Sep 17 12:12:51 CEST 2006
Author: arigo
Date: Sun Sep 17 12:12:50 2006
New Revision: 32404
Modified:
pypy/dist/pypy/rpython/rctypes/apointer.py
pypy/dist/pypy/rpython/rctypes/rarray.py
pypy/dist/pypy/rpython/rctypes/rpointer.py
Log:
Arrays of length 0 are lots of fun.
Modified: pypy/dist/pypy/rpython/rctypes/apointer.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/apointer.py (original)
+++ pypy/dist/pypy/rpython/rctypes/apointer.py Sun Sep 17 12:12:50 2006
@@ -68,7 +68,9 @@
# POINTER(varsized_array_type): given that rctypes performs
# no index checking, this pointer-to-array type is equivalent
# to a pointer to an array of whatever size.
- RESTYPE = POINTER(s_arg.ctype_array._type_ * 0)
+ # ('0' is a bad idea, though, as FixedSizeArrays of length 0
+ # tend to say they have impossible items.)
+ RESTYPE = POINTER(s_arg.ctype_array._type_ * 1)
else:
# POINTER(constant_ctype) returns the constant annotation
# corresponding to the POINTER(ctype).
Modified: pypy/dist/pypy/rpython/rctypes/rarray.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rarray.py (original)
+++ pypy/dist/pypy/rpython/rctypes/rarray.py Sun Sep 17 12:12:50 2006
@@ -1,5 +1,6 @@
from ctypes import ARRAY, c_int
-from pypy.rpython.lltypesystem.rstr import string_repr
+from pypy.rpython.error import TyperError
+from pypy.rpython.lltypesystem.rstr import string_repr, emptystr
from pypy.rpython.rmodel import IntegerRepr, inputconst
from pypy.rpython.rslice import AbstractSliceRepr
from pypy.rpython.lltypesystem import lltype
@@ -65,9 +66,12 @@
assert s_attr.is_constant()
assert s_attr.const == 'value'
assert self.r_item.ll_type == lltype.Char # .value: char arrays only
- v_box = hop.inputarg(self, 0)
hop.exception_cannot_occur()
- return hop.gendirectcall(ll_chararrayvalue, v_box)
+ if self.length == 0:
+ return hop.inputconst(lltype.typeOf(emptystr), emptystr)
+ else:
+ v_box = hop.inputarg(self, 0)
+ return hop.gendirectcall(ll_chararrayvalue, v_box)
def get_c_data_of_item(self, llops, v_array, v_index):
v_c_array = self.get_c_data(llops, v_array)
@@ -144,9 +148,12 @@
class __extend__(pairtype(ArrayRepr, AbstractSliceRepr)):
def rtype_getitem((r_array, r_slic), hop):
rs = hop.rtyper.type_system.rslice
+ hop.exception_cannot_occur()
if r_slic == rs.startstop_slice_repr:
# slicing: char array only
assert r_array.r_item.ll_type == lltype.Char
+ if r_array.length == 0:
+ return hop.inputconst(lltype.typeOf(emptystr), emptystr)
v_array, v_slice = hop.inputargs(r_array, rs.startstop_slice_repr)
return hop.gendirectcall(ll_chararrayslice, v_array, v_slice)
raise TyperError('getitem does not support slices with %r' % (r_slic,))
Modified: pypy/dist/pypy/rpython/rctypes/rpointer.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rpointer.py (original)
+++ pypy/dist/pypy/rpython/rctypes/rpointer.py Sun Sep 17 12:12:50 2006
@@ -37,8 +37,8 @@
llops.genop('setfield', inputargs)
def initialize_const(self, p, ptr):
- if ptr is None: # passed as argument to functions expecting pointers
- return
+ if not ptr: # NULL pointer, or literal None passed as argument to
+ return # functions expecting pointers
llcontents = self.r_contents.convert_const(ptr.contents)
p.c_data[0] = llcontents.c_data
# the following line is probably pointless, as 'llcontents' will be
More information about the Pypy-commit
mailing list