473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing a packed C structure to a c module

Hi,

Is it possible to define a packed C structure in python and pass it to the c
module, or should the wrapper do that ?

Regards,

Philippe

Apr 14 '06 #1
8 1964
Philippe Martin wrote:
Is it possible to define a packed C structure in python and pass it to the c
module, or should the wrapper do that ?


You can create a packed structure using string concatenation, and with
the help of the struct module. However, this gives you a string object
in the end, which you still need to pass into your C library.

It is better to fill the struct in the wrapper.

Regards,
Martin
Apr 14 '06 #2
Thanks,

It's a pretty big structure: painfull to pass each item as a param.

Regards,

Philippe
"Martin v. Löwis" wrote:
Philippe Martin wrote:
Is it possible to define a packed C structure in python and pass it to
the c module, or should the wrapper do that ?


You can create a packed structure using string concatenation, and with
the help of the struct module. However, this gives you a string object
in the end, which you still need to pass into your C library.

It is better to fill the struct in the wrapper.

Regards,
Martin


Apr 14 '06 #3
Philippe Martin wrote:
It's a pretty big structure: painfull to pass each item as a param.


So how else would you like to pass them? Define the API you want,
and then just implement it. It still shouldn't require to define
the layout in Python.

Regards,
Martin
Apr 14 '06 #4
Well,

The call actually is an IOCtl: depending on the control code, the structure
has a different format.

Although the number of control codes/structures is finite, it would make the
wrapper function fairly large.

You seem to think that building the structure from python would be a
mistake: why is that ?

PS: the wrapper also has to work under multiple OSs

Regards,

Philippe

"Martin v. Löwis" wrote:
Philippe Martin wrote:
It's a pretty big structure: painfull to pass each item as a param.


So how else would you like to pass them? Define the API you want,
and then just implement it. It still shouldn't require to define
the layout in Python.

Regards,
Martin


Apr 14 '06 #5

On Apr 14, 2006, at 9:44 AM, Philippe Martin wrote:
Thanks,

It's a pretty big structure: painfull to pass each item as a param.

Regards,

Philippe


Maybe this can do something for you?

http://pyconstruct.sourceforge.net/
Jay P.

Apr 14 '06 #6
Philippe Martin wrote:
The call actually is an IOCtl: depending on the control code, the structure
has a different format.
Ah. In that case, I recommend to use the ioctl module; you won't need a
C wrapper, then.
Although the number of control codes/structures is finite, it would make the
wrapper function fairly large.
*Some* code to handle this will be very large, regardless of how you
write it.
You seem to think that building the structure from python would be a
mistake: why is that ?
It's very error-prone. You have to match the C structure layout of the
compiler precisely, and you even have to get the alignment right,
something that can't be done reliably in Python.
PS: the wrapper also has to work under multiple OSs


That makes it worse: now you not only have to match the C compiler's
expectation on a single processor, but on different ones.

Perhaps you should be using ctypes.

Regards,
Martin
Apr 14 '06 #7
I misslead you: it is a smart card-style ioctl ...

Philippe

"Martin v. Löwis" wrote:
Philippe Martin wrote:
The call actually is an IOCtl: depending on the control code, the
structure has a different format.


Ah. In that case, I recommend to use the ioctl module; you won't need a
C wrapper, then.
Although the number of control codes/structures is finite, it would make
the wrapper function fairly large.


*Some* code to handle this will be very large, regardless of how you
write it.
You seem to think that building the structure from python would be a
mistake: why is that ?


It's very error-prone. You have to match the C structure layout of the
compiler precisely, and you even have to get the alignment right,
something that can't be done reliably in Python.
PS: the wrapper also has to work under multiple OSs


That makes it worse: now you not only have to match the C compiler's
expectation on a single processor, but on different ones.

Perhaps you should be using ctypes.

Regards,
Martin


Apr 14 '06 #8
I'll take a look,

thanks.

Jay Parlar wrote:

On Apr 14, 2006, at 9:44 AM, Philippe Martin wrote:
Thanks,

It's a pretty big structure: painfull to pass each item as a param.

Regards,

Philippe


Maybe this can do something for you?

http://pyconstruct.sourceforge.net/
Jay P.


Apr 14 '06 #9

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

Similar topics

8
1789
by: Bryan G | last post by:
Hi, I'm working on a VB project which involves using C library functions which take struct pointers as args, and I keep running into this error when trying to pass either an IntPtr or a Structure ByRef to the functions. An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveExcept ion' occurred in ConsoleApplication1.exe Additional information: PInvoke restriction: can not
3
1761
by: Steve | last post by:
Hello, I created a public Structure in a Standard Module and also an array of Structures. Then I load data into the array of structures in a public sub that I call on the Form load event. Next I have a class, and I want to pass a structure member from my array of Structures to the class constructor. In the form I instantiate a class object. Module1
4
4048
by: Dave Cullen | last post by:
I want to call a function using my own data type as an argument. The declaration for my function looks like this: Public Function CreateCardInfo(ByVal data As WoData) VB.NET balks at this, saying: 'data' cannot expose a Friend type outside of the Public class 'frmMain'.
3
12143
by: parag.kanade | last post by:
I have a packet structure which has a field of Integer arrays, that is packed struct { int a; char b; int count; }foo; I need to initialize all the entries of count to a particular value,
15
23976
by: Daniel Rudy | last post by:
What is the difference between packed and unpacked structs? -- Daniel Rudy Email address has been base64 encoded to reduce spam Decode email address using b64decode or uudecode -m Why geeks like computers: look chat date touch grep make unzip
1
1774
by: sharadvasista | last post by:
I have a structure typedef struct t_abcd { int a; int b; int c; } abcd; I have to pass the structure to another function. I can do this in two ways.
9
17626
by: Sikandar | last post by:
Hi, I am beginner in C. Pls let me know what is packed array in C. Where is it used? Thanks, Sikandar
4
1940
by: Kris Kennaway | last post by:
I want to make use of UNIX credential passing on a local domain socket to verify the identity of a user connecting to a privileged service. However it looks like the socket module doesn't implement sendmsg/recvmsg wrappers, and I can't find another module that does this either. Is there something I have missed? Kris
7
6875
by: Travis | last post by:
Hi all - Most of my experience in c++ has been upper level. I am just now getting into lower level stuff and I see this alot class foo { .... } __attribute__((aligned(1), packed)); I am having trouble finding any documentation online that explains
0
9281
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...
1
9200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
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
8148
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
6722
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
4525
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.