Wrapper function

J

Java and Swing

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/index.php/Lots_more_details_on_writing_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.
 
D

Diez B. Roggisch

PyObject *wrap_doStuff(PyObject *, PyObject *args) {
^^^^^
I guess you need a parameter name here....


Diez
 
R

Robert Kern

Java said:
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
(e-mail address removed)

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

Java and Swing

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?
 
R

Robert Kern

Java said:
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
(e-mail address removed)

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

Java and Swing

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top