Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_superclass 有一个错误,会导致register_natives 中获取的clazz_id不正确 #83

Open
pony5551 opened this issue Nov 21, 2023 · 0 comments

Comments

@pony5551
Copy link

我的代码修改如下
@native_method
def get_superclass(self, uc, env, clazz_idx):
"""
If clazz represents any class other than the class Object, then this function returns the object that represents the superclass of the class specified by clazz.

    If clazz specifies the class Object, or clazz represents an interface, this function returns NULL.
    """
    clazz = self.get_reference(clazz_idx)
    if not isinstance(clazz, jclass):
        raise ValueError('Expected a jclass.')
    
    # pony modfy start
    # Create class instance.
    class_obj = clazz.value
    pyclass = class_obj
    logger.debug("JNIEnv->GetSuperClass (%s) is called, index %d" % (pyclass.jvm_name, clazz_idx) )

    pyclazz_super = pyclass.jvm_super
    if (not pyclazz_super):
        raise RuntimeError("super class for %s is None!!! you should at least inherit Object!!!")
    #
    logger.debug("JNIEnv->GetSuperClass (%s) return (%s)"%(pyclass.jvm_name, pyclazz_super.jvm_name))
    # clazz_super_object = pyclazz_super.class_object
    return self.add_local_reference(jclass(pyclazz_super))

    # pony modfy end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant