Windows error 0x000000D5, 213

Detailed Error Information

DRIVER_PAGE_FAULT_IN_FREED_SPECIAL_POOL[1]

This is a Blue Screen of Death stop code. More information is available in the Knowledge Base article Bug Check 0xD5: DRIVER_PAGE_FAULT_IN_FREED_SPECIAL_POOL.

HRESULT analysis[2]

This is probably not the correct interpretation of this error. The Win32 error above is more likely to indicate the actual problem.
FlagsSeveritySuccess

This code indicates success, rather than an error. This may not be the correct interpretation of this code, or possibly the program is handling errors incorrectly.

Reserved (R)false
OriginMicrosoft
NTSTATUSfalse
Reserved (X)false
FacilityCode0 (0x000)
NameFACILITY_NULL[2][3]
DescriptionThe default facility code.[2][3]
Error Code213 (0x00d5)

Possible solutions

8

How to create a SafeArray C#?

c#
com
interop
com-interop
safearray

use such a code for this

Array ar = Array.CreateInstance(typeof (int), 500);

instead of typeof(int) use your own data type, your COM object must say you what type is expecting.

answered on Stack Overflow May 4, 2011 by Eugen
5

From a huge enumeration, I try to make a function to apply the right action without using a switch body by using some template tricks

c++
templates
c++11

Use a table of entities.

You could also use std::map<value, function_pointer> which may be faster depending on your enumeration values.

The table is also called a jump table. Many compilers will convert switch statements into jump tables. Although the table of may be what the compiler generates, I believe the table is easier to maintain then a switch statement for large quantities of cases.

Edit 1: - Example
Simple Version: array of function pointers.

// Synonym for pointer to a function that has no parameters
//    and returns no values.
typedef void (*Function_Pointer)(void);

// Prototypes
void Eat(void);
void Sleep(void);
void Drink(void);

// The table
const static Function_Ptr dispatch_table[] =
{ /* Index 0 */ Eat,
  /* Index 1 */ Sleep,
  /* Index 2 */ Drink,
};

// Execution syntax
unsigned int index = 1;
(dispatch_table[index])();  // Execute Sleep() function.

More Robust Version: Associating enum with function pointer.

struct Dispatch_Entry
{
  unsigned int  function_ID;
  Function_Pointer p_function;
};

const static Dispatch_Entry robust_dispatch_table[] =
{
  // Unlike the array, this structure allows the
  // function pointers to be listed in any order.
  // Also, they don't have to be contiguous.
  {2, Drink},
  {0, Eat},
  {1, Sleep},
};
const unsigned int num_entries =
  sizeof(robust_dispatch_table) / sizeof(robust_dispatch_table[0]);

// Look up the function:
for (unsigned int i = 0;
     i < num_entries;
     ++i)
{
  if (robust_dispatch_table[i].function_ID == function_id_to_execute)
  {
    (robust_dispatch_table[i].p_function)(); // Execute function.
    break;
  }
}
answered on Stack Overflow Jan 17, 2015 by Thomas Matthews • edited Jan 17, 2015 by Thomas Matthews
2

What happens between the .NET interop layer and COM?

c#
.net
com
com-interop
tlbimp

Another update: I just realize it might be that you mean that the GetTags itself should populate that Array (from the COM code). But this can never work as that parameter is an [in] parameter.

For the COM component to be able to fill up that Array, It should be passed as an [in, out] parameter, and by reference (SAFEARRAY*).


Update: Ok, apparently I was mixing the creation of a COM component in .NET with calling a COM component from .NET.

The CCW (com callable wrapper) indeed takes a .NET Array for COM SafeArray's. I see you create your array in the code in your question, but you don't show how you actually populate it. Maybe something's wrong with that code? Could you share it?


Not sure if this is a solution to your problem, but I've experienced problems with COM-interop and SAFEARRAY's in the past.

One thing I learned from it is that the .NET equivalent of a COM SAFEARRAY should always be object, so try passing your array as an object in stead of as an Array.

answered on Stack Overflow May 9, 2011 by fretje • edited May 9, 2011 by fretje
1

How to register events using libxcb-xinput

c
linux
touch
x11
xcb

You need to use xcb_input_event_mask_t and xcb_input_xi_event_mask_t together, in the following way:

struct {
    xcb_input_event_mask_t head;      // describes the subsequent xcb_input_xi_event_mask_t (or an array thereof)
    xcb_input_xi_event_mask_t mask;
} mask;

