{"record":{"id":"eb6408b374fa9c82","repo":"jax-ml/jax","slug":"buffer-array-with-copy-true-is-not-supported","errorCode":null,"errorMessage":"Buffer.__array__ with copy=True is not supported.","messagePattern":"Buffer\\.__array__ with copy=True is not supported\\.","errorType":"validation","errorClass":"nb::value_error","httpStatus":null,"severity":"error","filePath":"jaxlib/ffi.cc","lineNumber":447,"sourceCode":"\nvoid RegisterFfiApis(nb::module_& m) {\n  nb::module_ ffi_module =\n      m.def_submodule(\"ffi\", \"Python bindings for the XLA FFI.\");\n\n  nb::class_<PyFfiAnyBuffer> buffer(ffi_module, \"Buffer\");\n  buffer.def_prop_ro(\"dtype\", xla::ValueOrThrowWrapper(&PyFfiAnyBuffer::dtype));\n  buffer.def_prop_ro(\"ndim\", &PyFfiAnyBuffer::ndim);\n  buffer.def_prop_ro(\"shape\", &PyFfiAnyBuffer::shape);\n  buffer.def_prop_ro(\"writeable\", &PyFfiAnyBuffer::writeable);\n  buffer.def(\n      \"__array__\",\n      [](PyFfiAnyBuffer self, nb::object dtype, nb::object copy) {\n        if (!dtype.is_none()) {\n          throw nb::value_error(\n              \"dtype parameter is not supported by Buffer.__array__.\");\n        }\n        if (!copy.is_none() && nb::cast<bool>(copy)) {\n          throw nb::value_error(\n              \"Buffer.__array__ with copy=True is not supported.\");\n        }\n        return xla::ValueOrThrow(self.NumpyArray());\n      },\n      nb::arg(\"dtype\") = nb::none(), nb::arg(\"copy\") = nb::none());\n  buffer.def_prop_ro(\n      \"__cuda_array_interface__\",\n      xla::ValueOrThrowWrapper(&PyFfiAnyBuffer::CudaArrayInterface));\n  buffer.def(\n      \"__dlpack__\",\n      [](PyFfiAnyBuffer self, nb::object stream, nb::object max_version,\n         nb::object dl_device, nb::object copy) {\n        if (!copy.is_none() && nb::cast<bool>(copy)) {\n          throw nb::value_error(\n              \"Buffer.__dlpack__ with copy=True is not supported.\");\n        }\n\n        // Fall back on the non-versioned API if unsupported by the requested","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/ffi.cc#L429-L465","documentation":"The FFI Buffer's __array__ returns a zero-copy view of device/host memory; copy=True requests a copy which the implementation does not provide, so it is rejected rather than silently returning an aliased array.","triggerScenarios":"np.asarray(ffi_buffer, copy=True) or numpy 2.x code paths (e.g. np.array(..., copy=None) semantics) that request copies on FFI buffers.","commonSituations":"Libraries written for NumPy 2's copy protocol calling arrays with copy=True on xla.ffi Buffer objects.","solutions":["Accept the zero-copy view; if you need a copy, do arr.copy() on the returned array","Update code not to pass copy to Buffer.__array__"],"exampleFix":"# before\nnp.asarray(buf, copy=True)\n# after\nnp.asarray(buf).copy()","handlingStrategy":"validation","validationCode":"arr = buf.__array__()\nneed_copy = arr.copy()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call .copy() on the returned array instead of passing copy=True"],"tags":["jax","ffi","numpy","copy"],"backgroundTag":"unsupported-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}