Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r502:bf0449814cff Date: 2012-06-24 16:22 +0200 http://bitbucket.org/cffi/cffi/changeset/bf0449814cff/
Log: Test and fix. diff --git a/c/_ffi_backend.c b/c/_ffi_backend.c --- a/c/_ffi_backend.c +++ b/c/_ffi_backend.c @@ -744,6 +744,8 @@ "(got %zd characters)", ct->ct_name, n); return -1; } + if (n != ct->ct_length) + n++; srcdata = PyString_AS_STRING(init); memcpy(data, srcdata, n); return 0; diff --git a/c/test_c.py b/c/test_c.py --- a/c/test_c.py +++ b/c/test_c.py @@ -875,3 +875,17 @@ pass else: raise AssertionError + +def test_assign_string(): + BChar = new_primitive_type("char") + BArray1 = new_array_type(new_pointer_type(BChar), 5) + BArray2 = new_array_type(new_pointer_type(BArray1), 5) + a = newp(BArray2, ["abc", "de", "ghij"]) + assert str(a[2]) == "ghij" + a[2] = "." + assert str(a[2]) == "." + a[2] = "12345" + assert str(a[2]) == "12345" + e = py.test.raises(IndexError, 'a[2] = "123456"') + assert 'char[5]' in str(e.value) + assert 'got 6 characters' in str(e.value) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit