title: Pass a list of object references to a CFFI function
body: <p>I am coding on a project where I need to process many tree-like data elements, to overcome some performance issues I want to call a given processing function already written in C with the signature <code>int process(Node* root)</code> and a tree node defined as: </p>
  
  <pre><code>typedef struct Node {
      int value;
      struct Node ** children;
      int num_children;
  } Node;
  </code></pre>
  
  <p>Thus a tree node can have an arbitrary number of child nodes. Analogously a tree node in my Python project is defined as:</p>
  
  <pre><code>class Node():
      def __init__(self,value):
          self.value = value
          self.children = list()
  
      def add_child(self,child):
          self.children.append(child)
  </code></pre>
  
  <p>To call the C function I would like to use <a href="https://cffi.readthedocs.io/en/latest/" rel="nofollow noreferrer">CFFI</a>. The problem I ran into is that I need to convert my Python tree data structure to a matching C representation. A node representation, which can be passed to the CFFI function can be created via: </p>
  
  <pre><code>ffi_node = ffi.new("Node *")
  ffi_node.value = some_value
  </code></pre>
  
  <p>But I could not find a way to convert the list references to children to the <code>struct Node** children</code>.</p>