Why can't I destroy Py_Decref() the pointer? It crashes because of that. Anyone could point to me what is wrong in this piece of code? - #include "stdafx.h"
-
#include <windows.h>
-
#include <string>
-
#include <Python.h>
-
#include <iostream>
-
using namespace std;
-
-
#include "BounceInterface_wrap.cxx"
-
-
PyObject * pModule = NULL, *pFunc = NULL;
-
PyThreadState * mainThreadState = NULL;
-
-
-
const char * line = "from time import time,ctime\nprint 'Today is',ctime(time())\n";
-
-
DWORD WINAPI Callback1( LPVOID lpvData)
-
{
-
-
-
for(int i = 0; i < 200; i++)
-
{
-
-
-
PyObject *pArgs, *pObject, *pMsg;
-
BounceResult Object;
-
pObject = SWIG_NewPointerObj((void*)&Object, SWIGTYPE_p_BounceResult, 1);
-
pMsg = PyString_FromString("ASDASDSAD");
-
-
PyObject * pValue = NULL;
-
-
pArgs = PyTuple_New(2);
-
-
PyTuple_SetItem(pArgs, 0, pObject);
-
PyTuple_SetItem(pArgs, 1, pMsg);
-
-
-
if(pArgs && pMsg && pObject)
-
{
-
//printf("Calling function...");
-
Py_BEGIN_ALLOW_THREADS;
-
pValue = PyObject_CallFunction(pFunc, "O", pArgs);
-
Py_END_ALLOW_THREADS;
-
-
}
-
else
-
{
-
return NULL;
-
}
-
-
if (!pValue) {
-
fprintf(stderr, "Cannot convert argument\n");
-
return NULL;
-
}
-
-
-
if (pValue) {
-
Py_XDECREF(pValue);
-
}
-
else {
-
PyErr_Print();
-
fprintf(stderr,"Call failed\n");
-
return NULL;
-
}
-
-
if(pObject != NULL)
-
{
-
// Py_DECREF(pObject);; If I uncomment this it'll crash
-
}
-
if(pArgs != NULL)
-
{
-
// Py_DECREF(pArgs); If I uncomment this it'll crash
-
}
-
-
-
-
}
-
-
-
Sleep(100);
-
return TRUE;
-
};
-
-
-
int main(int argc, char *argv[])
-
{
-
Py_Initialize();
-
PyEval_InitThreads();
-
SWIG_init();
-
init_BounceCheck();
-
-
PyObject *pName = NULL;
-
-
pName = PyString_FromString("bounce");
-
pModule = PyImport_Import(pName);
-
Py_DECREF(pName);
-
-
if (pModule != NULL)
-
{
-
pFunc = PyObject_GetAttrString(pModule, "CheckBounce");
-
-
if (!pFunc || !PyCallable_Check(pFunc))
-
{
-
printf("ERROR\n");
-
//Py_DECREF(pFunc);
-
system("PAUSE");
-
}
-
}
-
-
const int nHandles = 1000;
-
HANDLE hHandles[nHandles];
-
DWORD threadID[nHandles];
-
-
-
-
for(int i = 0; i < nHandles; i++)
-
{
-
hHandles[i] = CreateThread(NULL,0 ,Callback1,(LPVOID)NULL,0,&threadID[i]);
-
}
-
-
cout << "Waiting for the threads to end" << endl;
-
-
for(int i = 0; i < nHandles; i++)
-
{
-
WaitForSingleObject(hHandles[i],INFINITE);
-
CloseHandle(hHandles[i]);
-
}
-
cout << "Threads are finished...\n";
-
// shut down the interpreter
-
-
-
Py_Finalize();
-
system("PAUSE");
-
return 0;
-
}
-
0 909 Sign in to post your reply or Sign up for a free account.
Similar topics
by: jimjim |
last post by:
Hello,
This is a simple question for you all, I guess .
int main(){
double *g= new double;
*g = 9;
delete g;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
*g =...
|
by: Martin Heuckeroth |
last post by:
Hi,
How can we set and read the pointer in a listbox or a combibox to the
found search. We use the datarow function with SQL2000 and VB.NET.
Hope anyone can help
Regards, Martin
|
by: arun |
last post by:
suppose i have a pointer to an array of integers.can i initialize each
member of the array using pointers?plz explain
|
by: mkaushik |
last post by:
Hi everyone,
Im just starting out with C++, and am curious to know how "delete
<pointer>", knows about the number of memory locations to free.
I read somewhere that delete frees up space...
|
by: laikon |
last post by:
Hi, everyone, below is my program to test static pointer data member;
class A
{
private:
static A* p;
protected:
A() {}
public:
static A* init()
|
by: shuisheng |
last post by:
Dear All,
The problem of choosing pointer or reference is always confusing me.
Would you please give me some suggestion on it. I appreciate your kind
help.
For example, I'd like to convert a...
|
by: desktop |
last post by:
Why does the value of the below int pointer not disappear after using
destroy:
std::allocator<intallo;
int* ip;
allo.construct(ip,777);
std::cout << "*ip = " << *ip << std::endl;
...
|
by: ASWINIGANGADHARAM |
last post by:
hi all,
i am studying engg,i have problem that ,how can i convet from the file pointer to character pointer or character array.in my project i cant use file pointer,i need to convert file pointer...
|
by: Phil Bouchard |
last post by:
I am currently writting a smart pointer which is reasonnably stable and I
decided supporting allocators for completion because of its increase in
efficiency when the same pool used by containers is...
|
by: Juha Nieminen |
last post by:
I asked a long time ago in this group how to make a smart pointer
which works with incomplete types. I got this answer (only relevant
parts included):
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |