mabuchilab / NiceLib

A Python package for rapidly developing "nice" bindings for C libraries, using cffi
GNU General Public License v3.0
24 stars 8 forks source link

Add better string handling #1

Open natezb opened 7 years ago

natezb commented 7 years ago

Currently, the 'buf'-related signature types are returned after being run through ffi.string(). This returns a bytes object (equivalent to str in Python 2). However, it'd be useful to have more control. There are probably 3 common cases:

  1. Always bytes
  2. Version-specific str (equivalent to bytes on py2, unicode on py3)
  3. Always unicode

We could introduce new names, e.g. strbuf, but that may be overly cluttered and annoying. A better solution may be to introduce a new flag for this setting, which will also allow us to do it on a per-library, per-object, and per-function level.