<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/115904>115904</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Segmentation fault when trying to create a python inerface
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Abhishek-TyRnT
      </td>
    </tr>
</table>

<pre>
    I am trying to create a python object fo mlir ModuleOp using the code below.

```static py::object getMlirIrClass(const char* className) {
  return py::module::import(MAKE_MLIR_PYTHON_QUALNAME("ir")).attr(className);
}

static py::object castMlirModuleToPythonObject(MlirModule module) {
  auto moduleClass = getMlirIrClass("Module");
  auto moduleCapsule =
 py::reinterpret_steal<py::object>(mlirPythonModuleToCapsule(module));
 return moduleClass.attr(MLIR_PYTHON_CAPI_FACTORY_ATTR)(moduleCapsule);
}```


But whenever I try to access the mlir module from python I get a segmentation fault. I figured the line `moduleClass.attr(MLIR_PYTHON_CAPI_FACTORY_ATTR)(moduleCapsule);
` causes the segmentation fault. 


clang version :- clang version 14.0.0-1ubuntu1.1
llvm commit  :- d418a03e01e6a31b51b0c9dd42ba46da6c47f89d
pybind version :- 2.13.6
OS :- ubuntu 22.04
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVE2PozgT_jXmUgryByFw4EB3Jnqjd9Lp7cke5hQZUwTvAka26Vb-_YqP9Cbboz2tFJHIlarnox4sndOXDjEj6yey3gZy8LWxWV7U2tX45-p0fetOQWHKa7YH2YK3V91dwBtQFqVHkNBffW06MMUfqDxUBtpGWziYcmjw2MPgpoYaQZkSocDGfISEbgnNl2dM54_z0msF_ZWInIh8GXhBf2i03dvnRjpHeKJM5zyoWlrCc1Dj6YtskfAUyOZpnglg0Q-2-xzWTnTm37rtjfWEJ4f8_9_Oh-_7t_Prz9P_ji_n337Pv7_kh2-EJ4RzbQnnhKeEp6H03o7Yd2hELGBks73X82sZSrpJx-zLybxOrh2n4kjlswQL1Uc5cvBmqUw-ABHbr9YQzg9LN79n-NgvezfiELHQ_qRqUXcebW_Rn51H2RDx_CiDiNGbccEz_5uaZeZYu7F_wF-2cSfg5ui9_c_56_68y59Px7ef5_x0epvGJA-0_2n8LTwPiZqeT4OHjxo7fEcL-zG5Y2ylUujclMcpp_NwqKxpb0nej8aCBIeXFrtxm6aDSg6ND2EPlb4MFstpQqM7BBLT_1pXTEHJweHM81c8vspVjewu8I7WjX8jIl_B4xGLQhrSFRuKofMDC9nc1zTvLSjTttrD3FZGLJFUIGUYS8GKNSuoSssy4oWM4lLGKtpUSVrO_f210F35CMxDJsJ4rh9_zGczLHAe0igoM1GmIpUBZmwjWCRoGsVBnWGSJBtVJSytGErGSlGtRanohsZrVVYi0BmnPGKMcbahnK_DSqJMMOVlKuN1FFckothK3YSjrtDYS6CdGzBjbJ3SKGhkgY2bbjvOO_yAqTq-LuttYLOxaVUMF0ci2mjn3d9jvPYNZj--7GLK2L_ci7pDW0mFwWCbrPa-d-MLxXeE7y7a10MRKtMSvhuBlq9Vb818L-wmeo7w3cL_PeN_BQAA__-aNsud">