title: Segmentation fault while calling cpp function from Python
body: <p>I am trying to call <a href="https://github.com/tesseract-ocr/tesseract/blob/a3ba11b030345d32829b1e8355afea5419978d82/api/capi.cpp#L441" rel="nofollow">this cpp function</a> from python:</p>
  
  <pre><code>TESS_API BOOL TESS_CALL TessBaseAPIProcessPages(TessBaseAPI* handle, const char* filename, 
    const char* retry_config, int timeout_millisec, TessResultRenderer* renderer)
  {
      if (handle-&gt;ProcessPages(filename, retry_config, timeout_millisec, renderer))
          return TRUE;
      else
          return FALSE;
  }
  </code></pre>
  
  <p>The last parameter of this function is <code>TessResultRenderer</code>. There is <a href="https://github.com/tesseract-ocr/tesseract/blob/a3ba11b030345d32829b1e8355afea5419978d82/api/capi.cpp#L52" rel="nofollow">another cpp function</a> for creating <code>TessResultRenderer</code></p>
  
  <pre><code>TESS_API TessResultRenderer* TESS_CALL TessTextRendererCreate(const char* outputbase)
  {
      return new TessTextRenderer(outputbase);
  }
  </code></pre>
  
  <p>Now while calling this from my python, I did the following:</p>
  
  <pre><code>outputbase = "stdout"
  renderer = tesseract.TessTextRendererCreate(outputbase)
  text_out = tesseract.TessBaseAPIProcessPages(api, 
       ctypes.create_string_buffer(path), 
       None, 0, renderer) //Segmentation fault (core dumped) error on this line
  </code></pre>
  
  <p>but I keep getting <code>Segmentation fault</code> error. </p>
  
  <p>My question is how can I called <code>TessBaseAPIProcessPages</code> from Python?</p>
  
  <p>Some more reference links into the codebase:</p>
  
  <p><a href="https://github.com/tesseract-ocr/tesseract/blob/a3ba11b030345d32829b1e8355afea5419978d82/api/renderer.cpp#L32" rel="nofollow">referer api</a></p>
  
  <p><a href="https://github.com/tesseract-ocr/tesseract/blob/a3ba11b030345d32829b1e8355afea5419978d82/api/baseapi.cpp#L1077" rel="nofollow">Implementation of processPages(...)</a></p>
  
  <p><strong>Edit</strong></p>
  
  <p>After trying the commented suggestions, I did the following but I get an error: <code>item 1 in _argtypes_ has no from_param method</code></p>
  
  <pre><code>PTessResultRenderer = ctypes.POINTER(TessResultRenderer)
  self.tesseract.TessTextRendererCreate.restype = PTessResultRenderer
  outputbase = "stdout"
  self.tesseract.TessTextRendererCreate.argtypes = [outputbase] #error here
  self.tesseract.TessTextRendererCreate
  
  ReturnVal = ctypes.c_bool
  self.tesseract.TessBaseAPIProcessPages.argtypes = [self.api, path, None, 0, PTessResultRenderer]
  self.tesseract.TessBaseAPIProcessPages.restype = ReturnVal
  self.tesseracto.TessBaseAPIProcessPages
  
  class TessResultRenderer(ctypes.Structure):
      pass
  </code></pre>