forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PyExc_VMSError

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
dlaroche-ca



Joined: 03 Jul 2013
Posts: 32
Location: Montréal, Québec, Canada

PostPosted: Thu May 21, 2015 12:47 pm    Post subject: PyExc_VMSError Reply with quote

Would it be possible to post an example of raising a PyExc_VMSError exception from a C module?

Thanks in advance.
Back to top
View user's profile Send private message Send e-mail
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Fri May 22, 2015 6:54 am    Post subject: Reply with quote

There is nothing special with PyExc_VMSError.
You can raise it like any other exception.

For example take a look at 1.2 in
https://docs.python.org/2/extending/extending.html

If you want to build a new module I suggest to use Cython instead of C.

JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dlaroche-ca



Joined: 03 Jul 2013
Posts: 32
Location: Montréal, Québec, Canada

PostPosted: Fri May 22, 2015 11:33 am    Post subject: Reply with quote

What I wasn't sure is how to pass to two values, the errno and the message. I found an example in the Python source code (Modules/posixmodule.c):
Code:
v = Py_BuildValue("(is)", code, text);
PyErr_SetObject(PyExc_OSError, v);

Is the learning curve to learn Cython significant?

Thanks for the reply.
Back to top
View user's profile Send private message Send e-mail
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Fri May 22, 2015 11:40 am    Post subject: Reply with quote

According to https://docs.python.org/2/c-api/exceptions.html you can also use PyErr_SetFromErrno:
Quote:
This is a convenience function to raise an exception when a C library function has returned an error and set the C variable errno. It constructs a tuple object whose first item is the integer errno value and whose second item is the corresponding error message (gotten from strerror()), and then calls PyErr_SetObject(type, object).


Cython allow to mixed C and Python in the same source file. So if you know Python and C the learning curve is probably not very significant.

JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dlaroche-ca



Joined: 03 Jul 2013
Posts: 32
Location: Montréal, Québec, Canada

PostPosted: Fri May 22, 2015 3:23 pm    Post subject: Reply with quote

I had read about PyErr_SetFromErrno, but I was wondering about the value of errno. When a VMS system call fails, does it set the value of errno to the status value of the system call?

About Cython, how would you build a Cython module on VMS?

Thanks again.
Back to top
View user's profile Send private message Send e-mail
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Fri May 22, 2015 3:47 pm    Post subject: Reply with quote

I would start with:
Code:

$ show sym cython
  CYTHON == "$ PYTHON_ROOT:[VMS.BIN]PYTHON PYTHON_ROOT:[BIN]CYTHON."

$ cython
Cython (http://cython.org) is a compiler for code written in the
Cython language.  Cython is based on Pyrex by Greg Ewing.

Usage: cython [options] sourcefile.{pyx,py} ...

Options:
...
...
...

I have done nothing apart from the standard install of the LD files.
Back to top
View user's profile Send private message
dlaroche-ca



Joined: 03 Jul 2013
Posts: 32
Location: Montréal, Québec, Canada

PostPosted: Fri May 22, 2015 4:14 pm    Post subject: Reply with quote

Great, thank you.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group