Skip to content

Commit 8a68eb3

Browse files
committed
Implement C API function 'PyMapping_GetItemString'.
1 parent a61428c commit 8a68eb3

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,19 @@ PyObject* PySequence_Tuple(PyObject *v) {
247247
return to_sulong(result);
248248
}
249249

250-
PyObject *
251-
PySequence_Fast(PyObject *v, const char *m)
252-
{
250+
PyObject * PySequence_Fast(PyObject *v, const char *m) {
253251
void* result = polyglot_invoke(PY_TRUFFLE_CEXT, "PySequence_Fast", to_java(v), polyglot_from_string(m, "ascii"), ERROR_MARKER);
254252
if(result == ERROR_MARKER) {
255253
return NULL;
256254
}
257255
return to_sulong(result);
258256
}
257+
258+
PyObject * PyMapping_GetItemString(PyObject *o, const char *key) {
259+
void* result = polyglot_invoke(PY_TRUFFLE_CEXT, "PyObject_GetItem", to_java(o), polyglot_from_string(key, "utf-8"), ERROR_MARKER);
260+
if(result == ERROR_MARKER) {
261+
return NULL;
262+
}
263+
return to_sulong(result);
264+
}
265+

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -691,22 +691,19 @@ def compile_module(self, name):
691691
cmpfunc=unhandled_error_compare
692692
)
693693

694-
# test_PyMapping_GetItemString = CPyExtFunction(
695-
# _reference_fast,
696-
# lambda: (
697-
# (tuple(), "should not be an error"),
698-
# ((1,2,3), "should not be an error"),
699-
# ((None,), "should not be an error"),
700-
# ([], "should not be an error"),
701-
# #(['a','b','c'],"should not be an error"),
702-
# #({'a','b','c'}, "should not be an error"),
703-
# #({'a': 0,'b': 1,'c': 2}, "should not be an error"),
704-
# #(None, "None cannot be a sequence"),
705-
# #(0, "int cannot be a sequence"),
706-
# ),
707-
# resultspec="O",
708-
# argspec='Os',
709-
# arguments=["PyObject* sequence", "char* error_msg"],
710-
# cmpfunc=unhandled_error_compare
711-
# )
694+
test_PyMapping_GetItemString = CPyExtFunction(
695+
lambda args: args[0][args[1]],
696+
lambda: (
697+
(tuple(), "hello"),
698+
((1,2,3), "1"),
699+
(['a','b','c'],"nothing"),
700+
({'a','b','c'}, "a"),
701+
({'a': 0,'b': 1,'c': 2}, "nothing"),
702+
({'a': 0,'b': 1,'c': 2}, "c"),
703+
),
704+
resultspec="O",
705+
argspec='Os',
706+
arguments=["PyObject* mapping", "char* keyStr"],
707+
cmpfunc=unhandled_error_compare
708+
)
712709

0 commit comments

Comments
 (0)