strings, encodings, and NCI

With the recent addition of the as_string method to UnManagedStruct and Ptr PMCs (see my last post) and the get_pointer vtable in ByteBuffer now is easier to pass and get strings from NCI (parrot Native Calll Interface).

To pass a string to a NCI 'p' parameter you just need to create a ByteBuffer and set the string to it, maybe after trans_encoding it, and add the zero-termination required in most usages by pushing a 0 value. ByteBuffer takes care of memory management.

The same procedure can be used to set a char * member in a struct (using the StructView PMC), but you need to set the StructView as if it were a void * instead of a char *.

To get the string from a 'p' return type, or from StructView as in the parameter case, you use as_string in the PMC (which currently can be a UnManagedStruct or a Ptr, but as long as both provide the same method you don't need to worry).

This doesn't address the problem of memory management of the returned values. When you use an external function that returns a value that you are responsible to free, you still need to manage it. A more automated way probably must wait until UnManagedStruct finish its deprecations cycle.