|
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. |
2 | 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
3 | 3 | #
|
4 | 4 | # The Universal Permissive License (UPL), Version 1.0
|
@@ -85,3 +85,30 @@ def compile_module(self, name):
|
85 | 85 | callfunction="get_mmap_buf",
|
86 | 86 | cmpfunc=unhandled_error_compare
|
87 | 87 | )
|
| 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