Skip to content

Commit 3fda084

Browse files
committed
Add test for the mmap buffer pointer
1 parent bc0c844 commit 3fda084

File tree

1 file changed

+28
-1
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+28
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_mmap.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -85,3 +85,30 @@ def compile_module(self, name):
8585
callfunction="get_mmap_buf",
8686
cmpfunc=unhandled_error_compare
8787
)
88+
89+
# Exercises conversion to native and copying from the actual mmap pointer
90+
test_buffer_memcpy = CPyExtFunction(
91+
lambda args: b"hello, world",
92+
lambda: (
93+
(create_and_map_file(),),
94+
),
95+
code="""
96+
static PyObject* get_mmap_buf(PyObject* mmapObj) {
97+
Py_buffer buf;
98+
Py_ssize_t len, i;
99+
char* data = NULL;
100+
if (PyObject_GetBuffer(mmapObj, &buf, PyBUF_SIMPLE)) {
101+
return NULL;
102+
}
103+
len = buf.len;
104+
data = (char*) malloc(sizeof(char)*len);
105+
memcpy(data, buf.buf, len);
106+
return PyBytes_FromStringAndSize(data, len);
107+
}
108+
""",
109+
resultspec="O",
110+
argspec='O',
111+
arguments=["PyObject* mmapObj"],
112+
callfunction="get_mmap_buf",
113+
cmpfunc=unhandled_error_compare
114+
)

0 commit comments

Comments
 (0)