|
1 |
| -# Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. |
| 1 | +# Copyright (c) 2019, 2023, 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
|
|
39 | 39 |
|
40 | 40 | import itertools
|
41 | 41 | import sys
|
| 42 | +import struct |
42 | 43 |
|
43 | 44 | from . import CPyExtTestCase, CPyExtFunction, CPyExtType, unhandled_error_compare_with_message, unhandled_error_compare
|
44 | 45 |
|
@@ -445,6 +446,29 @@ def compile_module(self, name):
|
445 | 446 |
|
446 | 447 |
|
447 | 448 | class TestObject(object):
|
| 449 | + def test_memoryview_fromobject_multidim(self): |
| 450 | + TestType = CPyExtType( |
| 451 | + "TestMemoryViewMultidim", |
| 452 | + """ |
| 453 | + PyObject* get_converted_view(PyObject* self, PyObject* obj) { |
| 454 | + PyObject *mv = PyMemoryView_FromObject(obj); |
| 455 | + if (!mv) { |
| 456 | + return NULL; |
| 457 | + } |
| 458 | +
|
| 459 | + Py_buffer *view = PyMemoryView_GET_BUFFER(mv); |
| 460 | + // int i = (int)PyNumber_AsSsize_t(idx, NULL); |
| 461 | + return PyMemoryView_FromBuffer(view); |
| 462 | + } |
| 463 | + """, |
| 464 | + tp_methods='{"get_converted_view", get_converted_view, METH_O, ""}', |
| 465 | + ) |
| 466 | + |
| 467 | + obj = TestType() |
| 468 | + t1_buf = struct.pack("d"*12, *[1.5*x for x in range(12)]) |
| 469 | + t1_mv = memoryview(t1_buf).cast('d', shape=[3,4]) |
| 470 | + assert t1_mv == obj.get_converted_view(t1_mv) |
| 471 | + |
448 | 472 | def test_memoryview_acquire_release(self):
|
449 | 473 | TestType = CPyExtType(
|
450 | 474 | "TestMemoryViewBuffer1",
|
|
0 commit comments