[pypy-svn] r16106 - in pypy/dist/pypy/translator/llvm2: . test
rxe at codespeak.net
rxe at codespeak.net
Wed Aug 17 13:08:50 CEST 2005
Author: rxe
Date: Wed Aug 17 13:08:49 2005
New Revision: 16106
Modified:
pypy/dist/pypy/translator/llvm2/arraynode.py
pypy/dist/pypy/translator/llvm2/structnode.py
pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
pypy/dist/pypy/translator/llvm2/varsize.py
Log:
Fixes for adding NUL in mallocs when we have a STR.chars
Modified: pypy/dist/pypy/translator/llvm2/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/arraynode.py (original)
+++ pypy/dist/pypy/translator/llvm2/arraynode.py Wed Aug 17 13:08:49 2005
@@ -8,7 +8,6 @@
class ArrayTypeNode(LLVMNode):
def __init__(self, db, array):
assert isinstance(array, lltype.Array)
-
self.db = db
self.array = array
arraytype = self.arraytype = array.OF
@@ -61,12 +60,12 @@
def writeimpl(self, codewriter):
log.writeimpl(self.ref)
- fromtype = self.db.repr_type(self.arraytype)
varsize.write_constructor(self.db, codewriter, self.ref,
self.constructor_decl,
- fromtype,
+ self.array,
atomicmalloc=self.is_atomic())
+
class VoidArrayTypeNode(LLVMNode):
def __init__(self, db, array):
Modified: pypy/dist/pypy/translator/llvm2/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/structnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/structnode.py Wed Aug 17 13:08:49 2005
@@ -77,12 +77,11 @@
name = current._names_without_voids()[-1]
current = current._flds[name]
assert isinstance(current, lltype.Array)
- arraytype = self.db.repr_type(current.OF)
varsize.write_constructor(self.db,
codewriter,
self.ref,
self.constructor_decl,
- arraytype,
+ current,
indices_to_array,
atomicmalloc=self.is_atomic())
Modified: pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_extfunc.py (original)
+++ pypy/dist/pypy/translator/llvm2/test/test_extfunc.py Wed Aug 17 13:08:49 2005
@@ -192,6 +192,18 @@
os.unlink(tmpfile)
assert f() == False
+def test_os_path_exists2():
+ # forces malloc / versus pbc for NUL testing of C string
+ tmpfile = str(udir.join('test_os_path_exists.TMP'))
+ def fn(l):
+ filename = tmpfile[:l]
+ return os.path.exists(filename)
+ f = compile_function(fn, [r_uint], view=True)
+ open(tmpfile, 'w').close()
+ lfile = len(tmpfile)
+ assert f(lfile) == True
+ assert f(lfile-2) == False
+
def test_os_path_isdir():
directory = "./."
def fn():
Modified: pypy/dist/pypy/translator/llvm2/varsize.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/varsize.py (original)
+++ pypy/dist/pypy/translator/llvm2/varsize.py Wed Aug 17 13:08:49 2005
@@ -1,3 +1,4 @@
+from pypy.rpython.rstr import STR
# example for an array constructor in concrete llvm code:
# (thanks to chris lattner)
@@ -15,17 +16,26 @@
ret %array* %result
}"""
-def write_constructor(db, codewriter, ref, constructor_decl, elemtype,
+def write_constructor(db, codewriter, ref, constructor_decl, ARRAY,
indices_to_array=(), atomicmalloc=False):
+
#varsized arrays and structs look like this:
#Array: {int length , elemtype*}
#Struct: {...., Array}
# the following indices access the last element in the array
+ elemtype = db.repr_type(ARRAY.OF)
lentype = db.get_machine_word()
- elemindices = list(indices_to_array) + [("uint", 1), (lentype, "%len")]
-
- codewriter.openfunc(constructor_decl)
+
+ codewriter.openfunc(constructor_decl)
+
+ # Need room for NUL terminator
+ if ARRAY is STR.chars:
+ codewriter.binaryop("add", "%actuallen", lentype, "%len", 1)
+ else:
+ codewriter.cast("%actuallen", lentype, "%len", lentype)
+
+ elemindices = list(indices_to_array) + [("uint", 1), (lentype, "%actuallen")]
codewriter.getelementptr("%size", ref + "*", "null", *elemindices)
codewriter.cast("%usize", elemtype + "*", "%size", "uint")
codewriter.malloc("%ptr", "sbyte", "%usize", atomic=atomicmalloc)
@@ -37,6 +47,15 @@
"%result",
*indices_to_array)
codewriter.store(lentype, "%len", "%arraylength")
+
+ if ARRAY is STR.chars:
+ # NUL the last element
+ codewriter.getelementptr("%terminator",
+ ref + "*",
+ "%result",
+ *elemindices)
+ codewriter.store(elemtype, 0, "%terminator")
+
codewriter.ret(ref + "*", "%result")
codewriter.closefunc()
More information about the Pypy-commit
mailing list