mask.head.deviceid = XCB_INPUT_DEVICE_ALL;
mask.head.mask_len = sizeof(mask.mask) / sizeof(uint32_t);

mask.mask = XCB_INPUT_XI_EVENT_MASK_TOUCH_BEGIN
| XCB_INPUT_XI_EVENT_MASK_TOUCH_END
| XCB_INPUT_XI_EVENT_MASK_TOUCH_UPDATE
| XCB_INPUT_XI_EVENT_MASK_TOUCH_OWNERSHIP;

xcb_input_xi_select_events(dpy, root, 1, &mask.head);

Disclaimer: I have never used this. I have found one single usage example on the 'net here. I tried to verify this usage against the source of xcb_input_xi_select_events here but its code is expletive deleted unreadable. I have not a slightest idea how exactly people should be able to use this library.

answered on Stack Overflow Sep 25, 2016 by n.m.
1

How to register events using libxcb-xinput

c
linux
touch
x11
xcb

I found a solution to this.
Big thanks to https://github.com/eemikula/touchwm.

const uint32_t mask[] = {
    XCB_INPUT_XI_EVENT_MASK_TOUCH_BEGIN
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_UPDATE
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_END
    | XCB_INPUT_XI_EVENT_MASK_TOUCH_OWNERSHIP
};
const uint32_t modifiers[] = {XCB_INPUT_MODIFIER_MASK_ANY};

xcb_input_xi_passive_grab_device(
    dpy, 
    XCB_CURRENT_TIME, 
    root,
    XCB_CURSOR_NONE,
    0, // detail - as used by XIPassiveGrab
    XCB_INPUT_DEVICE_ALL_MASTER,
    1, // num_modifiers
    1, // mask_len
    XCB_INPUT_GRAB_TYPE_TOUCH_BEGIN,
    XCB_INPUT_GRAB_MODE_22_TOUCH,
    XCB_INPUT_GRAB_MODE_22_ASYNC,
    XCB_INPUT_GRAB_OWNER_NO_OWNER,
    mask,
    modifiers
);

It looks a bit cryptic, but it works.

answered on Stack Overflow Sep 27, 2016 by freundTech
1

What happens between the .NET interop layer and COM?

c#
.net
com
com-interop
tlbimp

I hesitate to suggest this as an answer, but...

If the Delphi test code really does work, as noted elsewhere, this means the GetTags method must not be playing properly by SAFEARRAY rules. If the COM method is always called in-process, you MAY be able to get the .NET code to work by doing some custom marshalling "by hand", following exactly what the unmanaged Delphi test code does.

As a rough outline, I would imagine that this would involve:

  • allocating an unmanaged buffer to hold the array values
  • calling Ole Automation SAFEARRAY initialization APIs via P/Invoke to allocate a SAFEARRAY structure and attach the array buffer to it as its pData member
  • invoking the GetTags method with this SAFEARRAY
  • marshalling your unamanaged buffer into a managed array, before...
  • calling the Win32 API to destroy the SAFEARRAY

But much better to get the COM component changed to do things properly, if you can.

answered on Stack Overflow May 9, 2011 by Chris Dickson
1

