Skip to content

Commit a3c0de6

Browse files
committed
[GR-24268] Add missing conversion to Py_Ssize_t in _PyDict_Next.
PullRequest: graalpython/1048
2 parents 1081c9d + 95b32c8 commit a3c0de6

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

graalpython/com.oracle.graal.python.cext/src/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int _PyDict_Next(PyObject *d, Py_ssize_t *ppos, PyObject **pkey, PyObject **pval
101101
*pvalue = PyTuple_GetItem(tresult, 1);
102102
}
103103
if (phash != NULL) {
104-
*phash = PyTuple_GetItem(tresult, 2);
104+
*phash = PyLong_AsSsize_t(PyTuple_GetItem(tresult, 2));
105105
}
106106
return 1;
107107

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_dict.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -255,6 +255,31 @@ def compile_module(self, name):
255255
cmpfunc=lambda x, y: type(x) == tuple and type(y) == tuple and len(x) == 3 and len(y) == 3 and (x[0] == 0 and y[0] == 0 or x == y)
256256
)
257257

258+
# _PyDict_SetItem_KnownHash
259+
test__PyDict_SetItem_KnownHash = CPyExtFunction(
260+
lambda args: {'a': "hello"},
261+
lambda: (({'a': "hello"}, ),),
262+
code='''PyObject* wrap__PyDict_SetItem_KnownHash(PyObject* dict) {
263+
PyObject* result = PyDict_New();
264+
265+
Py_ssize_t ppos = 0;
266+
PyObject* key;
267+
PyObject* value;
268+
Py_hash_t phash;
269+
270+
int res = 0;
271+
272+
_PyDict_Next(dict, &ppos, &key, &value, &phash);
273+
res = _PyDict_SetItem_KnownHash(result, key, value, phash);
274+
return result;
275+
}
276+
''',
277+
resultspec="O",
278+
argspec='O',
279+
arguments=["PyObject* dict"],
280+
callfunction="wrap__PyDict_SetItem_KnownHash",
281+
)
282+
258283
# PyDict_Size
259284
test_PyDict_Size = CPyExtFunction(
260285
lambda args: len(args[0]),

0 commit comments

Comments
 (0)