 |
forum.vmspython.org Forum system
|
View previous topic :: View next topic |
Author |
Message |
dlaroche-ca
Joined: 03 Jul 2013 Posts: 32 Location: Montréal, Québec, Canada
|
Posted: Thu Mar 19, 2015 3:01 pm Post subject: building an extension module |
|
|
I'm trying to build an extension module following the instructions in document "Extending and embedding Python" in the Python documentation set. I used the example in the document, the spam module. I put files spammodule.c and setup.py in a directory and then invoked
Code: | python setup.py build |
There is a C compiler on the VMS system where I work:
Code: | MANGA: cc/version
HP C V7.2-022 on OpenVMS IA64 V8.3
|
Unfortunately the build doesn't work. Here's the ouput of the setup script:
Code: | MANGA: python setup.py build
running build
running build_ext
building 'spam' extension
creating build
creating build/temp.openvms-0-HP_rx2620__(1.60GHz-3.0MB)-2.7
mc cc -I/python_root/include/python2.7 -c spammodule.c /object= build/temp.openvms-0-HP_rx2620__(1.60GHz-3.0MB)-2.7/spammodule.obj
%DCL-W-ACTIMAGE, error activating image cc
-CLI-E-IMAGEFNF, image file not found MANGA$DKA0:[SYS0.SYSCOMMON.][SYSEXE]CC.EXE;
Traceback (most recent call last):
File "setup.py", line 8, in <module>
ext_modules = [module1])
File "/python_root/lib/distutils/core.py", line 151, in setup
dist.run_commands()
File "/python_root/lib/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
## many entries in the stack trace deleted...
File "/python_root/lib/distutils/spawn.py", line 138, in _spawn_vms
if rc[2] & 1 == 0:
IndexError: tuple index out of range
|
Essentially the problem is that setup can't find the C compiler. I checked the keywords that can be passed to setup but I didn't find any to tell it where to find the C compiler.
Would someone have a suggestion?
Thanks. |
|
Back to top |
|
 |
dlaroche-ca
Joined: 03 Jul 2013 Posts: 32 Location: Montréal, Québec, Canada
|
Posted: Thu Mar 19, 2015 5:55 pm Post subject: |
|
|
I found a previous post that discusses the subject. I tried script python_vms:build_module.py. The module now builds, but I can't import it. Here's how I structured the module:
Code: | |
|--- spam
|
|--- __init__.py
|--- _spam.exe
|
__init__.py contains this
Code: | from _spam import *
__version__ = '0.1'
|
Now when I try to import it:
Code: | MANGA: python
Python 2.7.8 (default, Sep 9 2014, 11:50:54) [DECC] on OpenVMS
Type "help", "copyright", "credits" or "license" for more information.
>>> import spam
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "spam/__init__.py", line 1, in <module>
from _spam import *
ImportError: dynamic module does not define init function (init_spam)
|
Finally, here's the source code of the module:
Code: | #include <Python.h>
static PyObject* spam_system (PyObject *self, PyObject *args);
static PyMethodDef SpamMethods[] = {
{"system", spam_system, METH_VARARGS,
"Execute a shell command."},
{NULL, NULL, 0, NULL}
};
static PyObject*
spam_system (PyObject *self, PyObject *args)
{
const char *command;
int sts;
if (!PyArg_ParseTuple (args, "s", command))
return NULL;
sts = system (command);
return Py_BuildValue ("i", sts);
}
PyMODINIT_FUNC
init_spam (void)
{
Py_InitModule ("_spam", SpamMethods);
}
|
I can't see why the init function is not found.
Thanks again. |
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 636
|
Posted: Fri Mar 20, 2015 9:01 am Post subject: |
|
|
Hello,
When you invoke the script script python_vms:build_module.py you need
to pass the correct case argument. You can try to be sure to use something like this:
Code: | $ python /python_vms/build_cython_module.py "_spam" |
JF |
|
Back to top |
|
 |
