FFI problem with wxHaskell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
I have a little test application which looks like this:

Firstly import[1] some functions:

foreign import ccall "wxStringProperty_Create" wxStringProperty_Create :: Ptr (TWxString a) -> IO (Ptr (TStringProperty ()))
foreign import ccall "wxPGProperty_GetValue" wxPGProperty_GetValue :: Ptr (TPGProperty a) -> IO (Ptr (TAny ()))
foreign import ccall "wxAny_IsInt" anyIsInt :: Ptr (TAny a) -> IO Bool
foreign import ccall "wxAny_IsString" anyIsString :: Ptr (TAny a) -> IO Bool


And then we do this:

main = start test

test = do
  pAny <- withStringPtr "TEST" wxStringProperty_Create >>= wxPGProperty_GetValue
  anyIsInt pAny >>= putStrLn . show
  anyIsString pAny >>= putStrLn . show


Now what I expected is "False" and "True", but I actually get back "True" twice.
I've written what should be an identical program[2] in C++ and it works as expected.

Any suggestions?



[1] Here's the source of those functions (which I've created in wxcore/cpp/extra.cpp):
EWXWEXPORT(wxStringProperty*,wxStringProperty_Create)(wxString const* label)
{
        return new wxStringProperty(*label);
}

EWXWEXPORT(wxAny*,wxPGProperty_GetValue)(wxPGProperty* self)
{
        wxAny *result = new wxAny();
        *result = self->GetValue();
        return result;
}

EWXWEXPORT(bool,wxAny_IsInt)(wxAny* self)
{
        return self->CheckType< int >();
}

EWXWEXPORT(bool,wxAny_IsString)(wxAny* self)
{
        return self->CheckType< wxString >();
}


[2] The C++ version looks like this:
    wxStringProperty testStr("TEST");
    wxPGProperty prop = testStr;

    wxAny *result = new wxAny();
    *result = prop.GetValue();

    printf("is Int? %s\n", result->CheckType< int >() ? "yes" : "no");
    printf("is String? %s\n", result->CheckType< wxString >() ? "yes" : "no");