title: Pointer returned by open_memstream represented as b'' in Cython
body: <p>I have the following cython code in a cdef object:</p>
  
  <pre><code>def __getstate__(self):
  
      cdef char *bp
      cdef size_t size
      cdef cn.FILE *stream
  
      stream = cn.open_memstream(&amp;bp, &amp;size)
  
      cn.write_padded_binary(self.im, self.n, 256, stream)
      cn.fflush(stream);
  
      cn.fclose(stream)
  
      print("pointer", bp, "size_t:", size)
      # ('pointer', b'', 'size_t:', 6144)
      bt = c.string_at(bp, size)
      print("bt", bt)
  
      cn.free(bp)
  
      return bt
  </code></pre>
  
  <p>However, the pointer printed in <code>print("pointer", bp, "size_t:", size)</code> and the bytestring that is printed in <code>print("bt", bt)</code> makes me worried that something is wrong. The pointer is just <code>('pointer', b'', 'size_t:', 6144)</code> and the bytestring seems to contain text from Python source code:</p>
  
  <blockquote>
    <p>x00\x00 Normalize an encoding name.\n\n        Normalization works as
    follows: all non-alphanumeric\n        characters except the dot used
    for Python package names are\n        collapsed and replaced with a
    single underscore, e.g. \'  -;#\'\n        becomes \'_\'. Leading and
    trailing underscores are removed.\n\n        Note that encoding names
    should be ASCII only; if they do use\n        non-ASCII characters,
    these must be Latin-1 compatible.\n\n    \x00\x00\</p>
  </blockquote>
  
  <p>(It's mostly just byte-symbols though).</p>
  
  <p>I am sure the <code>write_padded_binary_works</code>, because it works when I give it a regular file descriptor. I am also sure open_memstream works because when I try it with <code>cn.fprintf(stream, "hello");</code> instead of the <code>write_padded_binary</code> the output is <code>('bt', b'hello')</code>. However, the pointer is also <code>('pointer', b'hello', 'size_t:', 5)</code> so I must be misunderstanding something pointer-related I think...</p>