Y._fields_ = []
self.assertRaises(AttributeError, setattr, X, "_fields_", [])
+ def test_5(self):
+ class X(Structure):
+ _fields_ = (("char", c_char * 5),)
+
+ x = X(b'#' * 5)
+ x.char = b'a\0b\0'
+ self.assertEqual(bytes(x), b'a\x00###')
+
# __set__ and __get__ should raise a TypeError in case their self
# argument is not a ctype instance.
def test___set__(self):
}
data = PyBytes_AS_STRING(value);
- size = strlen(data); /* XXX Why not Py_SIZE(value)? */
+ // bpo-39593: Use strlen() to truncate the string at the first null character.
+ size = strlen(data);
+
if (size < length) {
/* This will copy the terminating NUL character
* if there is space for it.