Use py_ssize_t for a # format when calling py_buildvalue

This commit is contained in:
Kovid Goyal 2021-12-04 14:40:20 +05:30
parent 869f556365
commit e113bf1657
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 19 additions and 10 deletions

View File

@ -58,7 +58,7 @@
- Google metadata plugin: When searching by ISBN if no results are found retry using an alternate query syntax - Google metadata plugin: When searching by ISBN if no results are found retry using an alternate query syntax
- 5.33.1 fixes a couple of regressions that broke the toolbar in the popup comments editor dialog and rendering of the download - 5.33.1 fixes a couple of regressions that broke the toolbar in the popup comments editor dialog and rendering of the download
metadata button in the edit metadata dialog on windows metadata button in the edit metadata dialog on Windows
:: improved recipes :: improved recipes
- Smithsonian Magazine - Smithsonian Magazine

View File

@ -483,7 +483,8 @@ set_ui_language(PyObject *self, PyObject *args) {
static int static int
py_callback(void *ctx, int flags, const char *text, int text_length, int start_offset, int end_offset) { py_callback(void *ctx, int flags, const char *text, int text_length, int start_offset, int end_offset) {
PyObject *ans = reinterpret_cast<PyObject*>(ctx); PyObject *ans = reinterpret_cast<PyObject*>(ctx);
pyobject_raii item(Py_BuildValue("{ss# si si si}", "text", text, text_length, "start", start_offset, "end", end_offset, "flags", flags)); Py_ssize_t psz = text_length;
pyobject_raii item(Py_BuildValue("{ss# si si si}", "text", text, psz, "start", start_offset, "end", end_offset, "flags", flags));
if (item) PyList_Append(ans, item.ptr()); if (item) PyList_Append(ans, item.ptr());
return SQLITE_OK; return SQLITE_OK;
} }

View File

@ -565,7 +565,8 @@ wpd::get_file(IPortableDevice *device, const wchar_t *object_id, PyObject *dest,
} else if (SUCCEEDED(hr)) { } else if (SUCCEEDED(hr)) {
if (bytes_read > 0) { if (bytes_read > 0) {
total_read += bytes_read; total_read += bytes_read;
pyobject_raii res(PyObject_CallMethod(dest, "write", "y#", buf.ptr(), bytes_read)); Py_ssize_t br = bytes_read;
pyobject_raii res(PyObject_CallMethod(dest, "write", "y#", buf.ptr(), br));
if (!res) { return NULL; } if (!res) { return NULL; }
if (callback != NULL) { if (callback != NULL) {
pyobject_raii r(PyObject_CallFunction(callback, "kK", total_read, filesize)); pyobject_raii r(PyObject_CallFunction(callback, "kK", total_read, filesize));

View File

@ -676,7 +676,8 @@ end:
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
buflen <<= 8; buflen += (uint8_t)buf[i]; buflen <<= 8; buflen += (uint8_t)buf[i];
} }
ans = Py_BuildValue("y#", buf + 3, MIN(buflen, pos - buf)); Py_ssize_t psz = MIN(buflen, pos - buf);
ans = Py_BuildValue("y#", buf + 3, psz);
} }
if (buf != NULL) free(buf); if (buf != NULL) free(buf);
if (PyErr_Occurred()) return NULL; if (PyErr_Occurred()) return NULL;

View File

@ -293,7 +293,8 @@ static PyObject* serialize_cert(PyObject *self, PyObject *args) {
if (!mem) return set_error("BIO_new"); if (!mem) return set_error("BIO_new");
if (!PEM_write_bio_X509(mem, cert)) { BIO_free(mem); return set_error("PEM_write_bio_X509"); } if (!PEM_write_bio_X509(mem, cert)) { BIO_free(mem); return set_error("PEM_write_bio_X509"); }
sz = BIO_get_mem_data(mem, &p); sz = BIO_get_mem_data(mem, &p);
ans = Py_BuildValue("s#", p, sz); Py_ssize_t psz = sz;
ans = Py_BuildValue("s#", p, psz);
BIO_free(mem); BIO_free(mem);
return ans; return ans;
} }
@ -314,7 +315,8 @@ static PyObject* cert_info(PyObject *self, PyObject *args) {
if (!mem) return set_error("BIO_new"); if (!mem) return set_error("BIO_new");
if (!X509_print_ex(mem, cert, XN_FLAG_COMPAT, X509_FLAG_COMPAT)) { BIO_free(mem); return set_error("X509_print_ex"); } if (!X509_print_ex(mem, cert, XN_FLAG_COMPAT, X509_FLAG_COMPAT)) { BIO_free(mem); return set_error("X509_print_ex"); }
sz = BIO_get_mem_data(mem, &p); sz = BIO_get_mem_data(mem, &p);
ans = Py_BuildValue("s#", p, sz); Py_ssize_t psz = sz;
ans = Py_BuildValue("s#", p, psz);
BIO_free(mem); BIO_free(mem);
return ans; return ans;
} }
@ -344,7 +346,8 @@ static PyObject* serialize_rsa_key(PyObject *self, PyObject *args) {
else ok = PEM_write_bio_PrivateKey(mem, key, NULL, NULL, 0, 0, NULL); else ok = PEM_write_bio_PrivateKey(mem, key, NULL, NULL, 0, 0, NULL);
if (!ok) { set_error("PEM_write_bio_PrivateKey"); goto error; } if (!ok) { set_error("PEM_write_bio_PrivateKey"); goto error; }
sz = BIO_get_mem_data(mem, &p); sz = BIO_get_mem_data(mem, &p);
ans = Py_BuildValue("s#", p, sz); Py_ssize_t psz = sz;
ans = Py_BuildValue("s#", p, psz);
error: error:
if (mem) BIO_free(mem); if (mem) BIO_free(mem);
if (key) EVP_PKEY_free(key); if (key) EVP_PKEY_free(key);

View File

@ -354,7 +354,8 @@ PDFDoc_get_xmp_metadata(PDFDoc *self, PyObject *args) {
if ((str = metadata->GetStream()) != NULL) { if ((str = metadata->GetStream()) != NULL) {
str->GetFilteredCopy(&buf, &len); str->GetFilteredCopy(&buf, &len);
if (buf != NULL) { if (buf != NULL) {
ans = Py_BuildValue("y#", buf, len); Py_ssize_t psz = len;
ans = Py_BuildValue("y#", buf, psz);
free(buf); buf = NULL; free(buf); buf = NULL;
if (ans == NULL) goto error; if (ans == NULL) goto error;
} }

View File

@ -460,7 +460,8 @@ winutil_read_directory_changes(PyObject *self, PyObject *args) {
p = (PFILE_NOTIFY_INFORMATION)(PyBytes_AS_STRING(buffer) + offset); p = (PFILE_NOTIFY_INFORMATION)(PyBytes_AS_STRING(buffer) + offset);
offset += p->NextEntryOffset; offset += p->NextEntryOffset;
if (p->FileNameLength) { if (p->FileNameLength) {
PyObject *temp = Py_BuildValue("ku#", p->Action, p->FileName, p->FileNameLength / sizeof(wchar_t)); Py_ssize_t psz = p->FileNameLength / sizeof(wchar_t);
PyObject *temp = Py_BuildValue("ku#", p->Action, p->FileName, psz);
if (!temp) { Py_DECREF(ans); return NULL; } if (!temp) { Py_DECREF(ans); return NULL; }
int ret = PyList_Append(ans, temp); int ret = PyList_Append(ans, temp);
Py_DECREF(temp); Py_DECREF(temp);
@ -1048,7 +1049,8 @@ load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
DWORD sz = SizeofResource(handle, res); DWORD sz = SizeofResource(handle, res);
if (!sz) return NULL; if (!sz) return NULL;
HICON icon = CreateIconFromResourceEx(data, sz, TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR); HICON icon = CreateIconFromResourceEx(data, sz, TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR);
return Py_BuildValue("y#N", data, sz, Handle_create(icon, IconHandle)); Py_ssize_t psz = sz;
return Py_BuildValue("y#N", data, psz, Handle_create(icon, IconHandle));
} }
struct GRPICONDIR { struct GRPICONDIR {