Skip to content

Commit 82d4c70

Browse files
committed
fix: use buf.obj instead of buf.buf for buffer-acquired check
buf.obj is set by PyObject_GetBuffer when a buffer is successfully acquired, making it a more semantically clear check than buf.buf. Initialize buf->obj = NULL in _parse_fastcall_args to match.
1 parent 7705e2a commit 82d4c70

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/_xxhash.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ _parse_fastcall_args(PyObject *const *args, Py_ssize_t nargs,
9191

9292
*seed = 0;
9393
buf->buf = NULL;
94+
buf->obj = NULL;
9495
*buf_owner = NULL;
9596

9697
/* positional args */
@@ -527,7 +528,7 @@ PYXXH32_vectorcall(PyObject *type, PyObject *const *args,
527528
self->seed = seed;
528529
XXH32_reset(self->xxhash_state, seed);
529530

530-
if (buf.buf)
531+
if (buf.obj)
531532
PYXXH32_do_update(self, &buf);
532533
Py_XDECREF(buf_owner);
533534
return (PyObject *)self;
@@ -570,7 +571,7 @@ static int PYXXH32_init(PYXXH32Object *self, PyObject *args, PyObject *kwargs)
570571
self->seed = seed;
571572
XXH32_reset(self->xxhash_state, seed);
572573

573-
if (buf.buf) {
574+
if (buf.obj) {
574575
PYXXH32_do_update(self, &buf);
575576
}
576577

@@ -886,7 +887,7 @@ PYXXH64_vectorcall(PyObject *type, PyObject *const *args,
886887
self->seed = seed;
887888
XXH64_reset(self->xxhash_state, seed);
888889

889-
if (buf.buf)
890+
if (buf.obj)
890891
PYXXH64_do_update(self, &buf);
891892
Py_XDECREF(buf_owner);
892893
return (PyObject *)self;
@@ -926,7 +927,7 @@ static int PYXXH64_init(PYXXH64Object *self, PyObject *args, PyObject *kwargs)
926927
self->seed = seed;
927928
XXH64_reset(self->xxhash_state, seed);
928929

929-
if (buf.buf) {
930+
if (buf.obj) {
930931
PYXXH64_do_update(self, &buf);
931932
}
932933

@@ -1241,7 +1242,7 @@ PYXXH3_64_vectorcall(PyObject *type, PyObject *const *args,
12411242
self->seed = seed;
12421243
XXH3_64bits_reset_withSeed(self->xxhash_state, seed);
12431244

1244-
if (buf.buf)
1245+
if (buf.obj)
12451246
PYXXH3_64_do_update(self, &buf);
12461247
Py_XDECREF(buf_owner);
12471248
return (PyObject *)self;
@@ -1281,7 +1282,7 @@ static int PYXXH3_64_init(PYXXH3_64Object *self, PyObject *args, PyObject *kwarg
12811282
self->seed = seed;
12821283
XXH3_64bits_reset_withSeed(self->xxhash_state, seed);
12831284

1284-
if (buf.buf) {
1285+
if (buf.obj) {
12851286
PYXXH3_64_do_update(self, &buf);
12861287
}
12871288

@@ -1605,7 +1606,7 @@ PYXXH3_128_vectorcall(PyObject *type, PyObject *const *args,
16051606
self->seed = seed;
16061607
XXH3_128bits_reset_withSeed(self->xxhash_state, seed);
16071608

1608-
if (buf.buf)
1609+
if (buf.obj)
16091610
PYXXH3_128_do_update(self, &buf);
16101611
Py_XDECREF(buf_owner);
16111612
return (PyObject *)self;
@@ -1645,7 +1646,7 @@ static int PYXXH3_128_init(PYXXH3_128Object *self, PyObject *args, PyObject *kwa
16451646
self->seed = seed;
16461647
XXH3_128bits_reset_withSeed(self->xxhash_state, seed);
16471648

1648-
if (buf.buf) {
1649+
if (buf.obj) {
16491650
PYXXH3_128_do_update(self, &buf);
16501651
}
16511652

0 commit comments

Comments
 (0)