473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

help with extending python

Hello,

I'd appreciate some help figuring out what I might be doing wrong. I am
trying to extend Python to add some modules. However, when the code
appended below runs, the conversion always fails (returns -1), and I
get a TypeError

Thanks
Siddharth
So the usage is like this:
import PyTest_itsFsm
a = [(10,True)]
PyTest_itsFsm.pytestprimitive(a)
the int is -1
bool is -1
in primitive test op with arg1 -1and arg 2183
1 TypeError: an integer is required


The PyMethodDef looks as below:
------------------------------
static PyMethodDef PyTest_itsFsmMethods[] = {
{"pytestprimitive", PyTest_itsFsm_pytestprimitive,
METH_VARARGS, "pytestprimitive"},
{NULL,NULL,0,NULL}
};

And the method I've added looks like this:
------------------------------------------
static PyObject * PyTest_itsFsm_pytestprimitive(PyObject * self,
PyObject *args) { int arg1;
if
(!PyArg_ParseTuple(args,"O&",convert_pytestprimiti ve_arg1,&arg1))
{
return NULL;
}
bool arg2;
if
(!PyArg_ParseTuple(args,"O&",convert_pytestprimiti ve_arg2,&arg2))
{
return NULL;
}
Finally, the convert functions:
---------------------------------

PyTest_itsFsm::pytestpint convert_pytestprimitive_arg1 (PyObject * ob,
void * addr )
{
// this routine should convert the PyObject * to int for argument
arg1 int * p = (int *) addr;
printf ("ready to parse in convert function\n");

*p = PyInt_AsLong (ob);
printf ("the int is %d\n",*p);
if (PyErr_Occurred())
return -1;

return 1;
}
int convert_pytestprimitive_arg2 (PyObject * ob, void * addr )
{
// this routine should convert the PyObject * to bool for argument
arg2 bool * b = (bool *) addr;

int x;
x = PyInt_AsLong (ob);
printf ("bool is %d\n", (int) x);
if (PyErr_Occurred() )
return -1;
*b = (bool )PyBool_FromLong (x);
return 1;
}

Jul 19 '05 #1
0 1226

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eli Daniel | last post by:
Hi, I am relative new to Python. Please tell me if the following is possible. I have a command line shell written in C. This shell executes some commands which I would like to import to the...
3
by: stefan | last post by:
Hi Folks, I currenty extended some of my C++ functionality to python and also embedded python to use python functionality in my C++ system (and use as well these extended functions). While...
1
by: Tommy Nordgren | last post by:
I want to write an application that embeds and extends (at least) the Python and Perl interpreters. Now i want to find as much as possible about the Python tools used for extending and embedding...
3
by: ch424 | last post by:
Hi there, I'm using Python 2.4.1 on Ubuntu Linux, and I'm having problems extending python in C: The C code is below: #include <Python.h> #include "ni488.h"
1
by: Richard Townsend | last post by:
In the "Extending and Embedding" part of the Python documentation: section 5.4 "Extending Embedded Python" - it describes how to use a Python extension module from Python that is embedded in a C...
0
by: Terry Tang | last post by:
Hi There, We are extending Python interpreter to support special functions of our tools. What we did is to compile Python's source code (which is got from the an installation on a Linux...
3
by: Redefined Horizons | last post by:
I'm trying to understand the argument flags that are used in the method table of an extension module written in C. First let me ask this question about the method table. Is it an C array named...
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
7
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.