/** * Call a Java static method on a class from native code. * * @param cname name of the class whose method is to be called * @param loader the class loader that's to be used to lookup the class * @param method_name the name of the method to be called * @param signature the signature of the method to be called * @param argptr the arguments to be passed to the method * * @throws NuSuchMethodError if method cannot be found * * @return the return value of the method */ void do_execute_java_class_method_v(jvalue *retval, const char* cname, Hjava_lang_ClassLoader* loader, const char* method_name, const char* signature, va_list argptr) { Hjava_lang_Class* clazz; errorInfo info; Method* mb = NULL; char *buf; /* Convert "." to "/" and lookup class */ buf = checkPtr(KMALLOC(strlen(cname) + 1)); classname2pathname(cname, buf); clazz = lookupClass(buf, loader, &info); KFREE(buf); /* Get method */ if (clazz != NULL) { mb = lookupClassMethod(clazz, method_name, signature, false, &info); } if (mb == NULL) { throwError(&info); } /* Method must be static to invoke it here */ if ((mb->accflags & ACC_STATIC) == 0) { throwException(NoSuchMethodError(method_name)); } /* Make the call */ KaffeVM_callMethodV(mb, METHOD_NATIVECODE(mb), NULL, argptr, retval); }
Class* Unit::getClass(const NamedEntity* ne, const StringData *name, bool tryAutoload) { Class *cls = lookupClass(ne); if (UNLIKELY(!cls && tryAutoload)) { return loadMissingClass(ne, name); } return cls; }
/** * Allocate an object and execute the constructor. * * @param cname the name of the class to be instantiated (may be 0 if cc is != 0) * @param loader the class loader that's to be used to lookup the class * @param cc the class to be instantiated (may be 0 if cname is != 0) * @param signature the signature of the constructor to be executed * @param argptr arguments to be passed to the constructor * * @throws InstantiationException if class is an interface or abstract * @throws NoSuchMethodError if the specified constructor cannot be found * * @return the newly allocated object */ Hjava_lang_Object* execute_java_constructor_v(const char* cname, Hjava_lang_ClassLoader* loader, Hjava_lang_Class* cc, const char* signature, va_list argptr) { Hjava_lang_Object* obj; Method* mb; jvalue retval; errorInfo info; Utf8Const* sig; if (cc == 0) { char *buf; /* Convert "." to "/" and lookup class */ buf = checkPtr(KMALLOC(strlen(cname) + 1)); classname2pathname(cname, buf); cc = lookupClass(buf, loader, &info); KFREE(buf); if (!cc) { throwError(&info); } } /* We cannot construct interfaces or abstract classes */ if (CLASS_IS_INTERFACE(cc) || CLASS_IS_ABSTRACT(cc)) { throwException(InstantiationException(cc->name->data)); } if (cc->state < CSTATE_USABLE) { if (processClass(cc, CSTATE_COMPLETE, &info) == false) { throwError(&info); } } sig = checkPtr(utf8ConstFromString(signature)); mb = findMethodLocal(cc, constructor_name, sig); utf8ConstRelease(sig); if (mb == 0) { throwException(NoSuchMethodError(constructor_name->data)); } obj = newObject(cc); assert(obj != 0); /* Make the call */ KaffeVM_callMethodV(mb, METHOD_NATIVECODE(mb), obj, argptr, &retval); return (obj); }
/* * Look up a qualified Python type and return the corresponding node (or NULL * if the type should be omitted because of a recursive definition). */ static typeHintNodeDef *lookupType(sipSpec *pt, char *name, int out) { char *sp, *ep; classDef *scope_cd; mappedTypeDef *scope_mtd; typeHintDef *thd; typeHintNodeDef *node; /* Start searching at the global level. */ scope_cd = NULL; scope_mtd = NULL; sp = name; ep = NULL; while (*sp != '\0') { enumDef *ed; /* Isolate the next part of the name. */ if ((ep = strchr(sp, '.')) != NULL) *ep = '\0'; /* See if it's an enum. */ if ((ed = lookupEnum(pt, sp, scope_cd, scope_mtd)) != NULL) { /* Make sure we have used the whole name. */ if (ep == NULL) { node = sipMalloc(sizeof (typeHintNodeDef)); node->type = enum_node; node->u.ed = ed; return node; } /* There is some left so the whole lookup has failed. */ break; } /* * If we have a mapped type scope then we must be looking for an enum, * which we have failed to find. */ if (scope_mtd != NULL) break; if (scope_cd == NULL) { mappedTypeDef *mtd; /* * We are looking at the global level, so see if it is a mapped * type. */ if ((mtd = lookupMappedType(pt, sp)) != NULL) { /* * If we have used the whole name then the lookup has * succeeded. */ if (ep == NULL) { thd = (out ? mtd->typehint_out : mtd->typehint_in); if (thd != NULL && thd->status != being_parsed) return copyTypeHintNode(pt, thd, out); /* * If we get here we have a recursively defined mapped type * so we simply omit it. */ return NULL; } /* Otherwise this is the scope for the next part. */ scope_mtd = mtd; } } if (scope_mtd == NULL) { classDef *cd; /* If we get here then it must be a class. */ if ((cd = lookupClass(pt, sp, scope_cd)) == NULL) break; /* If we have used the whole name then the lookup has succeeded. */ if (ep == NULL) { thd = (out ? cd->typehint_out : cd->typehint_in); if (thd != NULL && thd->status != being_parsed) return copyTypeHintNode(pt, thd, out); node = sipMalloc(sizeof (typeHintNodeDef)); node->type = class_node; node->u.cd = cd; return node; } /* Otherwise this is the scope for the next part. */ scope_cd = cd; } /* If we have run out of name then the lookup has failed. */ if (ep == NULL) break; /* Repair the name and go on to the next part. */ *ep++ = '.'; sp = ep; } /* Repair the name. */ if (ep != NULL) *ep = '.'; /* Nothing was found. */ node = sipMalloc(sizeof (typeHintNodeDef)); node->type = other_node; node->u.name = sipStrdup(name); return node; }