freelanceprogrammers.org Forum Index » Delphi

bug in demo9?


View user's profile Post To page top
tocer_deng Posted: Sun May 21, 2006 7:56 pm


Joined: 17 May 2006

Posts: 32
bug in demo9?
Hi:

read line 25 in module.pas in demo9:

Result := nil;

it takes a error: "SystemError: error return without exception set" when running
into this line. I fix it:

Result := Py_None;

now it work well.

I use Delphi7 + p4d 3.31. Is it a bug?

I have another question. After "Add" function in this unit, it must use "far"
and "cdecl".
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Sun May 21, 2006 8:53 pm


Joined: 29 Apr 2005

Posts: 103
bug in demo9?
Hi,

>read line 25 in module.pas in demo9:

>Result := nil;

>it takes a error: "SystemError: error return without exception set" when
>running
>into this line. I fix it:

>Result := Py_None;

>now it work well.

>I use Delphi7 + p4d 3.31. Is it a bug?

No, the code is correct. I don`t know why in your case you get such an
exception as it works fine with my D7.
The Python function PyArg_ParseTuple will return an integer telling you if
it could parse or not the parameters.
If yes then you have to provide a valid Python object as a result (such as
Py_None which by the way must be incremented before returning it!!!!!!
That`s why you should write something like Result := ReturnNone; which will
do it for you).
If it could not parse the parameters, it will create its own error message
and in that case you MUST return nil.

>I have another question. After "Add" function in this unit, it must use
>"far"
>and "cdecl".
I think that "Far" is obsolete now.
But "cdecl" is a must as Python APIs are coded in the C language.

Bye,

Morgan
Reply with quote
Send private message
View user's profile Post To page top
tocer_deng Posted: Mon May 22, 2006 6:31 am


Joined: 17 May 2006

Posts: 32
bug in demo9?
I get it. thank your particular explain.

