473,769 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(P yObject *, PyObject *args) {
int result;
char *input = 0;
char *d = 0;
int ok = PyArg_ParseTupl e(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 2672
> PyObject *wrap_doStuff(P yObject *, 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(P yObject *, PyObject *args) {
PyObject *wrap_doStuff(P yObject *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(P yObject *self, PyObject *args) {
int result;
char *input = 0;
char *d = 0;
int ok = PyArg_ParseTupl e(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_VERS ION
);

}

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(P yObject *, 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("DLLT ester", ["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
4101
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 the built in operators: class Foo(object): class __metaclass__(type): def __getattribute__(self, name): print "Klass", name
4
2881
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 function to append a list to another. Using a wrapper class I could do something like:
14
2739
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= 0; char *aString = 0; char *bString = 0; MY_NUM *a;
4
1971
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 complete and the first letter is shown after 1 second.
23
1657
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; /* stuff happens to arg1, arg2, and crnt_pos */
3
3557
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 it into my own user defined structures. Since the process of opening and retrieving data from the database is exactly the same for all struct types, and the only part that's different is how the data is copied into the diff structs, I was...
9
2340
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 is just a vendor function for doing forward FFT's. At issue CSL_COMPLEX is 'cumbersome' to work with. As a result I created a wrapper. So now - given the pseudo code. #include <iostream> #include <complex> #include <vector>
1
2009
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 developer will pass a delegate to the Managed C++ wrapper and in this wrapper, we have to cast the delegate into function pointer. The argument list of that function pointer is not compatible in .NET. A .NET developer will pass a delegate to get the...
5
2138
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 (forwarded through my class object to the real function). I've looked around for sources on how to do this but I can't find anything. How do you do this? I would also appreciate any references to good sources about this topic if you have any. ...
3
4686
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 that it RETURNS the 'to' string which in turn helps me fill out a query in the following manner using sprintf: unescaped_query = "INSERT into MYTABLE values ('%s', '%s')"; sprintf(escaped_query, unescaped_query, wrapper(<string argument no.1...
0
9420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.