New Issue: createStringWithNewBuffer should accept buffer type of: c_ptr(c_char)

16321, “ben-albrecht”, “createStringWithNewBuffer should accept buffer type of: c_ptr(c_char)”, “2020-09-02T14:36:36Z”

Summary of Problem

I was toying with migrating c_string code to c_ptr(c_char) code in preparation for deprecating c_string (#14215), and I ran into an issue with converting a c_ptr(c_char) back into a Chapel string. The issue stems from the argument type of createStringWithNewBuffer() to be bufferType (c_ptr(uint(8)), but c_ptr(c_char) is c_ptr(int(8)).

I think createStringWithNewBuffer() should accept c_ptr(int(8)) as well.

Not sure what type to label this issue w.r.t. bug vs. feature request vs. unimplemented feature, so I’ll leave that off for now…

Steps to Reproduce

Source Code:

I expected the code below to work:

// Doesn't work
use SysCTypes;

var s = 'foo';
var ptr = s.c_str():c_ptr(c_char);
var s2 = createStringWithNewBuffer(ptr, s.size);
writeln(s2);

However, this gave a resolution error:

cstring.chpl:7: error: unresolved call 'createStringWithNewBuffer(c_ptr(int(8)), int(64))'
$CHPL_HOME/modules/internal/String.chpl:690: note: this candidate did not match: createStringWithNewBuffer(x: c_string, length = x.size, policy = decodePolicy.strict)
cstring.chpl:7: note: because call actual argument #1 with type c_ptr(int(8))
$CHPL_HOME/modules/internal/String.chpl:690: note: is passed to formal 'x: c_string'
$CHPL_HOME/modules/internal/String.chpl:698: note: candidates are: createStringWithNewBuffer(s: c_string, length = s.size, policy = decodePolicy.strict)
$CHPL_HOME/modules/internal/String.chpl:728: note:                 createStringWithNewBuffer(x: bufferType, length: int, size = length+1, policy = decodePolicy.strict)
note: and 3 other candidates, use --print-all-candidates to see them

bufferType is defined in ByteBufferHelpers.chpl as:

  pragma "no doc"
  type byteType = uint(8);
  pragma "no doc"
  type bufferType = c_ptr(byteType);

So, to work-around this issue, I switched to using the bufferType:

// Works
use SysCTypes;
var s = 'foo';
var ptr = s.c_str():c_ptr(uint(8));
var s2 = createStringWithNewBuffer(ptr, s.size);
writeln(s2);

Configuration Information

  • Output of chpl --version: chpl version 1.23.0 pre-release (b9fcd23fa7)