in fact, I write some demo for p4d which will be post in py4d wiki.
First of these is to create a new modal for python extention which
return None. After looking demo9, I think simply that return nil is
ok, but I`m wrong. Return value must be python type value in any case,
but nil is not a python type value.

--tocer

Morgan Martinet wrote::
> Hi,
>
>> read line 25 in module.pas in demo9:
>
>> Result := nil;
>
>> it takes a error: "SystemError: error return without exception set" when
>> running
>> into this line. I fix it:
>
>> Result := Py_None;
>
>> now it work well.
>
>> I use Delphi7 + p4d 3.31. Is it a bug?
>
> No, the code is correct. I don`t know why in your case you get such an
> exception as it works fine with my D7.
> The Python function PyArg_ParseTuple will return an integer telling you if
> it could parse or not the parameters.
> If yes then you have to provide a valid Python object as a result (such as
> Py_None which by the way must be incremented before returning it!!!!!!
> That`s why you should write something like Result := ReturnNone; which will
> do it for you).
> If it could not parse the parameters, it will create its own error message
> and in that case you MUST return nil.
>
>> I have another question. After "Add" function in this unit, it must use
>> "far"
>> and "cdecl".
> I think that "Far" is obsolete now.
> But "cdecl" is a must as Python APIs are coded in the C language.
>
> Bye,
>
> Morgan
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Mon May 22, 2006 7:57 am


Joined: 29 Apr 2005

Posts: 103
bug in demo9?
> in fact, I write some demo for p4d which will be post in py4d wiki.
> First of these is to create a new modal for python extention which
> return None. After looking demo9, I think simply that return nil is
> ok, but I`m wrong. Return value must be python type value in any
case,
> but nil is not a python type value.

I have to see your code before continuing this discussion as I don`t
understand what you`re trying to do!
Returning nil is perfectly Ok when PyErr_Occurred returns a non nil
value, which will be the case when PyArge_ParseTuple fails.
Of course, when no error has been set (with PyErr_SetString for
instance), then you CAN`T return nil!
Demo9 has been there for a lot of years and was never reported as
buggy.

Bye,

Morgan
Reply with quote
Send private message
View user's profile Post To page top
tocer_deng Posted: Mon May 22, 2006 7:29 pm


Joined: 17 May 2006

Posts: 32
bug in demo9?
Hi Morgan:

I understand your typing. my case is very simple:

function hello: PPyObject; cdecl;
begin
with GetPythonEngine do begin
Writeln(`hello world`);
Result := Py_None;
end;
end;

no error has been set, I only want to expose delphi function to python:)

Now, I think we could stop the discuss :)

thank your paticular reply !

--tocer

Morgan Martinet wrote::
>> in fact, I write some demo for p4d which will be post in py4d wiki.
>> First of these is to create a new modal for python extention which
>> return None. After looking demo9, I think simply that return nil is
>> ok, but I`m wrong. Return value must be python type value in any case,
>> but nil is not a python type value.
>
> I have to see your code before continuing this discussion as I don`t
> understand what you`re trying to do!
> Returning nil is perfectly Ok when PyErr_Occurred returns a non nil
> value, which will be the case when PyArge_ParseTuple fails.
> Of course, when no error has been set (with PyErr_SetString for
> instance), then you CAN`T return nil!
> Demo9 has been there for a lot of years and was never reported as
> buggy.
>
> Bye,
>
> Morgan
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Mon May 22, 2006 7:56 pm


Joined: 29 Apr 2005

Posts: 103
bug in demo9?
--- In pythonfordelphi@yahoogroups.com, tocer <tocer.deng@...> wrote:
>
> Hi Morgan:
>
> I understand your typing. my case is very simple:
>
> function hello: PPyObject; cdecl;
> begin
> with GetPythonEngine do begin
> Writeln(`hello world`);
> Result := Py_None;
> end;
> end;
>
> no error has been set, I only want to expose delphi function to
python:)
>
> Now, I think we could stop the discuss :)
>
> thank your paticular reply !
Ok, this is simple, but wrong! As I already said, you make always
take reference counting into account when dealing with Python
object, and thus you must inc ref Py_Result or it will crash Python
if you invoke your method several times.

So, this should be:

function hello: PPyObject; cdecl;
begin
with GetPythonEngine do begin
Writeln(`hello world`);
Result := ReturnNone;
{ or Result := Py_None;
Py_IncRef(Result); }
end;
end;

Bye,

Morgan
Reply with quote
Send private message
View user's profile Post To page top
tocer_deng Posted: Mon May 22, 2006 8:19 pm


Joined: 17 May 2006

Posts: 32
bug in demo9?
oops,it is not simple :( I have to study hard.

but thanks.

--tocer

Morgan Martinet wrote::
> --- In pythonfordelphi@yahoogroups.com, tocer <tocer.deng@...> wrote:
>> Hi Morgan:
>>
>> I understand your typing. my case is very simple:
>>
>> function hello: PPyObject; cdecl;
>> begin
>> with GetPythonEngine do begin
>> Writeln(`hello world`);
>> Result := Py_None;
>> end;
>> end;
>>
>> no error has been set, I only want to expose delphi function to
> python:)
>> Now, I think we could stop the discuss :)
>>
>> thank your paticular reply !
> Ok, this is simple, but wrong! As I already said, you make always
> take reference counting into account when dealing with Python
> object, and thus you must inc ref Py_Result or it will crash Python
> if you invoke your method several times.
>
> So, this should be:
>
> function hello: PPyObject; cdecl;
> begin
> with GetPythonEngine do begin
> Writeln(`hello world`);
> Result := ReturnNone;
> { or Result := Py_None;
> Py_IncRef(Result); }
> end;
> end;
>
> Bye,
>
> Morgan
>
>
>
>
>
>
>
> To Post a message, send it to: pythonfordelphi@eGroups.com
>
> To Unsubscribe, send a blank message to:
pythonfordelphi-unsubscribe@eGroups.com
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Mon May 22, 2006 9:07 pm


Joined: 29 Apr 2005

Posts: 103
bug in demo9?
In fact, you can read Python material first as any Python rules applies to
P4D too!
In the Python documentation, there is a section on embedding Python into an
application...

> -----Original Message-----
> From: pythonfordelphi@yahoogroups.com
> [mailto:pythonfordelphi@yahoogroups.com] On Behalf Of tocer
> Sent: Monday, May 22, 2006 11:19 AM
> To: pythonfordelphi@yahoogroups.com
> Subject: Re: [pythonfordelphi] Re: bug in demo9?
>
> oops,it is not simple :( I have to study hard.
>
> but thanks.
>
> --tocer
>
> Morgan Martinet wrote::
> > --- In pythonfordelphi@yahoogroups.com, tocer <tocer.deng@...> wrote:
> >> Hi Morgan:
> >>
> >> I understand your typing. my case is very simple:
> >>
> >> function hello: PPyObject; cdecl;
> >> begin
> >> with GetPythonEngine do begin
> >> Writeln(`hello world`);
> >> Result := Py_None;
> >> end;
> >> end;
> >>
> >> no error has been set, I only want to expose delphi function to
> > python:)
> >> Now, I think we could stop the discuss :)
> >>
> >> thank your paticular reply !
> > Ok, this is simple, but wrong! As I already said, you make always
> > take reference counting into account when dealing with Python
> > object, and thus you must inc ref Py_Result or it will crash Python
> > if you invoke your method several times.
> >
> > So, this should be:
> >
> > function hello: PPyObject; cdecl;
> > begin
> > with GetPythonEngine do begin
> > Writeln(`hello world`);
> > Result := ReturnNone;
> > { or Result := Py_None;
> > Py_IncRef(Result); }
> > end;
> > end;
> >
> > Bye,
> >
> > Morgan
> >
> >
> >
> >
> >
> >
> >
> > To Post a message, send it to: pythonfordelphi@eGroups.com
> >
> > To Unsubscribe, send a blank message to: pythonfordelphi-
> unsubscribe@eGroups.com
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>
>
>
>
> To Post a message, send it to: pythonfordelphi@eGroups.com
>
> To Unsubscribe, send a blank message to: pythonfordelphi-
> unsubscribe@eGroups.com
> Yahoo! Groups Links
>
>
>
>
Reply with quote
Send private message
View user's profile Post To page top
tocer_deng Posted: Mon May 22, 2006 9:13 pm


Joined: 17 May 2006

Posts: 32
bug in demo9?
ok,I`ll try it.
thanks

--tocer

Morgan Martinet wrote::
> In fact, you can read Python material first as any Python rules applies to
> P4D too!
> In the Python documentation, there is a section on embedding Python into an
> application...
>
>> -----Original Message-----
>> From: pythonfordelphi@yahoogroups.com
>> [mailto:pythonfordelphi@yahoogroups.com] On Behalf Of tocer
>> Sent: Monday, May 22, 2006 11:19 AM
>> To: pythonfordelphi@yahoogroups.com
>> Subject: Re: [pythonfordelphi] Re: bug in demo9?
>>
>> oops,it is not simple :( I have to study hard.
>>
>> but thanks.
>>
>> --tocer
>>
>> Morgan Martinet wrote::
>>> --- In pythonfordelphi@yahoogroups.com, tocer <tocer.deng@...> wrote:
>>>> Hi Morgan:
>>>>
>>>> I understand your typing. my case is very simple:
>>>>
>>>> function hello: PPyObject; cdecl;
>>>> begin
>>>> with GetPythonEngine do begin
>>>> Writeln(`hello world`);
>>>> Result := Py_None;
>>>> end;
>>>> end;
>>>>
>>>> no error has been set, I only want to expose delphi function to
>>> python:)
>>>> Now, I think we could stop the discuss :)
>>>>
>>>> thank your paticular reply !
>>> Ok, this is simple, but wrong! As I already said, you make always
>>> take reference counting into account when dealing with Python
>>> object, and thus you must inc ref Py_Result or it will crash Python
>>> if you invoke your method several times.
>>>
>>> So, this should be:
>>>
>>> function hello: PPyObject; cdecl;
>>> begin
>>> with GetPythonEngine do begin
>>> Writeln(`hello world`);
>>> Result := ReturnNone;
>>> { or Result := Py_None;
>>> Py_IncRef(Result); }
>>> end;
>>> end;
>>>
>>> Bye,
>>>
>>> Morgan
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> To Post a message, send it to: pythonfordelphi@eGroups.com
>>>
>>> To Unsubscribe, send a blank message to: pythonfordelphi-
>> unsubscribe@eGroups.com
>>> Yahoo! Groups Links
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>>
>> To Post a message, send it to: pythonfordelphi@eGroups.com
>>
>> To Unsubscribe, send a blank message to: pythonfordelphi-
>> unsubscribe@eGroups.com
>> Yahoo! Groups Links
>>
>>
>>
>>
>
>
>
>
>
> To Post a message, send it to: pythonfordelphi@eGroups.com
>
> To Unsubscribe, send a blank message to:
pythonfordelphi-unsubscribe@eGroups.com
> Yahoo! Groups Links
>
>
>
>
>
>
>
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help