gcc does not produce debugging symbols for local variable-length arrays (or gdb doesn't find them)

gcc

Ooooooopppsssssss....
I just found out that on my machine (os x 10.7.5) gcc is not gcc!
It's just a link /usr/bin/gcc@ -> llvm-gcc-4.2

I did the same experiment on a machine with a genuine gcc and everything works as is should! The symbol for "array" is... lo and behold... "array".

So it's a llvm thing. Sorry guys. As far as gcc is concerned, case closed. If I compile with clang it's even worse. No symbol at all is produced for "array".

I shuold repost the question under the llvm-ggc tag with a different title.

answered on Stack Overflow Aug 6, 2014 by brian0
0

gcc does not produce debugging symbols for local variable-length arrays (or gdb doesn't find them)

gcc

gdb 7.8 should now support this:

Tue, 29 Jul 2014

GDB 7.8 brings new targets, features and improvements, including:

...

  • ISO C99 variable length automatic arrays support.

http://lwn.net/Articles/607108/

and indeed on ubuntu 14.10 utopic it works for me:

# gcc -g3 test.c -O0
# gdb ./a.out
GNU gdb (Ubuntu 7.8-0ubuntu1) 7.8
(gdb) break main
Breakpoint 1 at 0x4005be: file test.c, line 4.
(gdb) r
Starting program: /a.out 

Breakpoint 1, main (argc=1, argv=0x7fffffffe2d8) at test.c:4
4   int main( int argc, char **argv ) { 
(gdb) n
6       n = random() & 0xf;
(gdb) 
7       int array[n];
(gdb) 
8       int *array_pt = array;
(gdb) p array
$1 = {-136403536, 32767, -134225464, 1804289383, 3, 0, 4195800}
(gdb) 
answered on Stack Overflow Aug 6, 2014 by jtaylor • edited Aug 6, 2014 by jtaylor
0

From a huge enumeration, I try to make a function to apply the right action without using a switch body by using some template tricks

c++
templates
c++11

Approaching the age of 50 I feel free to present the vintage style solution to the problem. Traits:

  1. O(1) lookup.
  2. Table is not constructed/sorted at compile time, but instead at pre-main init time. A constructor writing 1200 function pointer values to a static array should not take more than a few microseconds.
  3. Template free - even the most silly of C++ compiler can handle this. Also, probably without all those templates your image size will be so much smaller that the runtime initialization of the array is amortized by the loading time for the image.
  4. Suitable to produce heart attacks to all your C++11++-whatnot fans.
  5. Took me only 30min...
  6. Most of the macro stuff you can throw into a header file (where your enum probably is...)

Here it is:

#include <iostream>
#include <vector>

typedef size_t Instr;

typedef enum Foo
{
    I_INVALID = 0
,   F_1 // for lack of better names... could as well be foo bar baz...
,   F_2
,   I_LAST_INSTRUCTION = 20
} Foo_t;

typedef void(*TestFunction_t)(std::vector<Instr> &, bool);

#define BEGIN_TEST_FUNCTION(id,name) \
    static void name (std::vector<Instr> & l, bool b) \
        { \
        static const Foo_t s_id = id; 
#define END_TEST_FUNCTION()\
        }

#define DECLARE_TEST_FUNCTION(id,name) \
    s_functions[id] = name;

#define INVOKE(id) \
    if( NULL != Invoker::s_functions[id]) \
        Invoker::s_functions[id]

BEGIN_TEST_FUNCTION(F_1,Test1)
    std::cout << "testing instruction #" << s_id << std::endl;
END_TEST_FUNCTION()

BEGIN_TEST_FUNCTION(F_2, Test2)
std::cout << "testing instruction #" << s_id << std::endl;
END_TEST_FUNCTION()

class Invoker
{
public:
    static TestFunction_t s_functions[I_LAST_INSTRUCTION];
    Invoker()
    {
        DECLARE_TEST_FUNCTION(F_1, Test1)
        DECLARE_TEST_FUNCTION(F_2, Test2)
        // ... and so on...
    }
};
static Invoker s_invokerInitializer;

TestFunction_t
Invoker::s_functions[I_LAST_INSTRUCTION] =
{
    {0}
};


int main(int argc, const char *argv[])
{
    std::vector<Instr> whatever;
    INVOKE(F_1)(whatever, true);
    INVOKE(F_2)(whatever, true);
    return 0;
}
answered on Stack Overflow Jan 18, 2015 by BitTickler
0

From a huge enumeration, I try to make a function to apply the right action without using a switch body by using some template tricks

c++
templates
c++11

Ok, if I choose an array of N elements viewed as a list of N/4 sub-arrays of 4 elements instead of the previous list of N sub-arrays of 1 element, compilation and execution are successful with right results (306 nests which is under 499 limit in VC2013). I wish it can be doable as a binary-tree so the nest count will be logarithmic (11 nests instead of 1223 nests!).

#include <iostream>
#include <vector>

using namespace std;

typedef size_t Instr; // dummy one for simplified code

enum
{
    I_INVALID = 0,

    I_LAST_INSTRUCTION = 1223
};

template< size_t id >
static void Test_T(std::vector< Instr > &, bool)
{
    cout << "testing instruction #" << id << endl;
}

template< typename Derived, size_t start_id, size_t end_id, size_t rem = ((end_id - start_id) & 3) >
struct Tester_T;

template< typename Derived, size_t start_id, size_t end_id >
struct Tester_T < Derived, start_id, end_id, 0 > : Tester_T < Derived, start_id, end_id - 4 >
{
    Tester_T()
    {
        static_cast<Derived *>(this)->array[end_id - 4] = Test_T< end_id - 4 >;
        static_cast<Derived *>(this)->array[end_id - 3] = Test_T< end_id - 3 >;
        static_cast<Derived *>(this)->array[end_id - 2] = Test_T< end_id - 2 >;
        static_cast<Derived *>(this)->array[end_id - 1] = Test_T< end_id - 1 >;
    }
};

template< typename Derived, size_t start_id, size_t end_id >
struct Tester_T < Derived, start_id, end_id, 1 > : Tester_T < Derived, start_id, end_id - 3 >
{
    Tester_T()
    {
        static_cast<Derived *>(this)->array[end_id - 3] = Test_T< end_id - 3 >;
        static_cast<Derived *>(this)->array[end_id - 2] = Test_T< end_id - 2 >;
        static_cast<Derived *>(this)->array[end_id - 1] = Test_T< end_id - 1 >;
    }
};

template< typename Derived, size_t start_id, size_t end_id >
struct Tester_T < Derived, start_id, end_id, 2 > : Tester_T < Derived, start_id, end_id - 2 >
{
    Tester_T()
    {
        static_cast<Derived *>(this)->array[end_id - 2] = Test_T< end_id - 2 >;
        static_cast<Derived *>(this)->array[end_id - 1] = Test_T< end_id - 1 >;
    }
};

template< typename Derived, size_t start_id, size_t end_id >
struct Tester_T < Derived, start_id, end_id, 3 > : Tester_T < Derived, start_id, end_id - 1 >
{
    Tester_T()
    {
        static_cast<Derived *>(this)->array[end_id - 1] = Test_T< end_id - 1 >;
    }
};

template< typename Derived >
struct Tester_T < Derived, 0, 0 >
{
};

struct Tester : Tester_T< Tester, I_INVALID, I_LAST_INSTRUCTION >
{
    void(*array[size_t(I_LAST_INSTRUCTION)])(std::vector< Instr > & list, bool is64);

    void operator()(size_t id, std::vector< Instr > & list, bool is64) const
    {
        if (id < I_LAST_INSTRUCTION)
        {
            (array[size_t(id)])(list, is64);
        }
        else
        {
            // to do nothing
        }
    }
};

static Tester const tester; 

int main()
{   
    std::vector< Instr > list;

    tester(0, list, true); // display testing instruction #0
    tester(1, list, true); // display testing instruction #1
    tester(2, list, true); // display testing instruction #2
    tester(3, list, true); // display testing instruction #3
    tester(4, list, true); // display testing instruction #4
    tester(8, list, true); // display testing instruction #8
    tester(15, list, true); // display testing instruction #15
    tester(16, list, true); // display testing instruction #16
    tester(1024, list, true); // display testing instruction #1024
    tester(1222, list, true); // display testing instruction #1222
    tester(1223, list, true); // invalid instruction number - do nothing
    tester(2048, list, true); // invalid instruction number - do nothing
}

Edit: the following code is doing the same in a more generic way (you can set the number max of element in a sub-array by setting the number of bits to encode an index of an element in a sub-array as the fourth template parameter of class Test_T)

#include <iostream>
#include <vector>

using namespace std;

typedef size_t Instr; // dummy one for simplified code

enum
{
    I_INVALID = 0,

    I_LAST_INSTRUCTION = 1223
};

template< size_t id >
static void Test_T(std::vector< Instr > &, bool)
{
    cout << "testing instruction #" << id << endl;
}

struct Tester;

template< size_t start_id, size_t end_id >
struct TestArrayInitializer_T
{
    static void Set(Tester & tester)
    {
        tester.array[start_id] = Test_T < start_id > ;
        TestArrayInitializer_T< start_id + 1, end_id >::Set(tester);
    }
};

template< size_t start_id >
struct TestArrayInitializer_T < start_id, start_id >
{
    static void Set(Tester & tester)
    {
        tester.array[start_id] = Test_T < start_id > ;
    }
};

template< typename Derived,
          size_t   start_id,
          size_t   end_id,
          size_t   bits,
          size_t   N = (1 << bits),
          size_t   i = (end_id - start_id) & (N - 1) >
struct Tester_T : Tester_T < Derived, start_id, end_id - N + i, bits >
{
    Tester_T()
    {
        TestArrayInitializer_T< end_id - N + i, end_id - 1 >::Set(*static_cast<Derived *>(this));
    }
};

template< typename Derived, size_t bits, size_t N, size_t i >
struct Tester_T < Derived, 0, 0, bits, N, i >
{
};

struct Tester :
    Tester_T < Tester,
               I_INVALID,
               I_LAST_INSTRUCTION,
               8 /* 256 elements per sub-array */ >
{
    void(*array[size_t(I_LAST_INSTRUCTION)])(std::vector< Instr > & list, bool is64);

    void operator()(size_t id, std::vector< Instr > & list, bool is64) const
    {
        if (id < I_LAST_INSTRUCTION)
        {
            (array[size_t(id)])(list, is64);
        }
        else
        {
            // to do nothing
        }
    }
};

static Tester const tester;

int main()
{
    std::vector< Instr > list;

    tester(0, list, true); // display testing instruction #0
    tester(1, list, true); // display testing instruction #1
    tester(2, list, true); // display testing instruction #2
    tester(3, list, true); // display testing instruction #3
    tester(4, list, true); // display testing instruction #4
    tester(8, list, true); // display testing instruction #8
    tester(15, list, true); // display testing instruction #15
    tester(16, list, true); // display testing instruction #16
    tester(1024, list, true); // display testing instruction #1024
    tester(1222, list, true); // display testing instruction #1222
    tester(1223, list, true); // invalid instruction number - do nothing
    tester(2048, list, true); // invalid instruction number - do nothing
}
answered on Stack Overflow Jan 18, 2015 by hlide • edited Jan 18, 2015 by hlide
0

From a huge enumeration, I try to make a function to apply the right action without using a switch body by using some template tricks

c++
templates
c++11

Just for the sake of completeness. Here a version which does not use macros, but does not use templates either.

Again O(1) and again fast compile times and small image size. And again, one time run time initialization in the range of microseconds.

Sorry if I misunderstood the question. To me it is about how to deal with the association between the large enum and test functions, just as the title says. To me it is not an exercise in meta programming.

To get rid of the throw, of course it is always possible to remove operator() and add a function taking the enum id as an additional parameter.

#include <iostream>
#include <vector>

typedef size_t Instr;

typedef enum Foo
{
    I_INVALID = 0
,   F_1 // for lack of better names... could as well be foo bar baz...
,   F_2
,   I_LAST_INSTRUCTION = 20
} Foo_t;

typedef void(*TestFunction_t)(std::vector<Instr> &, bool);

void Test1(std::vector<Instr>& l, bool b)
{
    const Foo_t ID = F_1;

    std::cout << "testing instruction #" << ID << std::endl;
}


void Test2(std::vector<Instr> & l, bool b)
{
    const Foo_t ID = F_2;

    std::cout << "testing instruction #" << ID << std::endl;
}


class Associator
{
public:
    static TestFunction_t s_functions[I_LAST_INSTRUCTION];
    static bool s_initialized;

    static inline void associate(size_t id, TestFunction_t fun)
    {
        s_functions[id] = fun;
    }

    Associator()
    {   
        // Only first instance runs the code below..
        // Does not look as if but it IS thread safe.
        // Why? Even if multiple threads race here, 
        // they all write the same values.
        if ( !s_initialized )
        {  
            s_initialized = true;

            // Add one line per test function.
            // Cannot see how to do without associating
            // the enum value with a function.
            associate(F_1, Test1);
            associate(F_2, Test2);
        }
    }

    TestFunction_t operator() (size_t id)
    {
        if (NULL == s_functions[id])
            throw std::invalid_argument("No function for this id.");
        return s_functions[id];
    }
};

TestFunction_t Associator::s_functions[I_LAST_INSTRUCTION] =
{
    0
};
bool Associator::s_initialized = false;


int main(int argc, const char * argv)
{
    Associator assoc; 

    std::vector<Instr> whatever;
    assoc(F_1)(whatever, true);
    assoc(F_2)(whatever, true);

    return 0;
}
answered on Stack Overflow Jan 18, 2015 by BitTickler • edited Jan 18, 2015 by BitTickler

Comments

Leave a comment

(plain text only)

Sources

  1. https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/bug-check-code-reference2
  2. https://msdn.microsoft.com/en-us/library/cc231198.aspx
  3. winerror.h from Windows SDK 10.0.14393.0

User contributions licensed under CC BY-SA 3.0