|
64 | 64 | MAKE_MLIR_PYTHON_QUALNAME("ir.Attribute._CAPIPtr")
|
65 | 65 | #define MLIR_PYTHON_CAPSULE_CONTEXT \
|
66 | 66 | MAKE_MLIR_PYTHON_QUALNAME("ir.Context._CAPIPtr")
|
| 67 | +#define MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY \ |
| 68 | + MAKE_MLIR_PYTHON_QUALNAME("ir.DialectRegistry._CAPIPtr") |
67 | 69 | #define MLIR_PYTHON_CAPSULE_EXECUTION_ENGINE \
|
68 | 70 | MAKE_MLIR_PYTHON_QUALNAME("execution_engine.ExecutionEngine._CAPIPtr")
|
69 | 71 | #define MLIR_PYTHON_CAPSULE_INTEGER_SET \
|
@@ -172,6 +174,28 @@ static inline MlirContext mlirPythonCapsuleToContext(PyObject *capsule) {
|
172 | 174 | return context;
|
173 | 175 | }
|
174 | 176 |
|
| 177 | +/** Creates a capsule object encapsulating the raw C-API MlirDialectRegistry. |
| 178 | + * The returned capsule does not extend or affect ownership of any Python |
| 179 | + * objects that reference the context in any way. |
| 180 | + */ |
| 181 | +static inline PyObject * |
| 182 | +mlirPythonDialectRegistryToCapsule(MlirDialectRegistry registry) { |
| 183 | + return PyCapsule_New(registry.ptr, MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY, |
| 184 | + NULL); |
| 185 | +} |
| 186 | + |
| 187 | +/** Extracts an MlirDialectRegistry from a capsule as produced from |
| 188 | + * mlirPythonDialectRegistryToCapsule. If the capsule is not of the right type, |
| 189 | + * then a null context is returned (as checked via mlirContextIsNull). In such a |
| 190 | + * case, the Python APIs will have already set an error. */ |
| 191 | +static inline MlirDialectRegistry |
| 192 | +mlirPythonCapsuleToDialectRegistry(PyObject *capsule) { |
| 193 | + void *ptr = |
| 194 | + PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY); |
| 195 | + MlirDialectRegistry registry = {ptr}; |
| 196 | + return registry; |
| 197 | +} |
| 198 | + |
175 | 199 | /** Creates a capsule object encapsulating the raw C-API MlirLocation.
|
176 | 200 | * The returned capsule does not extend or affect ownership of any Python
|
177 | 201 | * objects that reference the location in any way. */
|
|
0 commit comments