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

Wrapper function

I am having trouble with a wrapper function...

My C code looks like
-----------------------
#include <stdlib.h>
#include <string.h>
#include "Python.h"

int doStuff(const char *input, const char *d) {...}

PyObject *wrap_doStuff(PyObject *, PyObject *args) {
int result;
char *input = 0;
char *d = 0;
int ok = PyArg_ParseTuple(args, "ss", &input, &d);
if (!ok) return 0;

result = doStuff(input, d);

return PyBuildValue("i", result);
}

....when I try to compile this I get
"error C2055: expected formal parameter list, not a type list" and it
points to line 31...which is the line "PyObject *wrap_doStuff(...)".

I am learning based on the following link:
http://wiki.cacr.caltech.edu/danse/i...iting_wrappers

any ideas? Note, if I remove the wrapper function, it compiles fine
(so its not an issue with Python.h...i don't think), also I am using
Visual C++ 6
on Win xp.

thanks.

Oct 11 '05 #1
5 2660
> PyObject *wrap_doStuff(PyObject *, PyObject *args) {
^^^^^
I guess you need a parameter name here....
Diez
Oct 11 '05 #2
Java and Swing wrote:
I am having trouble with a wrapper function...

My C code looks like
-----------------------
#include <stdlib.h>
#include <string.h>
#include "Python.h"

int doStuff(const char *input, const char *d) {...}

PyObject *wrap_doStuff(PyObject *, PyObject *args) {
PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
...when I try to compile this I get
"error C2055: expected formal parameter list, not a type list" and it
points to line 31...which is the line "PyObject *wrap_doStuff(...)".


--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Oct 11 '05 #3
Diez, yes you were right! But I have other problems now.

I now have...

#include <stdlib.h>
#include <string.h>
#include "Python.h"

int doStuff(const char *input, const char *d) {...}

static PyObject *wrap_doStuff(PyObject *self, PyObject *args) {
int result;
char *input = 0;
char *d = 0;
int ok = PyArg_ParseTuple(args, "ss", &input, &d);
if (!ok) return 0;

result = doStuff(input, d);

return PyBuildValue("i", result);
}

static PyMethodDef myMethods[] =
{
{"PyDoStuff", wrap_doStuff, METH_VARARGS, "some documentation"},
{NULL, NULL}
};

extern PyMODINIT_FUNC initMyDLL(void)
{
Py_InitModule4(
"MyDLL", myMethods, "my doStuff function", NULL,
PYTHON_API_VERSION
);

}

When I compile, I get two warnings..which are ok. Then when I build my
DLL I get..

Linking...
Creating library Release/MyDLL.lib and object Release/MyDLL.exp
test.obj : error LNK2001: unresolved external symbol _PyBuildValue
Release/MyDLL.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

MyDLL.dll - 2 error(s), 0 warning(s)

...Any ideas?

Diez B. Roggisch wrote:
PyObject *wrap_doStuff(PyObject *, PyObject *args) {

^^^^^
I guess you need a parameter name here....
Diez


Oct 11 '05 #4
Java and Swing wrote:
When I compile, I get two warnings..which are ok. Then when I build my
DLL I get..

Linking...
Creating library Release/MyDLL.lib and object Release/MyDLL.exp
test.obj : error LNK2001: unresolved external symbol _PyBuildValue
Release/MyDLL.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

MyDLL.dll - 2 error(s), 0 warning(s)

..Any ideas?


Are you using distutils to build your extension module? You should be.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Oct 11 '05 #5
So, I write the C code...as shown previously.

Then, I do something like...

c:\> python
from distutils.core import setup, Extension

setup(
name="DLLTester",
ext_modules = [Extension("DLLTester", ["test.c"])]
)

c:\> python setup.py build_ext -i

...is that it? If so, then it's ok that I get those 2 errors when
trying to build in visual c++?

thanks

Robert Kern wrote: Java and Swing wrote:
When I compile, I get two warnings..which are ok. Then when I build my
DLL I get..

Linking...
Creating library Release/MyDLL.lib and object Release/MyDLL.exp
test.obj : error LNK2001: unresolved external symbol _PyBuildValue
Release/MyDLL.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

MyDLL.dll - 2 error(s), 0 warning(s)

..Any ideas?


Are you using distutils to build your extension module? You should be.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter


Oct 11 '05 #6

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

Similar topics

12
by: Egil M?ller | last post by:
Is there any way to create transparent wrapper objects in Python? I thought implementing __getattribute__ on either the wrapper class or its metaclass would do the trick, but it does not work for...
4
by: Christian Christmann | last post by:
Hi, I need an STL list and was thinking of putting the list in wrapper class. The reason for my decision is that you can much better perform consistency checks. For instance, I need a...
14
by: Java and Swing | last post by:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in=...
4
by: peterbe | last post by:
This works exactly as you would expect:: from time import sleep def foo(on='ABC'): for e in list(on): sleep(1) yield e When I run this on the command line It takes about 3 seconds to...
23
by: I.M. !Knuth | last post by:
A while back, I was mucking around with a recursive function. For brevity's sake, I'll define it like this: int func_recurs(int arg1, int arg2, int prev_pos) { int crnt_pos = 0; int result; ...
3
by: markww | last post by:
Hi, I have a wrapper around some 3rd party database library function. The pseudo code looks like the following - it is meant to open a table in a database, extract values from a table, then copy...
9
by: ma740988 | last post by:
Assume I have a vendor file called ' vendor.h'. Within the file there's two methods memalign and cforward. It is my understanding that the memalign function is a wrapper around malloc. cforward...
1
by: DebGuria | last post by:
We are writing a wrapper in Managed C++. Wrapper is based on a C dll. That wrapper will be used from .Net based application and VB also. Our initial understanding that a .NET Application...
5
by: GCRhoads | last post by:
I have some templated functions and I want to write a call wrapper class for it. I also want to pass the function object from this class to some functions that will then call the function...
3
by: srbakshi | last post by:
Hey all, I'm stuck with the following: The mysql_real_escape_string(conn, to, from, strlen(from)) function does not return the escaped string. So how can I go about writing a wrapper for it so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.