1

I'm trying to model a struct found in a library I'm wrapping, where the struct has a pointer-to-a-pointer like this:

typedef struct item_t {
  char* name;
}

typedef struct container_t {
  item_t **items;
}

How, when modeling with Python's ctypes module's Structure class, would I represent an array of pointers with a variable length?

1 Answer 1

1

You can use POINTER and convert item_t ** to POINTER(POINTER(item_t)):

from ctypes import *

class item_t(Structure):
    _fields_ = [
        ('name', c_char_p),
    ]


class container_t(Structure):
    _fields_ = [
        ('items', POINTER(POINTER(item_t))),
    ]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.