Пример #1
0
int messageArrived(void* context, char* topicName, int topicLen,
		MQTTClient_message* message)
{
	PyObject *result = NULL;
	CallbackEntry* e = context;
	int rc = -99;
	PyGILState_STATE gstate;

	//printf("messageArrived %s %s %d %.*s\n", PyString_AsString(e->context), topicName, topicLen,
	//	message->payloadlen, (char*)message->payload);

	gstate = PyGILState_Ensure();
	if (topicLen == 0)
		result = PyEval_CallFunction(e->ma, "Os{ss#sisisisi}", e->context,
				topicName, "payload", message->payload, message->payloadlen,
				"qos", message->qos, "retained", message->retained, "dup",
				message->dup, "msgid", message->msgid);
	else
		result = PyEval_CallFunction(e->ma, "Os#{ss#sisisisi}", e->context,
				topicName, topicLen, "payload", message->payload,
				message->payloadlen, "qos", message->qos, "retained",
				message->retained, "dup", message->dup, "msgid",
				message->msgid);
	if (result)
	{
		if (PyInt_Check(result))
			rc = (int) PyInt_AsLong(result);
		Py_DECREF(result);
	}
	PyGILState_Release(gstate);
	MQTTClient_free(topicName);
	MQTTClient_freeMessage(&message);
	return rc;
}
Пример #2
0
static void
pygdk_event_handler_marshal(GdkEvent *event, gpointer data)
{
    PyGILState_STATE state;
    PyGtkCustomNotify *cunote = data;
    PyObject *retobj;
    PyObject *pyevent;

    g_assert (cunote->func);

    state = pyg_gil_state_ensure();

    pyevent = pyg_boxed_new(GDK_TYPE_EVENT, event, TRUE, TRUE);
    if (cunote->data)
        retobj = PyEval_CallFunction(cunote->func, "(NO)",
				     pyevent, cunote->data);
    else
        retobj = PyEval_CallFunction(cunote->func, "(N)", pyevent);

    if (retobj == NULL) {
        PyErr_Print();
    } else
        Py_DECREF(retobj);

    pyg_gil_state_release(state);
}
Пример #3
0
hlVoid ExtractItemStartCallback(HLDirectoryItem *pItem)
{
#if 0
	PyEval_RestoreThread(g_extract_save);

	if( pStartExtractFunc == Py_None )
	{
		if(!bSilent)
		{
			if(hlItemGetType(pItem) == HL_ITEM_FILE)
			{
				PySys_WriteStdout("  Extracting %s: ", hlItemGetName(pItem));
				ProgressStart();
			}
			else
			{
				PySys_WriteStdout("  Extracting %s:\n", hlItemGetName(pItem));
			}
		}
	}
	else
	{
		PyEval_CallFunction(pStartExtractFunc, "si", hlItemGetName(pItem), hlItemGetType(pItem));
	}

	g_extract_save = PyEval_SaveThread();
#endif // 0
}
Пример #4
0
static int heard2_cb(struct PortalInternal *p,uint16_t a, uint16_t b) {
    EchoIndicationJson_heard2 (&dummy, a, b);
    PyGILState_STATE gstate = PyGILState_Ensure();
    PyEval_CallFunction(callbackFunction, "(s)", dummy.map_base, NULL);
    PyGILState_Release(gstate);
    return 0;
}
Пример #5
0
//-----------------------------------------------------------------------------
// Relay a received chat (eg. IRC) message to Python.
gboolean received_chat_msg(PurpleAccount *account, char *sender, char *message,
  PurpleConversation *conv, PurpleMessageFlags flags, PyObject *func) {
  char *data = purple_markup_strip_html(message);
  
  PyGILState_STATE state = PyGILState_Ensure();
  
  PyObject *obj0;
  PyObject *obj1;
  PyObject *result;

  if (0 == conv) {
    conv = purple_conversation_new(PURPLE_CONV_TYPE_CHAT, account, sender);
  }
  
  obj0 = PyCObject_FromVoidPtr(account, NULL);
  obj1 = PyCObject_FromVoidPtr(conv, NULL);
  result = PyEval_CallFunction(func, "OssOi", obj0, sender, data, obj1, flags);
  if (result == NULL)
    PyErr_Print();
  
  Py_XDECREF(result);
  Py_XDECREF(obj0);
  Py_XDECREF(obj1);

  PyGILState_Release(state);
  g_free(data);
  
  return FALSE;
}
Пример #6
0
void evalc(int n,double *x,int ind,double *c,int *flag) {

  PyObject *result = NULL,*x_py = NULL;

  *flag = -1;

  if (BuildRealPyArray(n,x,&x_py) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, BuildRealPyArray "
                   "returned -1\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if ((result = PyEval_CallFunction(evalc_py,"(Oi)",x_py,ind)) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyEval_CallFunction "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if (!PyArg_ParseTuple(result,"di:evalc",c,flag)) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyArg_ParseTuple "
                   "returned false\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

 cleanup:
  Py_XDECREF(x_py  );
  Py_XDECREF(result);

}
Пример #7
0
QString PythonMapFormat::shortName() const
{
    QString ret;

    // find fun
    PyObject *pfun = PyObject_GetAttrString(mClass, "shortName");
    if (!pfun || !PyCallable_Check(pfun)) {
        PySys_WriteStderr("Plugin extension doesn't define \"shortName\". Falling back to \"nameFilter\"\n");
        return nameFilter();
    }

    // have fun
    PyObject *pinst = PyEval_CallFunction(pfun, "()");
    if (!pinst) {
        PySys_WriteStderr("** Uncaught exception in script **\n");
    } else {
        ret = PyString_AsString(pinst);
        Py_DECREF(pinst);
    }
    handleError();

    Py_DECREF(pfun);

    return ret;
}
Пример #8
0
int CPyContext::write(const char* buff, int length)
{	
	if(buff)
	{
		if(is_callable)
		{
			int tail = BUFFMAXSIZE - m_PyRenderObject->buff_pos;

			if(tail >= length)
			{
				memcpy(&(m_PyRenderObject->buff[m_PyRenderObject->buff_pos]), buff, length);
				m_PyRenderObject->buff_pos += length;
			}
			else
			{
				memcpy(&(m_PyRenderObject->buff[m_PyRenderObject->buff_pos]), buff, tail);
				int datatail = length - tail;

				PyObject* result = PyEval_CallFunction(m_retval, "(s#)", m_PyRenderObject->buff, BUFFMAXSIZE);
				Py_XDECREF(result);

				m_PyRenderObject->buff_pos = 0;

				if((length - tail) > BUFFMAXSIZE)
				{
					PyObject* result = PyEval_CallFunction(m_retval, "(s#)", &buff[tail], datatail);
					Py_XDECREF(result);
				}
				else	
				{
					memcpy(&(m_PyRenderObject->buff[0]), &buff[tail], datatail);
					m_PyRenderObject->buff_pos = datatail;
				};
			};
		}
		else
		{
			PyObject* pystr	= PyString_FromStringAndSize(buff, length);
			PyList_Append(m_retval, pystr);

			Py_DECREF(pystr);
		};
	};

	return length;
};
Пример #9
0
static void SHAKE_CALLBACK main_audio_callback(shake_device* dev, short* mic_samples, int mic_len, short* playback_samples, int playback_len) {
    int i;
    PyObject *result = NULL;

    //printf("pyshake_audio_callback\n");

    for(i=0; i<devicelist_count; i++) {
        if(devicelist[i] == dev && audio_callbacks[i][1] != NULL) {
            int j = 0;
            PyGILState_STATE gstate;
            gstate = PyGILState_Ensure();
            audio_callback_active[i] = 1;

            //printf("pyshake_audio_callback for device %d, %d samples for mic (%d), %d samples for playback (%d)\n", i, mic_len, mic_samples == NULL, playback_len, playback_samples == NULL);

            if(mic_samples == NULL) {
                audio_callbacks[i][3] = PyList_New(SHAKE_AUDIO_DATA_LEN);
                for(j=0; j<playback_len; j++) {
                    PyList_SetItem(audio_callbacks[i][3], j, PyLong_FromLong(playback_samples[j]));
                }
                Py_INCREF(audio_callbacks[i][3]);

                Py_INCREF(Py_None);
                audio_callbacks[i][2] = Py_None; // mic samples
            } else {
                audio_callbacks[i][2] = PyList_New(SHAKE_AUDIO_DATA_LEN);
                for(j=0; j<mic_len; j++) {
                    PyList_SetItem(audio_callbacks[i][2], j, PyLong_FromLong(mic_samples[j]));
                }
                Py_INCREF(audio_callbacks[i][2]);
                //printf("Building list of samples\n");

                Py_INCREF(Py_None);
                audio_callbacks[i][3] = Py_None; // playback samples
            }

            // call python callback in audio_callbacks[i]
            if(audio_callbacks[i][1] != NULL) {
                result = PyEval_CallFunction(audio_callbacks[i][0], "(OOO)", audio_callbacks[i][1], audio_callbacks[i][2], audio_callbacks[i][3]);
                Py_XDECREF(result);
            }

            Py_XDECREF(audio_callbacks[i][2]);
            Py_XDECREF(audio_callbacks[i][3]);

            // if value still == 1, do nothing
            // if value now == -1, means that callback should be removed immediately as it has been unregistered
            if(audio_callback_active[i] == 1) {
                audio_callback_active[i] = 0;
            } else {
                unregister_audio_callback(i);
            }
            PyGILState_Release(gstate);
            break;
        }
    }
}
Пример #10
0
void evalhl(int n,double *x,int m,double *lambda,double scalef,
            double *scalec,int *hllin,int *hlcol,double *hlval,int *hlnnz,
            int *flag) {

  int i;
  PyObject *result = NULL,*x_py = NULL,*lambda_py = NULL,*scalec_py = NULL,
           *hllin_py,*hlcol_py,*hlval_py;

  *flag = -1;

  if (BuildRealPyArray(n,x,&x_py          ) == -1 ||
      BuildRealPyArray(m,lambda,&lambda_py) == -1 ||
      BuildRealPyArray(m,scalec,&scalec_py) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, BuildRealPyArray "
                   "returned -1\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if ((result = PyEval_CallFunction(evalhl_py,"(OiOdO)",x_py,m,lambda_py,scalef,
                                    scalec_py)) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyEval_CallFunction "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if (!PyArg_ParseTuple(result,"OOOii:evalhl",&hllin_py,&hlcol_py,&hlval_py,
                        hlnnz,flag)) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyArg_ParseTuple "
                   "returned false\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

  if (BuildIntArray( *hlnnz,hllin_py,hllin) == -1 ||
      BuildIntArray( *hlnnz,hlcol_py,hlcol) == -1 ||
      BuildRealArray(*hlnnz,hlval_py,hlval) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, Build(Int|Real)Array "
                   "returned -1\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

  for (i = 0; i < *hlnnz; i++) {
     hllin[i]++;
     hlcol[i]++;
  }

 cleanup:
  Py_XDECREF(x_py     );
  Py_XDECREF(lambda_py);
  Py_XDECREF(scalec_py);
  Py_XDECREF(result   );

}
Пример #11
0
void CPyContext::flush()
{
	if(is_callable)
	{
		PyObject* result = PyEval_CallFunction(m_retval, "(s#)", m_PyRenderObject->buff, m_PyRenderObject->buff_pos);
		Py_XDECREF(result);

		m_PyRenderObject->buff_pos = 0;
	};
};
Пример #12
0
hlVoid FileProgressCallback(HLDirectoryItem *pFile, hlUInt uiBytesExtracted, hlUInt uiBytesTotal, hlBool *pCancel)
{
#if 0
	PyEval_RestoreThread(g_extract_save);

	if( pUpdateFunc == Py_None )
		ProgressUpdate((hlULongLong)uiBytesExtracted, (hlULongLong)uiBytesTotal);
	else
		PyEval_CallFunction(pUpdateFunc, "II", uiBytesExtracted, uiBytesTotal);

	g_extract_save = PyEval_SaveThread();
#endif // 0
}
Пример #13
0
void inip(int *n,double **x,double **l,double **u,int *m,double **lambda,
          int **equatn,int **linear,int *coded,int *checkder) {

  PyObject *result = NULL,*x_py,*l_py,*u_py,*lambda_py,*equatn_py,*linear_py,
           *coded_py;

  if ((result = PyEval_CallFunction(inip_py,"()")) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyEval_CallFunction "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if (!PyArg_ParseTuple(result,"iOOOiOOOOi:inip",n,&x_py,&l_py,&u_py,m,
                        &lambda_py,&equatn_py,&linear_py,&coded_py,checkder)) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyArg_ParseTuple "
                   "returned false\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if ((*x      = (double *) malloc(*n * sizeof(double))) == NULL ||
      (*l      = (double *) malloc(*n * sizeof(double))) == NULL ||
      (*u      = (double *) malloc(*n * sizeof(double))) == NULL ||
      (*lambda = (double *) malloc(*m * sizeof(double))) == NULL ||
      (*equatn = (int    *) malloc(*m * sizeof(int   ))) == NULL ||
      (*linear = (int    *) malloc(*m * sizeof(int   ))) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, malloc "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if (BuildRealArray(*n,x_py,*x          ) == -1 ||
      BuildRealArray(*n,l_py,*l          ) == -1 ||
      BuildRealArray(*n,u_py,*u          ) == -1 ||
      BuildRealArray(*m,lambda_py,*lambda) == -1 ||
      BuildIntArray( *m,equatn_py,*equatn) == -1 ||
      BuildIntArray( *m,linear_py,*linear) == -1 ||
      BuildIntArray( 10, coded_py,  coded) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, Build(Int|Real)Array "
                   "returned -1\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

 cleanup:
  Py_XDECREF(result);

}
Пример #14
0
void evalhc(int n,double *x,int ind,int *hclin,int *hccol,double *hcval,
            int *hcnnz,int *flag) {

  int i;
  PyObject *result = NULL,*x_py = NULL,*hclin_py,*hccol_py,*hcval_py;

  *flag = -1;

  if (BuildRealPyArray(n,x,&x_py) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, BuildRealPyArray "
                   "returned -1\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if ((result = PyEval_CallFunction(evalhc_py,"(Oi)",x_py,ind)) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyEval_CallFunction "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if (!PyArg_ParseTuple(result,"OOOii:evalhc",&hclin_py,&hccol_py,&hcval_py,
                        hcnnz,flag)) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyArg_ParseTuple "
                   "returned false\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

  if (BuildIntArray( *hcnnz,hclin_py,hclin) == -1 ||
      BuildIntArray( *hcnnz,hccol_py,hccol) == -1 ||
      BuildRealArray(*hcnnz,hcval_py,hcval) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, Build(Int|Real)Array "
                   "returned -1\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

  for (i = 0; i < *hcnnz; i++) {
     hclin[i]++;
     hccol[i]++;
  }

 cleanup:
  Py_XDECREF(x_py  );
  Py_XDECREF(result);

}
Пример #15
0
void evalhlp(int n,double *x,int m,double *lambda,double scalef,
             double *scalec,double *p,double *hp,int *goth,int *flag) {

  PyObject *result = NULL,*x_py = NULL,*lambda_py = NULL,*scalec_py = NULL,
           *p_py = NULL,*hp_py;

  *flag = -1;

  if (BuildRealPyArray(n,x,&x_py          ) == -1 ||
      BuildRealPyArray(m,lambda,&lambda_py) == -1 ||
      BuildRealPyArray(m,scalec,&scalec_py) == -1 ||
      BuildRealPyArray(n,p,&p_py          ) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, BuildRealPyArray "
                   "returned -1\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if ((result = PyEval_CallFunction(evalhlp_py,"(OiOdOi)",x_py,m,lambda_py,
                                    scalef,scalec_py,p_py,*goth)) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyEval_CallFunction "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if (!PyArg_ParseTuple(result,"Oii:evalhlp",&hp_py,goth,flag)) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyArg_ParseTuple "
                   "returned false\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

  if (BuildRealArray(n,hp_py,hp) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, BuildRealArray "
                   "returned -1\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

 cleanup:
  Py_XDECREF(x_py     );
  Py_XDECREF(lambda_py);
  Py_XDECREF(scalec_py);
  Py_XDECREF(p_py     );
  Py_XDECREF(result   );

}
Пример #16
0
void evalgjac(int n,double *x,double *g,int m,int *jcfun,int *jcvar,
              double *jcval,int *jcnnz,int *flag) {

  int i;
  PyObject *result = NULL,*x_py = NULL,*g_py,*jcfun_py,*jcvar_py,*jcval_py;

  *flag = -1;

  if (BuildRealPyArray(n,x,&x_py) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, BuildRealPyArray "
                   "returned -1\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if ((result = PyEval_CallFunction(evalgjac_py,"(Oi)",x_py,m)) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyEval_CallFunction "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if (!PyArg_ParseTuple(result,"OOOOii:evalgjac",&g_py,&jcfun_py,&jcvar_py,
                        &jcval_py,jcnnz,flag)) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyArg_ParseTuple "
                   "returned false\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

  if (BuildRealArray(n,g_py,g             ) == -1 ||
      BuildIntArray( *jcnnz,jcfun_py,jcfun) == -1 ||
      BuildIntArray( *jcnnz,jcvar_py,jcvar) == -1 ||
      BuildRealArray(*jcnnz,jcval_py,jcval) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, Build(Int|Real)Array "
                   "returned -1\n\n",__func__);
    return_value = NULL; *flag = -1;
    goto cleanup;
  }

  for (i = 0; i < *jcnnz; i++)
     jcvar[i]++;

 cleanup:
  Py_XDECREF(x_py  );
  Py_XDECREF(result);

}
Пример #17
0
//-----------------------------------------------------------------------------
void buddy_typing(PurpleAccount *account, const char *name, PyObject *func) {
  PyGILState_STATE state = PyGILState_Ensure();
  
  PyObject *obj0;
  PyObject *result;

  obj0 = PyCObject_FromVoidPtr(account, NULL);
  result = PyEval_CallFunction(func, "Os", obj0, name);
  if (result == NULL)
    PyErr_Print();
  
  Py_XDECREF(result);
  Py_XDECREF(obj0);

  PyGILState_Release(state);
}
Пример #18
0
//-----------------------------------------------------------------------------
void buddy_icon_changed(PurpleBuddy *buddy, PyObject *func) {
  PyGILState_STATE state = PyGILState_Ensure();
  
  PyObject *obj0;
  PyObject *result;

  obj0 = PyCObject_FromVoidPtr(buddy, NULL);
  result = PyEval_CallFunction(func, "(O)", obj0);
  if (result == NULL)
    PyErr_Print();
  
  Py_XDECREF(result);
  Py_XDECREF(obj0);

  PyGILState_Release(state);
}
Пример #19
0
void xfers_python_cb(PurpleXfer *xfer, PyObject *func)
{
  PyGILState_STATE state = PyGILState_Ensure();
  
  PyObject *obj0;
  PyObject *result;

  obj0 = PyCObject_FromVoidPtr(xfer, NULL);
  result = PyEval_CallFunction(func, "(O)", obj0);
  if (result == NULL)
    PyErr_Print();
  
  Py_XDECREF(result);
  Py_XDECREF(obj0);

  PyGILState_Release(state);
}
Пример #20
0
static void
callbackWrapper(u_char *args, const struct pcap_pkthdr* pkthdr, const u_char* packet)
{
    PyObject *summary = NULL;
    PyObject *pkt = NULL;

    summary = Py_BuildValue("llII", pkthdr->ts.tv_sec, pkthdr->ts.tv_usec,
        pkthdr->caplen, pkthdr->len);

    pkt = Py_BuildValue("s#", packet, pkthdr->caplen);

    if(PyEval_CallFunction(py_callback_func, "OO", summary, pkt) == NULL)
    {
        PyErr_Print();
        Py_Exit(-1);
    }
}
Пример #21
0
void endp(int n,double *x,double *l,double *u,int m,double *lambda,
          int *equatn,int *linear) {

  PyObject *result = NULL,*x_py = NULL,*l_py = NULL,*u_py = NULL,
           *lambda_py = NULL,*equatn_py = NULL,*linear_py = NULL;

  if (BuildRealPyArray(n,x,&x_py          ) == -1 ||
      BuildRealPyArray(n,l,&l_py          ) == -1 ||
      BuildRealPyArray(n,u,&u_py          ) == -1 ||
      BuildRealPyArray(m,lambda,&lambda_py) == -1 ||
      BuildIntPyArray( m,equatn,&equatn_py) == -1 ||
      BuildIntPyArray( m,linear,&linear_py) == -1) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, Build(Int|Real)PyArray "
                   "returned -1\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

  if ((result = PyEval_CallFunction(endp_py,"(OOOiOOO)",x_py,l_py,u_py,m,
                                    lambda_py,equatn_py,linear_py)) == NULL) {
    fprintf(stderr,"\nPYTHON INTERFACE ERROR: in %s, PyEval_CallFunction "
                   "returned NULL\n\n",__func__);
    return_value = NULL;
    goto cleanup;
  }

 cleanup:
  free(x     );
  free(l     );
  free(u     );
  free(lambda);
  free(equatn);
  free(linear);

  Py_XDECREF(x_py     );
  Py_XDECREF(l_py     );
  Py_XDECREF(u_py     );
  Py_XDECREF(lambda_py);
  Py_XDECREF(equatn_py);
  Py_XDECREF(linear_py);
  Py_XDECREF(result   );

}
Пример #22
0
static void SHAKE_CALLBACK main_callback(shake_device* dev, int ev) {
    int i;
    PyObject *result;

    for(i=0; i<devicelist_count; i++) {
        if(devicelist[i] == dev) {
            // call python callback in callbacks[i]
            PyGILState_STATE gstate;
            gstate = PyGILState_Ensure();

            /* Perform Python actions here.  */
            result = PyEval_CallFunction(callbacks[i][0], "(Oi)", callbacks[i][1], ev);
            PyGILState_Release(gstate);

            Py_XDECREF(result);
            break;
        }
    }
}
Пример #23
0
# define N BOOST_PP_ITERATION()

template <
    class R
    BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
    >
typename detail::returnable<R>::type
call(PyObject* callable
    BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)
    , abt_boost::type<R>* = 0
    )
{
    PyObject* const result = 
        PyEval_CallFunction(
            callable
            , const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")")
            BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
            );
    
    // This conversion *must not* be done in the same expression as
    // the call, because, in the special case where the result is a
    // reference a Python object which was created by converting a C++
    // argument for passing to PyEval_CallFunction, its reference
    // count will be 2 until the end of the full expression containing
    // the conversion, and that interferes with dangling
    // pointer/reference detection.
    converter::return_from_python<R> converter;
    return converter(result);
}

