Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 17 May 2007
Offline Last Active Nov 04 2013 05:53 PM

Posts I've Made

In Topic: Flat hash containers

23 February 2013 - 05:48 AM

In response to your first question, about submission to boost:


The work you will have to do to get your library to the point of submission (assuming there's sufficient interest -- ask on the boost mailing list) includes:

  • provide documentation in a manner consistent with boost's style and infrastructure
  • ditto for tests
  • ditto for build scripts
  • modifying your code to use boost's portability macros/conventions
  • getting it to build and perform well on platforms that you may have little or no experience with. I'm almost certain that you will be required to provide a version that builds cleanly on POSIX systems such as Linux and OS X.

Libraries undergoing submission are assigned a review manager. At some point, your library will be reviewed publicly on the boost mailing list. It can take quite a long time, depending on interest, to get your library through the review backlog.


Once the review starts, a lot of people will tear your code apart, often with little or no tact. So make sure you're comfortable with criticism. Revisions will probably have to be made to what you have now until people are satisfied. I haven't looked at your code, it's just what usually happens.


Assuming submission is successful, you will have to maintain your library for the foreseeable future. This will probably mean:

  • familiarizing yourself with boost's release process
  • responding to bug reports, even those where you don't have access to a similar system to that of the reporter. Of course, this is true wherever you 'publish' your code, but the exposure provided by boost will mean more bugs reported (even if they're invalid).
  • there's talk on the mailing list of boost moving to a new version control/modularization/distribution system soon, too. So you will almost certainly have more maintenance work to do in future.
  • More generally, you will have to stay up to date with boost's infrastructure changes, just to keep your library's head above water. 


Exposure is nice of course, but submission to boost isn't a one-shot thing.

In Topic: Turn a non reentrant C library into a library supporting several instances of...

03 February 2013 - 06:54 AM

The best way is to fix the library so that each function takes some kind of 'context' structure, in to which all the global state is moved. Multiple context structures would allow multiple clients in the same process.


Loading a library twice (at distinct locations in virtual memory) may be possible, but it will be highly platform dependent. What platform(s) do you care about?


It's possible to write a non-intrusive wrapper, as long as you have a true static library (not a stub) and are willing to find all global state. In this case you will have to:

  1. Create a context structure with one member for each piece of global state. 
  2. Create init_context(context *ctx) that initializes a context in the same way that the global state is initialized.
  3. Create get_current_context(context *ctx) and set_current_context(const context *ctx) functions that get and set the current global state
  4. Add a global mutex if you want to use this in a multithreaded environment.
  5. Now wrap each function, f, as follows:

return_type wrapped_f(context *ctx, type1 arg1, type2 arg2, type3 arg3, etc)
    context old_ctx;
    return_type ret = f(arg1, arg2, arg3, etc);
    return ret;


An RAII-style class could automate the locking and context swapping. I admit it's ugly and you'll still have to take care to look for new global state to add to the context structure whenever the underlying library is changed, but it's probably all you can do without modifying the library.

In Topic: Best Method For Writing Unit Tests

19 January 2013 - 07:30 PM

IMHO, tests should really only use the public members of a class. You shouldn't need to add any kind of "hooks" for testing.

If you feel the need to add extra functionality purely for testing, it could be a hint that you've violated what's often called the Single Responsibility Principle.


I'm not an advocate of TDD, but when using this methodology, private methods arise naturally as part of the 'refactoring' steps and so will be automatically exercised by the tests.


As for how to structure unit tests, look at the examples of existing libraries/frameworks. googletest and unittest++ are two popular ones, though there are countless others.

In Topic: Accessing a Devices Interface/Class GUID always causes an error

05 January 2013 - 07:56 AM

MSDN says that lParam is 0 when wParam is DBT_DEVNODES_CHANGED (which IMHO, you should really assert on anyway). So your code behaves as expected -- undefined behaviour.


It appears you have copied the GUID passed to RegisterDeviceNotification from the MSDN example code. I don't know much about Windows' device handling but I have a strong suspicion that this GUID is not the one you should be using.


Have you tried adding DEVICE_NOTIFY_ALL_INTERFACE_CLASSES to the flags in your call to RegisterDeviceNotification()? In this case the GUID is ignored and you get messages for all devices. This may give you a better indication of what's really happening and help you detect your TV.


Just out of curiosity, are you attempting to detect your telly to automatically enable some kind of out-of-band debug console for a game? That would be cool :)

In Topic: Accessing a Devices Interface/Class GUID always causes an error

05 January 2013 - 12:17 AM

Have you checked wparam? If it's something like DBT_DEVICEREMOVECOMPLETE, you're probably casting lParam to the wrong type in the first place.


In general, it's my understanding that you should always first cast lparam to a DEV_BROADCAST_HDR* and only cast to something further once you have confirmed the value of its dbch_devicetype.