title: Passing a C pointer around with the Python/C API
body: <p>I'm new to the Python/C API ... I'm trying to add new functionality to my C program, wherein I can embed python into it and simultaneously extend functionality so that the embedded interpreter can execute a script that will interact with an extending python module written as part of my C program.  My C program doesn't have global variables. I would like to keep things this way; At the same time in order to expose C functionality to python, it appears the extending C function at least needs access to global variables to access state of the program. How do I get around this?</p>
  
  <p>e.g. Here is how I plan on embedding where PYINTERFACE_Initialize is called from main</p>
  
  <pre><code>void PYINTERFACE_Initialize(State *ptr, FILE *scriptFile, const char* scriptFileName)
  {
      Py_Initialize();
      PyObject *module = Py_InitModule("CInterface", CInterfaceMethods);
      if (PyRun_SimpleFileEx(scriptFile, scriptFileName, 1) != 0)
      {
          printf("PYINTERFACE script execution failed!\n");
      }
      **//ADD State *ptr TO module**      
  }
  </code></pre>
  
  <p>Here is the extended function:</p>
  
  <pre><code>static PyObject*
  CInterface_GetStateInfo(PyObject *self, PyObject *args)
  {
      const char *printStr;
      double stateInfo;
      State *ptr;
  
      if(!PyArg_ParseTuple(args, "s", &amp;printStr))
      {
          return NULL;
      }
      printf("Received %s\n", printStr);
  
      **//RETRIEVE State *ptr FROM self**      
  
      stateInfo = ptr-&gt;info;
      return Py_BuildValue("d", currentTime);
  }
  </code></pre>
  
  <p>Is this the cleanest way to pass the State *ptr around? I certainly don't see the need to expose the internal state to python. I've thought about using capsules, but it doesn't seem to be the intention of capsules to support this sort of behaviour.</p>
  
  <p>Thanks in advance!
  V</p>