# undef N
Пример #24
0
hlVoid ExtractItemEndCallback(HLDirectoryItem *pItem, hlBool bSuccess)
{
#if 0
	PyEval_RestoreThread(g_extract_save);

	hlUInt uiSize = 0;
	hlChar lpPath[512] = "";

	if( pEndExtractFunc == Py_None )
	{
		if(bSuccess)
		{
			if(!bSilent)
			{
				hlItemGetSize(pItem, &uiSize);
				if(hlItemGetType(pItem) == HL_ITEM_FILE)
				{
					PySys_WriteStdout("OK");
					PySys_WriteStdout(" (%u B)\n", uiSize);
				}
				else
				{
					PySys_WriteStdout("  Done %s: ", hlItemGetName(pItem));
					PySys_WriteStdout("OK");
					PySys_WriteStdout(" (%u B)\n", uiSize);
				}
			}
		}
		else
		{
			if(!bSilent)
			{
				if(hlItemGetType(pItem) == HL_ITEM_FILE)
				{
					PySys_WriteStdout("Errored\n");
					PySys_WriteStdout("    %s\n", hlGetString(HL_ERROR_SHORT_FORMATED));
				}
				else
				{
					PySys_WriteStdout("  Done %s: ", hlItemGetName(pItem));
					PySys_WriteStdout("Errored\n");
				}
			}
			else
			{
				hlItemGetPath(pItem, lpPath, sizeof(lpPath));
				if(hlItemGetType(pItem) == HL_ITEM_FILE)
				{
					PySys_WriteStdout("  Error extracting %s:\n", lpPath);
					PySys_WriteStdout("    %s\n", hlGetString(HL_ERROR_SHORT_FORMATED));
				}
				else
				{
					PySys_WriteStdout("  Error extracting %s.\n", lpPath);
				}
			}
		}
	}
	else
	{
		hlItemGetSize(pItem, &uiSize);
		hlItemGetPath(pItem, lpPath, sizeof(lpPath));

		PyEval_CallFunction(pEndExtractFunc, "bsisIs", bSuccess, hlItemGetName(pItem), hlItemGetType(pItem), lpPath, uiSize, bSuccess ? "" : hlGetString(HL_ERROR_SHORT_FORMATED));
	}

	g_extract_save = PyEval_SaveThread();
#endif // 0
	hlUInt uiSize = 0;
	hlChar lpPath[512] = "";

	if(hlItemGetType(pItem) == HL_ITEM_FILE) 
	{
		hlItemGetSize(pItem, &uiSize);

		g_bytesExtracted += uiSize;

		if( g_bytesExtracted > 10000000 && pUpdateFunc != Py_None )
		{
			hlItemGetPath(pItem, lpPath, sizeof(lpPath));

			PyEval_RestoreThread(g_extract_save);
			PyEval_CallFunction(pUpdateFunc, "bsisIs", bSuccess, hlItemGetName(pItem), hlItemGetType(pItem), lpPath, g_bytesExtracted, bSuccess ? "" : hlGetString(HL_ERROR_SHORT_FORMATED));
			g_extract_save = PyEval_SaveThread();

			g_bytesExtracted = 0;
		}
	}
}