dlaroche-ca
Joined: 03 Jul 2013 Posts: 32 Location: Montréal, Québec, Canada
|
Posted: Fri Mar 20, 2015 3:50 pm Post subject: |
|
|
Thanks for the reply. Unfortunately I'm still getting the same error. Here's the output of the build (I activated tracing with set verify):
Code: | MANGA: python /PYTHON_vms/build_module.py "_spam"
@tmp:tmpCojJhw.com
$ @python_vms:python_compiler_options
$ define /noLog python_use_ieee_float true
$!!! define /noLog 'p1'python_use_tcpip_v6 true
$
$ define /noLog python_c_names "/names=(as_is,shortened)/accept=novaxc_keywords"
$! /MAIN=POSIX_EXIT here just for convenience
$ define /noLog python_c_debug "/nodebug/MAIN=POSIX_EXIT"
$ arch_name = f$getsyi("arch_name")
$ if arch_name .eqs. "IA64"
$ then
$ define /noLog python_c_optim "/optimize=(level=5,tune=itanium2)/architecture=itanium2"
$ else
$ endif
$
$ ieeefloat = f$trnlnm("python_use_ieee_float")
$ if ieeefloat .eqs. ""
$ else
$ define /noLog python_c_float "/float=ieee/IEEE_MODE=DENORM_RESULTS"
$ endif
$
$ tcpipv6 = f$trnlnm("python_use_tcpip_v6")
$ if tcpipv6 .nes. ""
$ else
$ if f$trnlnm("DECC$SYSTEM_INCLUDE") .nes. "" then -
deassign decc$system_include
$ if f$trnlnm("ARPA") .nes. "" then -
deassign ARPA
$ if f$trnlnm("NET") .nes. "" then -
deassign NET
$ if f$trnlnm("NETINET") .nes. "" then -
deassign NETINET
$ if f$trnlnm("SYS") .nes. "" then -
deassign SYS
$ endif
$ PYTHON_C_DEBUG = f$trnlnm("PYTHON_C_DEBUG")
$ PYTHON_C_FLOAT = f$trnlnm("PYTHON_C_FLOAT")
$ PYTHON_C_NAMES = f$trnlnm("PYTHON_C_NAMES")
$ PYTHON_C_OPTIM = f$trnlnm("PYTHON_C_OPTIM")
$ cc /nodebug/MAIN=POSIX_EXIT /float=ieee/IEEE_MODE=DENORM_RESULTS /names=(as_is,shortened)/accept=novaxc_keywords /optimize=(lev
el=5,tune=itanium2)/architecture=itanium2 -
/include=(python_include)/define=(_USE_STD_STAT=1,__USE_INO64=1,-
_LARGEFILE,__NEW_STARLET,_POSIX_EXIT=1) _spam.c
$ link/share=_spam.exe sys$input:/opt
GSMATCH=lequal,1,1000
case_sensitive=YES
SYMBOL_VECTOR = (init_spam=PROCEDURE)
SYMBOL_VECTOR = (INIT_SPAM/init_spam=PROCEDURE)
case_sensitive=NO
_spam.obj
pythonshr/share
%ILINK-W-NUDFSYMS, 1 undefined symbol:
%ILINK-I-UDFSYM, vms_system
%ILINK-W-USEUNDEF, undefined symbol vms_system referenced
section: $CODE$
offset: %X0000000000000050 slot: 2
module: _spam
file: TFC$USER:[EX36672.TMP.spam]_spam.OBJ;2
$
$ delete tmp:tmpCojJhw.com;*
|
|
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 636
|
Posted: Wed Mar 25, 2015 8:50 am Post subject: |
|
|
So, the problem is that the _spam module call an unknown function "vms_system".
I can take a look if you give me a pointer on the source of _spam.c
JF |
|
Back to top |
|
 |
dlaroche-ca
Joined: 03 Jul 2013 Posts: 32 Location: Montréal, Québec, Canada
|
Posted: Wed Mar 25, 2015 10:32 pm Post subject: |
|
|
The code of the module is in the second post. Thanks. |
|
Back to top |
|
 |
jfp
Joined: 12 Jul 2004 Posts: 636
|
Posted: Thu Mar 26, 2015 9:59 am Post subject: |
|
|
forgotten that the source was already included.
I have found the problem, if you take a look at python_include:pyconfig.h
You will noticed that the function exit, system and wait are redefined but only vms_exit is exported in the shareable pythonshr.
I will fix this a forthcoming kit.
Thank for reporting.
JF |
|
Back to top |
|
 |
|
|
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
|