Skip to content

Commit 2c70bfe

Browse files
committed
Add test
1 parent 66101e0 commit 2c70bfe

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Lib/test/test_capi/test_abstract.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@ def test_object_delattrstring(self):
339339
# CRASHES delattrstring(obj, NULL)
340340
# CRASHES delattrstring(NULL, b'a')
341341

342+
def test_copy_to_object(self):
343+
s1 = _testcapi.object_copy_to_object(bytes(5), 'abcde', 'C')
344+
s2 = _testcapi.object_copy_to_object(bytes(5), 'abcde', 'F')
345+
s3 = _testcapi.object_copy_to_object(bytes(5), 'abcde', 'A')
346+
self.assertEqual(s1, s2)
347+
self.assertEqual(s2, s3)
348+
self.assertEqual(s1, s3)
342349

343350
def test_mapping_check(self):
344351
check = _testlimitedcapi.mapping_check

Modules/_testcapi/abstract.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ object_hasattrstringwitherror(PyObject *self, PyObject *args)
7878
RETURN_INT(PyObject_HasAttrStringWithError(obj, attr_name));
7979
}
8080

81+
static PyObject *
82+
object_copy_to_object(PyObject *self, PyObject *args)
83+
{
84+
PyObject *obj;
85+
Py_ssize_t len;
86+
int result;
87+
char *buf, fort;
88+
89+
if (!PyArg_ParseTuple(args, "Os#C", &obj, &buf, &len, &fort)) {
90+
return NULL;
91+
}
92+
result = PyObject_CopyToObject(obj, buf, len, fort);
93+
if (result < 0) {
94+
return NULL;
95+
}
96+
Py_INCREF(obj);
97+
return obj;
98+
}
99+
81100
static PyObject *
82101
mapping_getoptionalitemstring(PyObject *self, PyObject *args)
83102
{
@@ -162,6 +181,8 @@ static PyMethodDef test_methods[] = {
162181
{"object_getoptionalattrstring", object_getoptionalattrstring, METH_VARARGS},
163182
{"object_hasattrwitherror", object_hasattrwitherror, METH_VARARGS},
164183
{"object_hasattrstringwitherror", object_hasattrstringwitherror, METH_VARARGS},
184+
{"object_copy_to_object", object_copy_to_object, METH_VARARGS},
185+
165186
{"mapping_getoptionalitem", mapping_getoptionalitem, METH_VARARGS},
166187
{"mapping_getoptionalitemstring", mapping_getoptionalitemstring, METH_VARARGS},
167188

0 commit comments

Comments
 (0)