You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
I'm not sure how much of this is user error on my part, but I'm having difficulty using a c_array as though it was a c_ptr for the purpose of calling string.createCopyingBuffer (which accepts a c_ptr or a c_ptrConst).
An implicit conversion for a function call - also called a coercion - occurs when the actual argument of a function call is converted to the type of the corresponding formal argument, if the formal’s intent is param, in, const in, const, or the default intent.
Given that the argument for string.createCopyingBuffer uses the default intent, my expectation based on these two paragraphs is that I should be able to pass a c_array to that function without an explicit cast. However, when I try to do so, I get an unresolved call error. I think this means that either the documentation or the compiler needs to be updated.
Is this a blocking issue with no known work-arounds?
No. I encountered this while writing an example for another user (so nothing in work I was doing myself) and it looks like an explicit cast may be okay (though I'm having other difficulties that could also just be user error on my part, so I can't verify that the cast works at execution time until I figure those out).
Steps to Reproduce
Source Code:
// <some valid code to create a c_array named cArr>var str =string.createCopyingBuffer(cArr);
Compile command: chpl foo.chpl
Execution command:
N/A
Associated Future Test(s):
TBD
Configuration Information
Output of chpl --version: 2.1.0 pre-release
Output of $CHPL_HOME/util/printchplenv --anonymize: Any, this is a compiler error
Back-end compiler and version, e.g. gcc --version or clang --version: Any, this is a compiler error
(For Cray systems only) Output of module list: N/A
The text was updated successfully, but these errors were encountered:
I've tried four different ways to create the c_array in Chapel code (instead of creating it in C code and obtaining it that way, which I think would probably be easier to do at this point), but none of them have worked. Recording them here for myself when I get back to submitting a test to the test system:
I haven't gotten far enough to try reproducing the original issue yet, but with a quick look, I wonder whether the issue is that the argument to createBorrowingBuffer is generic, and we don't support coercions to generic arguments?
In attempt 1, recall that since Chapel strings can be UTF-8 and arbitrary length (i.e., we don't have a char type), you need to use a technique to specifically grab out the singleton byte if there is one. For example, string.toByte() is one such approach: https://chapel-lang.org/docs/language/spec/strings.html#String.string.toByte Here's approach one updated to address that on ATO
Oh, except then I'm not sure why approach 4 got through compilation… that's pretty surprising to me.
It makes sense that approach 2 doesn't work to me because it's effectively requesting a copy from a pointer to an array. For example, C similarly wouldn't support: char str[5] = myCharStarPtr; [ATO]. You'd need to use a memcpy() to get from one to the other [ATO]. We could arguably add an initializer that would do this conversion, but it'd be supporting a pattern that C doesn't (which is what I think of the c_array and c_ptr types as trying to do).
Approach 3 seems equivalent to approach 2.
Here's a proposed approach to writing the pattern: [ATO]
use CTypes, OS.POSIX;
var cArr =new c_array(c_char, 6);
memcpy(cArr, c_ptrToConst(b"abcde"), 6);
externproc printf(in x...);
printf("%s", cArr);
Summary of Problem
Description:
I'm not sure how much of this is user error on my part, but I'm having difficulty using a c_array as though it was a c_ptr for the purpose of calling
string.createCopyingBuffer
(which accepts a c_ptr or a c_ptrConst).The documentation for c_array says:
And the documentation for coercions says:
Given that the argument for
string.createCopyingBuffer
uses the default intent, my expectation based on these two paragraphs is that I should be able to pass ac_array
to that function without an explicit cast. However, when I try to do so, I get an unresolved call error. I think this means that either the documentation or the compiler needs to be updated.Is this a blocking issue with no known work-arounds?
No. I encountered this while writing an example for another user (so nothing in work I was doing myself) and it looks like an explicit cast may be okay (though I'm having other difficulties that could also just be user error on my part, so I can't verify that the cast works at execution time until I figure those out).
Steps to Reproduce
Source Code:
Compile command:
chpl foo.chpl
Execution command:
N/A
Associated Future Test(s):
TBD
Configuration Information
chpl --version
: 2.1.0 pre-release$CHPL_HOME/util/printchplenv --anonymize
: Any, this is a compiler errorgcc --version
orclang --version
: Any, this is a compiler errormodule list
: N/AThe text was updated successfully, but these errors were encountered: