| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "openFileStream.h" | ||
| 8 | #include "header_generator.h" | ||
| 9 | |||
| 10 | #include "wrapper_generator_module.h" | ||
| 11 | |||
| 12 | |||
| 13 | ///Create the PyType_Ready for all classes of the module | ||
| 14 | /** @param[out] fs : file to be modified | ||
| 15 | * @param vecClassConfig : vector of class configuration | ||
| 16 | */ | ||
| 17 | 3 | void project_wrapper_modulePyTypeReady(std::ofstream & fs, const PVecClassConfig & vecClassConfig){ | |
| 18 |
2/2✓ Branch 0 (73→3) taken 5 times.
✓ Branch 1 (73→74) taken 3 times.
|
16 | for(PVecClassConfig::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 19 |
3/3✓ Branch 0 (5→6) taken 5 times.
✓ Branch 2 (6→7) taken 2 times.
✓ Branch 3 (6→54) taken 3 times.
|
5 | if(it->getIsEnum()){ |
| 20 |
2/2✓ Branch 0 (9→10) taken 2 times.
✓ Branch 2 (10→11) taken 2 times.
|
2 | std::string varName(it->getName()+"EnumType"); |
| 21 |
6/6✓ Branch 0 (13→14) taken 2 times.
✓ Branch 2 (14→15) taken 2 times.
✓ Branch 4 (15→16) taken 2 times.
✓ Branch 6 (16→17) taken 2 times.
✓ Branch 8 (17→18) taken 2 times.
✓ Branch 10 (18→19) taken 2 times.
|
4 | fs << "\t//PyObject* "+varName+" = (PyObject*)Py_TYPE(WP"+it->getName()+"_newC(NULL, NULL, NULL));\t//1: A nice segmentation fault of python\n"; |
| 22 |
6/6✓ Branch 0 (25→26) taken 2 times.
✓ Branch 2 (26→27) taken 2 times.
✓ Branch 4 (27→28) taken 2 times.
✓ Branch 6 (28→29) taken 2 times.
✓ Branch 8 (29→30) taken 2 times.
✓ Branch 10 (30→31) taken 2 times.
|
4 | fs << "\tPyObject* "+varName+" = WP"+it->getName()+"_newC(NULL, NULL, NULL);\t//2: alone => SystemError: initialization of pystereodata raised unreported exception, while importing generated module\n"; |
| 23 |
4/4✓ Branch 0 (35→36) taken 2 times.
✓ Branch 2 (36→37) taken 2 times.
✓ Branch 4 (37→38) taken 2 times.
✓ Branch 6 (38→39) taken 2 times.
|
2 | fs << "\tif("+varName+" == NULL){" << std::endl; |
| 24 |
5/5✓ Branch 0 (41→42) taken 2 times.
✓ Branch 2 (44→45) taken 2 times.
✓ Branch 4 (45→46) taken 2 times.
✓ Branch 6 (46→47) taken 2 times.
✓ Branch 8 (47→48) taken 2 times.
|
4 | fs << "\t\tstd::cerr << \"Cannot create enum '"<<it->getName()<<"'\" << std::endl;" << std::endl; |
| 25 |
2/2✓ Branch 0 (48→49) taken 2 times.
✓ Branch 2 (49→50) taken 2 times.
|
2 | fs << "\t\treturn NULL;" << std::endl; |
| 26 |
2/2✓ Branch 0 (50→51) taken 2 times.
✓ Branch 2 (51→52) taken 2 times.
|
2 | fs << "\t}" << std::endl; |
| 27 | // fs << "\tif(PyType_Ready("+varName+") < 0){std::cerr << \"Type for enum '"<<it->getName()<<"' not ready\" << std::endl;return NULL;}\n"; | ||
| 28 | 2 | }else{ | |
| 29 |
4/4✓ Branch 0 (56→57) taken 3 times.
✓ Branch 2 (57→58) taken 3 times.
✓ Branch 4 (58→59) taken 3 times.
✓ Branch 6 (59→60) taken 3 times.
|
6 | fs << "\tif(PyType_Ready(&WP"+it->getName()+"Type) < 0){return NULL;}\n"; |
| 30 | } | ||
| 31 | } | ||
| 32 | 3 | } | |
| 33 | |||
| 34 | ///Create the Py_INCREF for all classes of the module | ||
| 35 | /** @param[out] fs : file to be modified | ||
| 36 | * @param vecClassConfig : vector of class configuration | ||
| 37 | */ | ||
| 38 | 3 | void project_wrapper_modulePyIncref(std::ofstream & fs, const PVecClassConfig & vecClassConfig){ | |
| 39 |
2/2✓ Branch 0 (35→3) taken 5 times.
✓ Branch 1 (35→36) taken 3 times.
|
16 | for(PVecClassConfig::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 40 |
3/3✓ Branch 0 (5→6) taken 5 times.
✓ Branch 2 (6→7) taken 2 times.
✓ Branch 3 (6→16) taken 3 times.
|
5 | if(it->getIsEnum()){ |
| 41 |
4/4✓ Branch 0 (9→10) taken 2 times.
✓ Branch 2 (10→11) taken 2 times.
✓ Branch 4 (11→12) taken 2 times.
✓ Branch 6 (12→13) taken 2 times.
|
4 | fs << "\t//Py_INCREF("+it->getName()+"EnumType);\t//2: An other segmentation fault of python, when pytest is collecting tests\n"; |
| 42 | }else{ | ||
| 43 |
4/4✓ Branch 0 (18→19) taken 3 times.
✓ Branch 2 (19→20) taken 3 times.
✓ Branch 4 (20→21) taken 3 times.
✓ Branch 6 (21→22) taken 3 times.
|
6 | fs << "\tPy_INCREF(&WP"+it->getName()+"Type);\n"; |
| 44 | } | ||
| 45 | } | ||
| 46 | 3 | } | |
| 47 | |||
| 48 | ///Create the Py_INCREF for all classes of the module | ||
| 49 | /** @param[out] fs : file to be modified | ||
| 50 | * @param vecClassConfig : vector of class configuration | ||
| 51 | */ | ||
| 52 | 3 | void project_wrapper_moduleAddObject(std::ofstream & fs, const PVecClassConfig & vecClassConfig){ | |
| 53 |
2/2✓ Branch 0 (49→3) taken 5 times.
✓ Branch 1 (49→50) taken 3 times.
|
16 | for(PVecClassConfig::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){ |
| 54 |
3/3✓ Branch 0 (5→6) taken 5 times.
✓ Branch 2 (6→7) taken 2 times.
✓ Branch 3 (6→23) taken 3 times.
|
5 | if(it->getIsEnum()){ |
| 55 |
7/7✓ Branch 0 (9→10) taken 2 times.
✓ Branch 2 (12→13) taken 2 times.
✓ Branch 4 (13→14) taken 2 times.
✓ Branch 6 (14→15) taken 2 times.
✓ Branch 8 (15→16) taken 2 times.
✓ Branch 10 (16→17) taken 2 times.
✓ Branch 12 (17→18) taken 2 times.
|
6 | fs << "\tPyModule_AddObject(m, \""+it->getName()+"\", "+it->getName()+"EnumType);\n"; |
| 56 | }else{ | ||
| 57 |
7/7✓ Branch 0 (25→26) taken 3 times.
✓ Branch 2 (28→29) taken 3 times.
✓ Branch 4 (29→30) taken 3 times.
✓ Branch 6 (30→31) taken 3 times.
✓ Branch 8 (31→32) taken 3 times.
✓ Branch 10 (32→33) taken 3 times.
✓ Branch 12 (33→34) taken 3 times.
|
9 | fs << "\tPyModule_AddObject(m, \""+it->getName()+"\", (PyObject *)&WP"+it->getName()+"Type);\n"; |
| 58 | } | ||
| 59 | } | ||
| 60 | 3 | } | |
| 61 | |||
| 62 | ///Create the main wrapper module | ||
| 63 | /** @param fileName : path of the module | ||
| 64 | * @param projectParam : config of the project | ||
| 65 | * @return true on success, false otherwise | ||
| 66 | */ | ||
| 67 | 2 | bool project_wrapper_moduleGeneratorMain(const PPath & fileName, const ProjectParam & projectParam){ | |
| 68 |
1/1✓ Branch 0 (2→3) taken 2 times.
|
2 | PString moduleName(projectParam.mode.moduleName); |
| 69 |
1/1✓ Branch 0 (3→4) taken 2 times.
|
2 | std::ofstream fs; |
| 70 |
2/3✓ Branch 0 (4→5) taken 2 times.
✗ Branch 2 (5→6) not taken.
✓ Branch 3 (5→7) taken 2 times.
|
2 | if(!openFileStream(fs, fileName)){return false;} |
| 71 |
1/1✓ Branch 0 (7→8) taken 2 times.
|
2 | licenceSave(fs); |
| 72 |
1/1✓ Branch 0 (8→9) taken 2 times.
|
2 | fs << "\n"; |
| 73 | // fs << "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION\n"; | ||
| 74 | // fs << "#ifndef DISABLE_COOL_ARRAY\n"; | ||
| 75 | // fs << "#\tdefine PY_ARRAY_UNIQUE_SYMBOL "+moduleName+"_ARRAY_API\n"; | ||
| 76 | // fs << "#endif\n"; | ||
| 77 |
1/1✓ Branch 0 (9→10) taken 2 times.
|
2 | fs << "\n"; |
| 78 |
1/1✓ Branch 0 (10→11) taken 2 times.
|
2 | fs << "#include <Python.h>\n"; |
| 79 |
1/1✓ Branch 0 (11→12) taken 2 times.
|
2 | fs << "#include \"structmember.h\"\n"; |
| 80 | // fs << "#include <numpy/arrayobject.h>\n"; | ||
| 81 |
1/1✓ Branch 0 (12→13) taken 2 times.
|
2 | fs << "\n"; |
| 82 |
1/1✓ Branch 0 (13→14) taken 2 times.
|
2 | fs << "#include <string>\n"; |
| 83 |
1/1✓ Branch 0 (14→15) taken 2 times.
|
2 | fs << "#include <iostream>\n"; |
| 84 | //TODO : put the includes of all class definitions | ||
| 85 |
2/2✓ Branch 0 (35→17) taken 3 times.
✓ Branch 1 (35→36) taken 2 times.
|
7 | for(const PDataConfig & config : projectParam.vecDataConfig){ |
| 86 |
6/6✓ Branch 0 (19→20) taken 3 times.
✓ Branch 2 (20→21) taken 3 times.
✓ Branch 4 (21→22) taken 3 times.
✓ Branch 6 (22→23) taken 3 times.
✓ Branch 8 (23→24) taken 3 times.
✓ Branch 10 (24→25) taken 3 times.
|
3 | fs << "#include \"" << config.getFileName().getFileName().eraseExtension() <<"_wrapper.h\"\n"; |
| 87 | } | ||
| 88 |
1/1✓ Branch 0 (36→37) taken 2 times.
|
2 | fs << "\n"; |
| 89 | // fs << "#include \""+ baseImplInclude + "_wrapper.h\"\n\n"; | ||
| 90 | |||
| 91 |
3/3✓ Branch 0 (37→38) taken 2 times.
✓ Branch 2 (38→39) taken 2 times.
✓ Branch 4 (39→40) taken 2 times.
|
2 | fs << "static PyMethodDef _"+moduleName+"_methods[] = {\n"; |
| 92 |
1/1✓ Branch 0 (42→43) taken 2 times.
|
2 | fs << "\t{NULL, NULL}\n"; |
| 93 |
1/1✓ Branch 0 (43→44) taken 2 times.
|
2 | fs << "};\n\n"; |
| 94 | |||
| 95 |
3/3✓ Branch 0 (44→45) taken 2 times.
✓ Branch 2 (45→46) taken 2 times.
✓ Branch 4 (46→47) taken 2 times.
|
2 | fs << "static PyModuleDef _"+moduleName+"_module = {\n"; |
| 96 |
1/1✓ Branch 0 (49→50) taken 2 times.
|
2 | fs << "\tPyModuleDef_HEAD_INIT,\n"; |
| 97 |
3/3✓ Branch 0 (50→51) taken 2 times.
✓ Branch 2 (51→52) taken 2 times.
✓ Branch 4 (52→53) taken 2 times.
|
2 | fs << "\t\""+moduleName+"\",\n"; |
| 98 |
1/1✓ Branch 0 (55→56) taken 2 times.
|
2 | fs << "\t\"\",\n"; |
| 99 |
1/1✓ Branch 0 (56→57) taken 2 times.
|
2 | fs << "\t-1,\n"; |
| 100 |
3/3✓ Branch 0 (57→58) taken 2 times.
✓ Branch 2 (58→59) taken 2 times.
✓ Branch 4 (59→60) taken 2 times.
|
2 | fs << "\t_"+moduleName+"_methods,\n"; |
| 101 |
1/1✓ Branch 0 (62→63) taken 2 times.
|
2 | fs << "\tNULL,\n"; |
| 102 |
1/1✓ Branch 0 (63→64) taken 2 times.
|
2 | fs << "\tNULL,\n"; |
| 103 |
1/1✓ Branch 0 (64→65) taken 2 times.
|
2 | fs << "\tNULL,\n"; |
| 104 |
1/1✓ Branch 0 (65→66) taken 2 times.
|
2 | fs << "\tNULL\n"; |
| 105 |
1/1✓ Branch 0 (66→67) taken 2 times.
|
2 | fs << "};\n\n"; |
| 106 | |||
| 107 |
3/3✓ Branch 0 (67→68) taken 2 times.
✓ Branch 2 (68→69) taken 2 times.
✓ Branch 4 (69→70) taken 2 times.
|
2 | fs << "///Create the python module "+moduleName+"\n"; |
| 108 |
3/3✓ Branch 0 (72→73) taken 2 times.
✓ Branch 2 (73→74) taken 2 times.
✓ Branch 4 (74→75) taken 2 times.
|
2 | fs << "/**\t@return python module "+moduleName+"\n"; |
| 109 |
1/1✓ Branch 0 (77→78) taken 2 times.
|
2 | fs << "*/\n"; |
| 110 |
3/3✓ Branch 0 (78→79) taken 2 times.
✓ Branch 2 (79→80) taken 2 times.
✓ Branch 4 (80→81) taken 2 times.
|
2 | fs << "PyMODINIT_FUNC PyInit_"+moduleName+"(void){\n"; |
| 111 | // fs << "\timport_array();\n"; //For numpy stuff | ||
| 112 |
1/1✓ Branch 0 (83→84) taken 2 times.
|
2 | fs << "\n"; |
| 113 |
2/2✓ Branch 0 (99→86) taken 3 times.
✓ Branch 1 (99→100) taken 2 times.
|
7 | for(const PDataConfig & config : projectParam.vecDataConfig){ |
| 114 |
2/2✓ Branch 0 (88→89) taken 3 times.
✓ Branch 2 (89→90) taken 3 times.
|
3 | project_wrapper_modulePyTypeReady(fs, config.getVecClassConfig()); |
| 115 | } | ||
| 116 |
1/1✓ Branch 0 (100→101) taken 2 times.
|
2 | fs << "\t\n"; |
| 117 |
3/3✓ Branch 0 (101→102) taken 2 times.
✓ Branch 2 (102→103) taken 2 times.
✓ Branch 4 (103→104) taken 2 times.
|
2 | fs << "\tPyObject * m = PyModule_Create(&_"+moduleName+"_module);\n"; |
| 118 |
1/1✓ Branch 0 (106→107) taken 2 times.
|
2 | fs << "\tif(m == NULL){\n"; |
| 119 |
1/1✓ Branch 0 (107→108) taken 2 times.
|
2 | fs << "\t\treturn NULL;\n"; |
| 120 |
1/1✓ Branch 0 (108→109) taken 2 times.
|
2 | fs << "\t}\n"; |
| 121 |
1/1✓ Branch 0 (109→110) taken 2 times.
|
2 | fs << "\t\n"; |
| 122 |
2/2✓ Branch 0 (125→112) taken 3 times.
✓ Branch 1 (125→126) taken 2 times.
|
7 | for(const PDataConfig & config : projectParam.vecDataConfig){ |
| 123 |
2/2✓ Branch 0 (114→115) taken 3 times.
✓ Branch 2 (115→116) taken 3 times.
|
3 | project_wrapper_modulePyIncref(fs, config.getVecClassConfig()); |
| 124 | } | ||
| 125 |
1/1✓ Branch 0 (126→127) taken 2 times.
|
2 | fs << "\t\n"; |
| 126 |
2/2✓ Branch 0 (142→129) taken 3 times.
✓ Branch 1 (142→143) taken 2 times.
|
7 | for(const PDataConfig & config : projectParam.vecDataConfig){ |
| 127 |
2/2✓ Branch 0 (131→132) taken 3 times.
✓ Branch 2 (132→133) taken 3 times.
|
3 | project_wrapper_moduleAddObject(fs, config.getVecClassConfig()); |
| 128 | } | ||
| 129 |
1/1✓ Branch 0 (143→144) taken 2 times.
|
2 | fs << "\t\n"; |
| 130 |
1/1✓ Branch 0 (144→145) taken 2 times.
|
2 | fs << "\treturn m;\n"; |
| 131 |
1/1✓ Branch 0 (145→146) taken 2 times.
|
2 | fs << "}\n\n"; |
| 132 |
1/1✓ Branch 0 (146→147) taken 2 times.
|
2 | fs.close(); |
| 133 | 2 | return true; | |
| 134 | 2 | } | |
| 135 | |||
| 136 | |||
| 137 | |||
| 138 | |||
| 139 |