Changeset View
Standalone View
source/blender/python/intern/gpu.c
| Show First 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | static PyObject *GPU_export_shader(PyObject *UNUSED(self), PyObject *args, PyObject *kwds) | ||||
| GPU_free_shader_export(shader); | GPU_free_shader_export(shader); | ||||
| return result; | return result; | ||||
| } | } | ||||
| static PyMethodDef meth_export_shader[] = { | static PyMethodDef meth_export_shader[] = { | ||||
| {"export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS, GPU_export_shader_doc} | {"export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS, GPU_export_shader_doc} | ||||
| }; | }; | ||||
campbellbarton: Multiple places in this patch use:
`PyUnicode_AsUTF8String`, then `PyBytes_AsString`.
This… | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Initialize Module */ | /* Initialize Module */ | ||||
| PyObject *GPU_initPython(void) | PyObject *GPU_initPython(void) | ||||
| { | { | ||||
| PyObject *module; | PyObject *module; | ||||
| PyObject *submodule; | PyObject *submodule; | ||||
| PyObject *sys_modules = PyThreadState_GET()->interp->modules; | PyObject *sys_modules = PyThreadState_GET()->interp->modules; | ||||
| module = PyInit_gpu(); | module = PyInit_gpu(); | ||||
| PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL)); | PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL)); | ||||
Done Inline ActionsThis should at least give some unique information. eg: return PyUnicode_FromFormat("<GPUNodeLink at %p>", self);campbellbarton: This should at least give some unique information. eg:
return PyUnicode_FromFormat… | |||||
| /* gpu.offscreen */ | /* gpu.offscreen */ | ||||
| PyModule_AddObject(module, "offscreen", (submodule = BPyInit_gpu_offscreen())); | PyModule_AddObject(module, "offscreen", (submodule = BPyInit_gpu_offscreen())); | ||||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||||
| Py_INCREF(submodule); | Py_INCREF(submodule); | ||||
| /* gpu.shader_node */ | |||||
| PyModule_AddObject(module, "shader_node", (submodule = BPyInit_gpu_shader_node())); | |||||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | |||||
| Py_INCREF(submodule); | |||||
| PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module); | PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module); | ||||
| return module; | return module; | ||||
| } | } | ||||
Done Inline ActionsThere won't be any errors here. campbellbarton: There won't be any errors here. | |||||
Done Inline Actionsmathutils_array_parse is preferred over exact type checks. Allows tuples/lists too. campbellbarton: `mathutils_array_parse` is preferred over exact type checks.
Allows tuples/lists too. | |||||
Done Inline ActionsAgain, should use mathutils_array_parse, see matrix construction in mathutils_Matrix.c campbellbarton: Again, should use `mathutils_array_parse`, see matrix construction in `mathutils_Matrix.c` | |||||
Done Inline ActionsA common pattern in CPy is to do: if (!(((id = _PyLong_AsInt(item)) == -1) && PyErr_Occurred())) {
/* id is ok! */
}
else {
PyErr_Clear();
... continue parsing ...
}This supports any types that support the number interface. campbellbarton: A common pattern in CPy is to do:
if (!(((id = _PyLong_AsInt(item)) == -1) &&… | |||||
Done Inline ActionsAgain, overly spesific type checks, see _PyLong_AsInt suggestion above. campbellbarton: Again, overly spesific type checks, see `_PyLong_AsInt` suggestion above. | |||||
Done Inline ActionsAgain very spesific parsing, (will fail on 0/1), suggest using PyC_ParseBool. campbellbarton: Again very spesific parsing, (will fail on 0/1), suggest using `PyC_ParseBool`. | |||||
Done Inline ActionsIf this fails it wont be clear for the caller why. campbellbarton: If this fails it wont be clear for the caller why. | |||||
Done Inline ActionsMust return NULL to properly raise an error. campbellbarton: Must return NULL to properly raise an error. | |||||
Done Inline ActionsNo need, its created with a single user. campbellbarton: No need, its created with a single user. | |||||
Done Inline ActionsAgain, must return NULL... also for all other false returns in this function. campbellbarton: Again, must return NULL... also for all other false returns in this function. | |||||
Done Inline ActionsAgain, must return NULL. campbellbarton: Again, must return NULL. | |||||
Done Inline ActionsAgain, must return NULL. campbellbarton: Again, must return NULL. | |||||
Done Inline ActionsThis function should probably return None, not a boolean. campbellbarton: This function should probably return None, not a boolean. | |||||
Done Inline ActionsAgain, no need for intermediate PyUnicode_AsUTF8String conversion. campbellbarton: Again, no need for intermediate `PyUnicode_AsUTF8String` conversion. | |||||
Done Inline ActionsAgain, no need for intermediate PyUnicode_AsUTF8String conversion. campbellbarton: Again, no need for intermediate `PyUnicode_AsUTF8String` conversion. | |||||
Multiple places in this patch use:
PyUnicode_AsUTF8String, then PyBytes_AsString.
This isn't needed (causes intermediate variable to be created which needs to be dec-ref'd after).
Instead just call _PyUnicode_AsString.