473,386 Members | 1,821 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,386 software developers and data experts.

[Q]An error with my module in C

hello,all.

I wrote a module in C as below, BUT msg() method cannot work
allright.

#include <stdio.h>
#include <python2.4/Python.h>

static PyObject *Roka_msg(PyObject *self,PyObject *args)
{
printf("Roka Python lib. Version 1.0\n");
}

static PyObject *Roka_func(PyObject *self,PyObject *args)
{
long arg;
if(!PyArg_ParseTuple(args,"l",&arg)){
return NULL;
}
return Py_BuildValue("l",arg*2);
}

//----------------------------------------------------------

static struct PyMethodDef functions[]=
{
{"msg",Roka_msg,METH_VARARGS},
{"func",Roka_func,METH_VARARGS},
{NULL,NULL,0},
};
void initRoka(void)
{
(void)Py_InitModule("Roka",functions);
}
-------------------------------------------------------------------------
python result:
>>>import Roka
Roka.msg()
Roka Python lib. Version 1.0
Segmentation fault

I throw out a Segmentation fault after display my message.
Can anyone tell me why?

thanks.

Oct 3 '06 #1
1 948
Jia,Lu wrote:
hello,all.

I wrote a module in C as below, BUT msg() method cannot work
allright.

#include <stdio.h>
#include <python2.4/Python.h>
This isn't related to your error, but you should include Python.h before other
headers, and it should be just this:

#include "Python.h"

distutils will make sure the include path is correct.
static PyObject *Roka_msg(PyObject *self,PyObject *args)
{
printf("Roka Python lib. Version 1.0\n");
}
You actually need to return a PyObject* here. Specifically, you want to return
None after incrementing its reference count:

Py_INCREF(Py_None);
return Py_None;

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 3 '06 #2

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

Similar topics

3
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how...
1
by: flupke | last post by:
Hi, i am in search of a cddb module for Python on windows. I stumbled upon http://sourceforge.net/projects/cddb-py but couldn't use it since the mci.dll is compiled against Python2.0. So i'm...
42
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
7
by: Spacen Jasset | last post by:
The main two desirable things I feel error handling should provide are these: 1) Debugging and diagnostic aid 2) User feedback One method that is used a fair amount it to 'say' that all...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
2
by: GrandpaB | last post by:
When I attempt to run the following code I get the following error: An unhandled exception of type 'System.NullReferenceException' occurred in Art.exe Additional information: Object reference...
12
by: TristaSD | last post by:
Hi, Here's a nice footer I get inside every php page I write in wwwroot on my server. The code gets parsed just fine. I installed php5.2-win32 under W2K Server, IIS 5.0. I've installed php on...
4
by: rlntemp-gng | last post by:
I am trying to dynamically populate the module name in the error message. Currently I populate a variable with hardcoded text: strModuleName = "cmdFlushWorkTables_Click" Per my code below, is...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.