472,952 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

ctypes - pointer to array of structs?


(Is this the right place to ask ctypes questions? There's a mailing list
but the last post to it seems to have been in November 2006.)

Using ctypes I reference a structure which contains a pointer to an array of
another structure:

class SYMBOL(Structure):
_fields_ = [("symbol", c_char_p),
("num", c_int),
("units", c_int),
("baseprice", c_int),
("active", c_int)]
SYMBOL_PTR = POINTER(SYMBOL)

class TABLE(Structure):
_fields_ = [("map", SYMBOL_PTR),
("nsymbols", c_uint),
...]

Effectively, TABLE.map is an array of TABLE.nsymbols SYMBOLS. How to I
reference elements in that array? In C I would just treat TABLE.map like an
array and index into it (for i=0; i< TABLE.nsymbols; i++) ...). This is
data returned from a C library, not something I'm building in Python to pass
into C.

Thx,

Skip
Jan 3 '08 #1
2 6024
sk**@pobox.com schrieb:
(Is this the right place to ask ctypes questions? There's a mailing list
but the last post to it seems to have been in November 2006.)
No, it's active.
Using ctypes I reference a structure which contains a pointer to an array of
another structure:

class SYMBOL(Structure):
_fields_ = [("symbol", c_char_p),
("num", c_int),
("units", c_int),
("baseprice", c_int),
("active", c_int)]
SYMBOL_PTR = POINTER(SYMBOL)

class TABLE(Structure):
_fields_ = [("map", SYMBOL_PTR),
("nsymbols", c_uint),
...]

Effectively, TABLE.map is an array of TABLE.nsymbols SYMBOLS. How to I
reference elements in that array? In C I would just treat TABLE.map like an
array and index into it (for i=0; i< TABLE.nsymbols; i++) ...). This is
data returned from a C library, not something I'm building in Python to pass
into C.
I think you should be able to create an array-type with the required
number of entries, and cast map to that. Along these lines (untested)

ap = POINTER(SYMBOL(table.nsymbols))

map = cast(table.map, ap)

Diez
Jan 3 '08 #2
(Is this the right place to ask ctypes questions? There's a mailing list
but the last post to it seems to have been in November 2006.)

No, it's active.
Thanks. I guess the official ASPN-based archive must be dead.

I managed to sort of get access to the array just using indexing
as I would in C, but I'm having some problems referencing
elements of the SYMBOL struct. I'll keep plugging away.

Skip

Jan 4 '08 #3

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

Similar topics

1
by: Thomas Heller | last post by:
ctypes 0.9.1 released - Sept 14, 2004 ===================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call...
10
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr;...
1
by: mrhicks | last post by:
Hello all, I need some advice/help on a particular problem I am having. I have a basic struct called "indv_rpt_rply" that holds information for a particular device in our system which I will...
15
by: Paminu | last post by:
Still having a few problems with malloc and pointers. I have made a struct. Now I would like to make a pointer an array with 4 pointers to this struct. #include <stdlib.h> #include <stdio.h>...
0
by: chris.atlee | last post by:
Hello, I've been trying to write a PAM module using ctypes. In the conversation function (my_conv in the script below), you're passed in a pam_response** pointer. You're supposed to allocate...
3
by: Chris AtLee | last post by:
Sorry for the repeat post...I'm not sure if my first post (on May 30th) went through or not. I've been trying to write a PAM module using ctypes. In the conversation function (my_conv in the...
14
by: Szabolcs Borsanyi | last post by:
Deal all, The type typedef double ***tmp_tensor3; is meant to represent a three-dimensional array. For some reasons the standard array-of-array-of-array will not work in my case. Can I...
3
by: Andrew Lentvorski | last post by:
Basically, I'd like to use the ctypes module as a much more descriptive "struct" module. Is there a way to take a ctypes.Structure-based class and convert it to/from a binary string? Thanks,...
2
by: overdrigzed | last post by:
Hello! I wanted to get the full contents of a character array stored in a struct, i.e. _fields_ = however, ctypes seems to try to return struct.array as a Python string rather than a...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

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.