Mercurial > hg > orthanc-python
comparison CodeAnalysis/FunctionBody.mustache @ 75:cbfc72a53970
refactoring calls to PythonLock::RaiseException()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Aug 2021 16:59:59 +0200 |
parents | 7ed502b17b8f |
children | e7ff5efb100d |
comparison
equal
deleted
inserted
replaced
73:da73be4b361b | 75:cbfc72a53970 |
---|---|
3 {{/args}} | 3 {{/args}} |
4 | 4 |
5 {{#has_args}} | 5 {{#has_args}} |
6 if (!PyArg_ParseTuple(args, {{tuple_format}})) | 6 if (!PyArg_ParseTuple(args, {{tuple_format}})) |
7 { | 7 { |
8 // TODO => RAISE : https://stackoverflow.com/questions/60832317 | |
9 PyErr_SetString(PyExc_TypeError, "Bad types for the arguments ({{count_args}} arguments expected)"); | 8 PyErr_SetString(PyExc_TypeError, "Bad types for the arguments ({{count_args}} arguments expected)"); |
10 return NULL; | 9 return NULL; |
11 } | 10 } |
12 {{/has_args}} | 11 {{/has_args}} |
13 {{#return_long}} | 12 {{#return_long}} |
32 OrthancPlugins::OrthancString s; | 31 OrthancPlugins::OrthancString s; |
33 s.Assign({{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}})); | 32 s.Assign({{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}})); |
34 {{#args}}{{release}}{{/args}} | 33 {{#args}}{{release}}{{/args}} |
35 if (s.GetContent() == NULL) | 34 if (s.GetContent() == NULL) |
36 { | 35 { |
37 // TODO => RAISE : https://stackoverflow.com/questions/60832317 | 36 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
38 //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); | |
39 PyErr_SetString(PyExc_ValueError, "Internal error"); | |
40 return NULL; | 37 return NULL; |
41 } | 38 } |
42 else | 39 else |
43 { | 40 { |
44 return PyUnicode_FromString(s.GetContent()); | 41 return PyUnicode_FromString(s.GetContent()); |
60 Py_INCREF(Py_None); | 57 Py_INCREF(Py_None); |
61 return Py_None; | 58 return Py_None; |
62 } | 59 } |
63 else | 60 else |
64 { | 61 { |
65 // TODO => RAISE : https://stackoverflow.com/questions/60832317 | 62 PythonLock::RaiseException(code); |
66 //PythonLock::RaiseException(module, code); | |
67 PyErr_SetString(PyExc_ValueError, "Internal error"); | |
68 return NULL; | 63 return NULL; |
69 } | 64 } |
70 {{/return_error}} | 65 {{/return_error}} |
71 {{#return_object}} | 66 {{#return_object}} |
72 // This is the case of a constructor | 67 // This is the case of a constructor |
73 {{return_object}}* obj = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | 68 {{return_object}}* obj = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |
74 {{#args}}{{release}}{{/args}} | 69 {{#args}}{{release}}{{/args}} |
75 if (obj == NULL) | 70 if (obj == NULL) |
76 { | 71 { |
77 // TODO => RAISE : https://stackoverflow.com/questions/60832317 | 72 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
78 //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); | |
79 PyErr_SetString(PyExc_ValueError, "Internal error"); | |
80 return NULL; | 73 return NULL; |
81 } | 74 } |
82 else | 75 else |
83 { | 76 { |
84 PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); | 77 PyObject *argList = Py_BuildValue("Lb", obj, false /* not borrowed */); |
95 { | 88 { |
96 return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); | 89 return PyBytes_FromStringAndSize(buffer.GetData(), buffer.GetSize()); |
97 } | 90 } |
98 else | 91 else |
99 { | 92 { |
100 // TODO => RAISE : https://stackoverflow.com/questions/60832317 | 93 PythonLock::RaiseException(OrthancPluginErrorCode_InternalError); |
101 //PythonLock::RaiseException(module, OrthancPluginErrorCode_InternalError); | |
102 PyErr_SetString(PyExc_ValueError, "Internal error"); | |
103 return NULL; | 94 return NULL; |
104 } | 95 } |
105 {{/return_bytes}} | 96 {{/return_bytes}} |
106 {{#return_enumeration}} | 97 {{#return_enumeration}} |
107 {{return_enumeration}} value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); | 98 {{return_enumeration}} value = {{c_function}}(OrthancPlugins::GetGlobalContext(){{self}}{{call_args}}); |