chapel icon indicating copy to clipboard operation
chapel copied to clipboard

[Feature Request]: Export functions with arrays of strings as arguments for Python interoperability

Open lydia-duncan opened this issue 10 months ago • 1 comments

Summary of Feature

Description: Today, in exported functions for Python you can:

  • accept string arguments
  • return strings
  • accept array arguments with numeric element types
  • return arrays with numeric element types
  • return arrays with string element types (test/interop/python/retStringArray.chpl)

However, you can't accept array arguments with string element types. This is because the current setup for converting a Python array-like object into a Chapel array expects all the elements to be the same size, but strings can vary in size. This is not insurmountable, but would require specializing the handling when the argument uses strings as the element type.

Is this a blocking issue with no known work-arounds? Currently there is no way to pass the array of strings returned from an exported Chapel function back into Chapel and allow it to be modifiable by Python along the way.

However, I believe you can return an opaque array of strings and have an exported Chapel function accept that back.

If #24874 was resolved, that would be a reasonable work-around (and was the strategy used before the conversion from c_string to c_ptrConst(c_char) occurred).

Code Sample

export proc takeStringArr(in x: [] string) {
  for str in x {
    writeln(str);
  }
}

Future added in #24896

lydia-duncan avatar Apr 17 '24 18:04 lydia-duncan