473,398 Members | 2,343 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,398 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 6044
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.