Beispiel #1
0
PyObject* convertToJValue(PyObject* self, PyObject* arg)
{
	try {
		char* tname;
		PyObject* value;

		JPyArg::parseTuple(arg, "sO", &tname, &value);

		JPTypeName name = JPTypeName::fromSimple(tname);
		JPType* type = JPTypeManager::getType(name);

		HostRef ref(value);
		jvalue v = type->convertToJava(&ref);

		jvalue* pv = new jvalue();
		*pv = v;

		PyObject* res;
		if (type->isObjectType())
		{
			res = JPyCObject::fromVoidAndDesc((void*)pv, (void*)"object jvalue", PythonHostEnvironment::deleteObjectJValueDestructor);
		}
		else
		{
			res = JPyCObject::fromVoidAndDesc((void*)pv, (void*)"jvalue", PythonHostEnvironment::deleteJValueDestructor);
		}

		return res;
	}
	PY_STANDARD_CATCH

	return NULL;
}
Beispiel #2
0
JPObject* JPMethodOverload::invokeConstructor(jclass claz, vector<HostRef*>& arg)
{
	TRACE_IN("JPMethodOverload::invokeConstructor");

	size_t len = arg.size();
	JPCleaner cleaner;
	
	JPMallocCleaner<jvalue> v(len);

	for (unsigned int i = 0; i < len; i++)
	{
		HostRef* obj = arg[i];
		// TODO the following can easily be optimized ... or at least cached
		JPType* t = JPTypeManager::getType(m_Arguments[i]);

		v[i] = t->convertToJava(obj);		
		if (t->isObjectType())
		{
			cleaner.addLocal(v[i].l);
		}
	}
	
	jvalue val;
	val.l = JPEnv::getJava()->NewObjectA(claz, m_MethodID, v.borrow());
	cleaner.addLocal(val.l);
	TRACE1("Object created");
	
	JPTypeName name = JPJni::getName(claz);
	return new JPObject(name, val.l);

	TRACE_OUT;
}