Skip to content

TestStdStringInField and TestArrayParams fail in debugging configuration on windows because std:string size is wrong. #1889

Description

@HenrikAkseliValve
Brief Description

Two tests didn't seem to succeed even after I reverted the code I was working on. The function call did go through, but some data coming from C# was uninitialized in C++. C# context everything looked fine.

It seems there is a size difference between C# std.BasicString (32 bytes) and C++ std::basic_string (40 bytes). These tests did not fail on the pull request #1887, hence I would conclude that Windows has some extra payload when compiling on debug.

How is Std.cs generated? With headers attached to Std module?
Is this just that CppSharp does not define _RELEASE or _DEBUG for clang, so the header is different from the binary?

OS: Windows

std::basic_string size on C++

image

std.BasicString on Std.cs on VTables.CSharp:
    namespace BasicString
    {
        [StructLayout(LayoutKind.Sequential, Size = 32, Pack = 8)]
        public unsafe partial struct __Internalc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C
        {
            internal global::Std.CompressedPair.__Internalc__N_std_S__Compressed_pair____N_std_S_allocator__C___N_std_S__String_val____N_std_S__Simple_types__C_Vb1 _Mypair;

            [SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ", CallingConvention = __CallingConvention.Cdecl)]
            internal static extern __IntPtr ctorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);

            [SuppressUnmanagedCodeSecurity, DllImport("Std-symbols", EntryPoint = "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ", CallingConvention = __CallingConvention.Cdecl)]
            internal static extern void dtorc__N_std_S_basic_string__C___N_std_S_char_traits__C___N_std_S_allocator__C(__IntPtr __instance);
        }
    }

Activity

  1. HenrikAkseliValve commented on Jan 5, 2025

    @HenrikAkseliValve
    ContributorAuthor

    Doh, there was an old discussion on this #1365

  2. duckdoom5 commented on Jan 25, 2025

    @duckdoom5
    Contributor

    I think this issue will be resolved when #1893 is merged. The issue is that there are some parser bindings that need to be manually generated for msvc's debug configuration.
    I've linked and added those in that PR, so if you need those soon you can grab them from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions