{"action":"created","issue":{"url":"https://api.github.com/repos/libffi/libffi/issues/305","repository_url":"https://api.github.com/repos/libffi/libffi","labels_url":"https://api.github.com/repos/libffi/libffi/issues/305/labels{/name}","comments_url":"https://api.github.com/repos/libffi/libffi/issues/305/comments","events_url":"https://api.github.com/repos/libffi/libffi/issues/305/events","html_url":"https://github.com/libffi/libffi/issues/305","id":228316960,"number":305,"title":"Pass struct by value not passing copy on win64","user":{"login":"embray","id":676149,"avatar_url":"https://avatars1.githubusercontent.com/u/676149?v=4","gravatar_id":"","url":"https://api.github.com/users/embray","html_url":"https://github.com/embray","followers_url":"https://api.github.com/users/embray/followers","following_url":"https://api.github.com/users/embray/following{/other_user}","gists_url":"https://api.github.com/users/embray/gists{/gist_id}","starred_url":"https://api.github.com/users/embray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/embray/subscriptions","organizations_url":"https://api.github.com/users/embray/orgs","repos_url":"https://api.github.com/users/embray/repos","events_url":"https://api.github.com/users/embray/events{/privacy}","received_events_url":"https://api.github.com/users/embray/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-12T14:54:19Z","updated_at":"2017-09-17T13:37:00Z","closed_at":null,"author_association":"NONE","body":"Forgive me if this is already a known issue or if I'm missing something, though I couldn't find any obvious reference to it.  I ran across this issue via running the test suite for Python on Cygwin 64-bit.  The following simple example reproduces the problem:\r\n\r\n```c\r\n#include <ffi.h>\r\n#include <stdio.h>\r\n#include <assert.h>\r\n\r\ntypedef struct {\r\n    unsigned long first;\r\n    unsigned long second;\r\n    unsigned long third;\r\n} Test;\r\n\r\n\r\nstatic void update_value(Test in) {\r\n    ((volatile Test*)&in)->first = 0x0badf00d;\r\n    ((volatile Test*)&in)->second = 0x0badf00d;\r\n    ((volatile Test*)&in)->third = 0x0badf00d;\r\n}\r\n\r\n\r\nint main(void) {\r\n    ffi_cif cif;\r\n    ffi_type *args[1];\r\n    void *values[1];\r\n    ffi_type Test_type;\r\n    ffi_type *Test_type_elements[4];\r\n    int idx;\r\n\r\n    Test test = {0xdeadbeef, 0xcafebabe, 0x0bad1dea};\r\n\r\n    Test_type.size = Test_type.alignment = 0;\r\n    Test_type.elements = (ffi_type **)&Test_type_elements;\r\n\r\n    for (idx = 0; idx < 3; idx++) {\r\n        Test_type_elements[idx] = &ffi_type_ulong;\r\n    }\r\n    Test_type_elements[3] = NULL;\r\n\r\n    args[0] = &Test_type;\r\n    values[0] = (void*)&test;\r\n\r\n    if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, args) == FFI_OK) {\r\n        ffi_call(&cif, (void*)update_value, NULL, values);\r\n        printf(\"test.first = 0x%08lx\\n\", test.first);\r\n        assert(test.first == 0xdeadbeef);\r\n    } else {\r\n        printf(\"Error with ffi_prep_cif\\n\");\r\n    }\r\n    return 0;\r\n}\r\n```\r\n\r\nJust looking at ffiw64.c I think it's pretty simplistic--it always just passes struct types by reference, and doesn't make a copy first before a pass by value."},"comment":{"url":"https://api.github.com/repos/libffi/libffi/issues/comments/330044961","html_url":"https://github.com/libffi/libffi/issues/305#issuecomment-330044961","issue_url":"https://api.github.com/repos/libffi/libffi/issues/305","id":330044961,"user":{"login":"andreas-schwab","id":2175493,"avatar_url":"https://avatars2.githubusercontent.com/u/2175493?v=4","gravatar_id":"","url":"https://api.github.com/users/andreas-schwab","html_url":"https://github.com/andreas-schwab","followers_url":"https://api.github.com/users/andreas-schwab/followers","following_url":"https://api.github.com/users/andreas-schwab/following{/other_user}","gists_url":"https://api.github.com/users/andreas-schwab/gists{/gist_id}","starred_url":"https://api.github.com/users/andreas-schwab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreas-schwab/subscriptions","organizations_url":"https://api.github.com/users/andreas-schwab/orgs","repos_url":"https://api.github.com/users/andreas-schwab/repos","events_url":"https://api.github.com/users/andreas-schwab/events{/privacy}","received_events_url":"https://api.github.com/users/andreas-schwab/received_events","type":"User","site_admin":false},"created_at":"2017-09-17T13:37:00Z","updated_at":"2017-09-17T13:37:00Z","author_association":"NONE","body":"This also fails on aarch64.\r\n\r\n(The test case is missing the assignment Test_type.type = FFI_TYPE_STRUCT.)"}}
{"actor":{"display_login":"andreas-schwab"}}