Cleanup: pass sizeof array element to PyC_AsArray

Replace the is_double argument which was only used for single/double
precision floats.

This allows supporting different sized int types more easily.
This commit is contained in:
2021-07-27 22:26:33 +10:00
parent b1a2abd6b2
commit 58eacb8e7c
9 changed files with 89 additions and 46 deletions

View File

@@ -144,8 +144,12 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
goto finally;
}
ok = PyC_AsArray_FAST(
values, seq_fast_item, verts_per_prim, &PyLong_Type, false, error_prefix) == 0;
ok = PyC_AsArray_FAST(values,
sizeof(*values),
seq_fast_item,
verts_per_prim,
&PyLong_Type,
error_prefix) == 0;
if (ok) {
for (uint j = 0; j < verts_per_prim; j++) {

View File

@@ -309,7 +309,8 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
ret = -1;
}
else {
ret = PyC_AsArray_FAST(values, seq_fast, length, &PyLong_Type, false, error_prefix);
ret = PyC_AsArray_FAST(
values, sizeof(*values), seq_fast, length, &PyLong_Type, error_prefix);
}
Py_DECREF(seq_fast);
}
@@ -448,7 +449,8 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
ret = -1;
}
else {
ret = PyC_AsArray_FAST(values, seq_fast, length, &PyLong_Type, false, error_prefix);
ret = PyC_AsArray_FAST(
values, sizeof(*values), seq_fast, length, &PyLong_Type, error_prefix);
}
Py_DECREF(seq_fast);
}

View File

@@ -153,7 +153,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *arg
int len = 1;
if (PySequence_Check(py_size)) {
len = PySequence_Size(py_size);
if (PyC_AsArray(size, py_size, len, &PyLong_Type, false, "GPUTexture.__new__") == -1) {
if (PyC_AsArray(size, sizeof(*size), py_size, len, &PyLong_Type, "GPUTexture.__new__") == -1) {
return NULL;
}
}
@@ -321,10 +321,11 @@ static PyObject *pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObje
memset(&values, 0, sizeof(values));
if (PyC_AsArray(&values,
(pygpu_dataformat.value_found == GPU_DATA_FLOAT) ? sizeof(*values.f) :
sizeof(*values.i),
py_values,
shape,
pygpu_dataformat.value_found == GPU_DATA_FLOAT ? &PyFloat_Type : &PyLong_Type,
false,
(pygpu_dataformat.value_found == GPU_DATA_FLOAT) ? &PyFloat_Type : &PyLong_Type,
"clear") == -1) {
return NULL;
}