Skip to content

Commit 3f24a65

Browse files
committed
Implement C API function PyModule_GetDef
1 parent bf86fcb commit 3f24a65

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ PyObject* PyModule_New(const char *name) {
150150
return UPCALL_CEXT_O(_jls_PyModule_NewObject, polyglot_from_string(name, SRC_CS));
151151
}
152152

153+
PyModuleDef* PyModule_GetDef(PyObject* m) {
154+
if (!PyModule_Check(m)) {
155+
PyErr_BadArgument();
156+
return NULL;
157+
}
158+
return ((PyModuleObject *)m)->md_def;
159+
}
160+
153161
void* PyModule_GetState(PyObject *m) {
154162
if (!PyModule_Check(m)) {
155163
PyErr_BadArgument();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/DynamicObjectNativeWrapper.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -875,10 +875,9 @@ static Object doTpDict(PythonClass object, @SuppressWarnings("unused") PythonNat
875875
return toSulongNode.execute(dict);
876876
}
877877

878-
@Specialization(guards = "eq(MD_DEF, key)", limit = "1")
879-
static Object doMdDef(@SuppressWarnings("unused") PythonObject object, DynamicObjectNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key,
880-
@CachedLibrary("nativeWrapper.getNativeMemberStore()") HashingStorageLibrary lib) {
881-
return lib.getItem(nativeWrapper.getNativeMemberStore(), MD_DEF);
878+
@Specialization(guards = "eq(MD_DEF, key)")
879+
static Object doMdDef(PythonModule object, @SuppressWarnings("unused") DynamicObjectNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key) {
880+
return object.getNativeModuleDef();
882881
}
883882

884883
@Specialization(guards = "eq(BUF_DELEGATE, key)")
@@ -1274,11 +1273,9 @@ static void doTpSubclasses(PythonClass object, @SuppressWarnings("unused") Pytho
12741273
hashLib.forEach(storage, eachNode, new SubclassAddState(storage, hashLib, subclasses));
12751274
}
12761275

1277-
@Specialization(guards = "eq(MD_DEF, key)", limit = "1")
1278-
static void doMdDef(@SuppressWarnings("unused") PythonObject object, DynamicObjectNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key, Object value,
1279-
@CachedLanguage PythonLanguage lang,
1280-
@CachedLibrary("nativeWrapper.createNativeMemberStore(lang)") HashingStorageLibrary lib) {
1281-
lib.setItem(nativeWrapper.createNativeMemberStore(lang), MD_DEF.getMemberName(), value);
1276+
@Specialization(guards = "eq(MD_DEF, key)")
1277+
static void doMdDef(PythonModule object, @SuppressWarnings("unused") DynamicObjectNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key, Object value) {
1278+
object.setNativeModuleDef(value);
12821279
}
12831280

12841281
@Specialization(guards = "eq(TP_DICT, key)", limit = "1")

0 commit comments

Comments
 (0)