Exemple #1
0
PyObject* PyJPMethod::__call__(PyObject* o, PyObject* args, PyObject* kwargs)
{
	TRACE_IN("PyJPMethod::__call__");
	try {
		PyJPMethod* self = (PyJPMethod*)o;
		TRACE1(self->m_Method->getName());
		JPCleaner cleaner;

		//JPyHelper::dumpSequenceRefs(args, "start");

		vector<HostRef*> vargs;
		Py_ssize_t len = JPyObject::length(args);
		for (Py_ssize_t i = 0; i < len; i++)
		{
			PyObject* obj = JPySequence::getItem(args, i); // return a new ref
			HostRef* ref = new HostRef((void*)obj);
			cleaner.add(ref);
			vargs.push_back(ref);
			Py_DECREF(obj); // delete the new ref returned by getItem
		}

		//JPyHelper::dumpSequenceRefs(args, "middle");

		HostRef* res = self->m_Method->invoke(vargs);
	
		//JPyHelper::dumpSequenceRefs(args, "end");

		return detachRef(res);
	}
	PY_STANDARD_CATCH

	return NULL;

	TRACE_OUT;
}
Exemple #2
0
PyObject* JPypeJavaNio::convertToDirectBuffer(PyObject* self, PyObject* args)
{  
	TRACE_IN("convertStringToBuffer"); 

	// Use special method defined on the TypeConverter interface ...
	PyObject* src;

	JPyArg::parseTuple(args, "O", &src);

	PyObject* res = NULL;
	if (JPyObject::isMemoryView(src))
	{
		// converts to byte buffer ...
		JPTypeName tname = JPTypeName::fromType(JPTypeName::_byte);
		JPType* type = JPTypeManager::getType(tname);
		HostRef srcRef(src);

		TRACE1("Converting");
		HostRef* ref = type->convertToDirectBuffer(&srcRef);
		JPEnv::registerRef(ref, &srcRef);

		TRACE1("detaching result");
		res = detachRef(ref);
	}

	if (res != NULL)
	{
		return res;
	}

	RAISE(JPypeException, "Do not know how to convert to direct byte buffer, only memory view supported");

	return NULL;
	TRACE_OUT;
}
Exemple #3
0
PyObject* PyJPField::getInstanceAttribute(PyObject* o, PyObject* arg)
{
	TRACE_IN("getInstanceAttribute");

	JPCleaner cleaner;
	try {
		PyJPField* self = (PyJPField*)o;

		PyObject* jo;
		JPyArg::parseTuple(arg, "O!", &PyCapsule_Type, &jo);

		JPObject* obj = (JPObject*)JPyCObject::asVoidPtr(jo);

		jobject jobj = obj->getObject();
		cleaner.addLocal(jobj);

		HostRef* res = self->m_Field->getAttribute(jobj);
		return detachRef(res);
	}
	PY_STANDARD_CATCH

	return NULL;

	TRACE_OUT;
}
Exemple #4
0
PyObject* JPypeJavaArray::getArrayItem(PyObject* self, PyObject* arg)
{
	try {
		PyObject* arrayObject;
		int ndx;
		JPyArg::parseTuple(arg, "O!i", &PyCObject_Type, &arrayObject, &ndx);
		JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject);

		HostRef* res = a->getItem(ndx);
		return detachRef(res);
	}
	PY_STANDARD_CATCH

	return NULL;
}
Exemple #5
0
PyObject* PyJPField::getStaticAttribute(PyObject* o, PyObject* arg)
{
	try {
		PyJPField* self = (PyJPField*)o;

		HostRef* res = self->m_Field->getStaticAttribute();
		PyObject* result = detachRef(res);
		return result;


	}
	PY_STANDARD_CATCH

	return NULL;
}
Exemple #6
0
PyObject* PyJPBoundMethod::__call__(PyObject* o, PyObject* args, PyObject* kwargs)
{
	TRACE_IN("PyJPBoundMethod::__call__");
	try {
		PyObject* result=NULL;
		{
			PyJPBoundMethod* self = (PyJPBoundMethod*)o;
			JPCleaner cleaner;
			TRACE1(self->m_Method->m_Method->getName());
	
			vector<HostRef*> vargs;
			Py_ssize_t len = JPyObject::length(args);
			HostRef* ref = new HostRef((void*)self->m_Instance);
			cleaner.add(ref);
			vargs.push_back(ref);
			for (Py_ssize_t i = 0; i < len; i++)
			{
				PyObject* obj = JPySequence::getItem(args, i); // returns a new ref
				ref = new HostRef((void*)obj);
				cleaner.add(ref);
				vargs.push_back(ref);
				Py_DECREF(obj); // remove ref returned by getItem
			}
	
			HostRef* res = self->m_Method->m_Method->invoke(vargs);
			TRACE2("Call finished, result = ", res);	
			
			result = detachRef(res);
			TRACE1("Cleaning up");
		}
		return result;
	}
	PY_STANDARD_CATCH

	return NULL;

	TRACE_OUT;
}