Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: class variable assumed local if passed to C function #26479

Open
mppf opened this issue Jan 7, 2025 · 0 comments
Open

[Bug]: class variable assumed local if passed to C function #26479

mppf opened this issue Jan 7, 2025 · 0 comments

Comments

@mppf
Copy link
Member

mppf commented Jan 7, 2025

Summary of Problem

Description:
Passing a variable of type unmanaged C? to an extern proc causes the compiler to assume that the class is local.

Is this issue currently blocking your progress?
No. Presumably the reason this has not come up much is that Chapel classes can't really be passed to C code (since we don't have a way of giving C the details of the type). They can be passed if cast to C void pointers, but the code looks different with such a cast (and works correctly).

We noticed this problem when making adjustments to a future in #26417 and #26476.

Steps to Reproduce

Source Code:

use CTypes;

extern proc sizeof(x):c_size_t;

class C {
  var x:int;
}

proc main() {
  var c:unmanaged C?;
  on Locales[numLocales-1] {
    writeln("allocating c on locale ", here);
    c = new unmanaged C(1);
  }
  sizeof(c); // it works if this line is commented out
  writeln(c.locale);
}
chpl program.chpl && ./program -nl 2

produces

allocating c on locale LOCALE1
LOCALE0

but I would expect it to produce

allocating c on locale LOCALE1
LOCALE1

Compile command:
see above

Execution command:
see above

Associated Future Test(s):
TODO

Configuration Information

A multi-locale configuration of Chapel. When writing this issue I was using quickstart+gasnet (local oversubscribed) and 2.4.0 pre-release.

@mppf mppf added the type: Bug label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant