Tuesday, 19 January 2016

Compile time ASSERT in 'C'

A nifty trick to get the compiler to check something the preprocessor can't grok.

{typedef int asserted[1-2*!condition];while(0==sizeof(asserted));}

The compiler can calculate array sizes based on things like enumerations that the pre-processor doesn't have access to, but will fail to parse an array declaration of negative length. No data or code is generated by this source line, just a freebie from the 'C' parser.

Monday, 6 October 2014

Jenkins continually re-triggered by SCM/git

I fixed this once and then promptly forgot what the problem was, so this time I'm writing it down :-)

I use a Unix-based Jenkins master with a Windows-based slave running Microsoft Visual Studio and other stuff that can't be run natively.

I setup my projects so that they use SCM polling and on a couple of occasions I've found that projects just rebuild ad infinitum.

My problem was that I didn't carefully follow the case of the SCM branch specified. Unix is case-sensitive and Windows is case-insensitive; it seems that the Unix part that decides if a new build is required fails-safe (and triggers a build) whereas the Windows part that checks out the source doesn't fail if the wrong case is used.

When I make the SCM Branch Specifier use the correct case everything goes back to normal.

Thursday, 18 September 2014

PICkit 2 and VirtualBox

It seems to be a perennial woe to make PICkit work with VirtualBox.

In my particular set-up, I use VMs to run guest installations of Windows XP that are specific to particular toolchains. All this runs on a Windows 7 64-bit host.

So, as discussed elsewhere PICkit and VirtualBox don't play nicely. The solution is as follows:

  1. Plug in your PICkit and open the VirtualBox Manager UI
  2. Add a USB filter and select your PICkit
  3. Edit the USB filter and leave just the Name, Vendor ID and Product ID removing all other items in the filter, particularly the Manufacturer and Serial Number
  4. Boot or Re-boot your VM, plug and un-plug your PICkit and it'll appear in your VM which will install its own HID drivers.
So I think the problem is that Windows enumerates two devices - a USB Input Device and a HID-compliant device. The default VirtualBox filter appears to be capturing one of them but not the other.

Good luck!

Friday, 28 March 2014

Patch: ddd-3.3.12 for OSX

Those battling to build ddd-3.3.12 under OSX/clang might find the following patch advantageous:

--- a/ddd/strclass.h    Fri Mar 28 09:05:06 2014 +0000
+++ b/ddd/strclass.h    Fri Mar 28 09:05:50 2014 +0000
@@ -543,6 +543,13 @@
     bool OK() const;
 };

+extern string common_prefix(const string& x, const string& y,
+                           int startpos = 0);
+extern string common_suffix(const string& x, const string& y,
+                           int startpos = -1);
+extern int readline(std::istream& s, string& x,
+                  char terminator = '\n',
+                  int discard_terminator = 1);

 class string
 {
@@ -810,10 +817,8 @@
     friend int split(const string& x, string *res, int maxn,
                     const regex& sep);

-    friend string common_prefix(const string& x, const string& y,
-                               int startpos = 0);
-    friend string common_suffix(const string& x, const string& y,
-                               int startpos = -1);
+    friend string common_prefix(const string& x, const string& y, int startpos);
+    friend string common_suffix(const string& x, const string& y, int startpos);
     friend string replicate(char c, int n);
     friend string replicate(const string& y, int n);
     friend string join(const string *src, int n, const string& sep);
@@ -864,8 +869,8 @@
     friend std::istream& operator>>(std::istream& s, string& x);

     friend int readline(std::istream& s, string& x,
-                       char terminator = '\n',
-                       int discard_terminator = 1);
+                       char terminator,
+                       int discard_terminator);

     // Status
     unsigned int length() const;

Wednesday, 12 June 2013

Windows XP Mode lost Integration Features

I use Windows XP Mode from Windows 7 Professional as sandboxes for testing and to evaluate applications (in this case, IAR Embedded Workbench which is quite good and you can use the JTAG via USB port forwarding). The advantage is that I don't pollute my 'nice' Windows 7 install will all sorts of bits & pieces and I certainly never have to 're-install the operating system'

So the way I work is that I installed Windows XP Mode, updated it to the latest service packs (which is a pain) and then saved a 'golden image' which I duplicate whenever I need to spawn a new VM.

Today, after the VM did some Microsoft Updating I found that Integration Features no longer worked - you get a dialog saying "Could Not Enable Integration Features" with options to Retry (see Einstein's definition of insanity) or Continue.

I tried re-installing Integration Features and it removed them(!). Then I tried re-re-installing Integration Features and they still don't work. Something is very badly wrong.

My solution is:

  1. Uninstall Integration Features in your VM
  2. Shutdown the VM
  3. Delete the .vmc and .vmcx files BUT NOT THE .VHD
  4. Create a new VM using the old .vhd
  5. Re-install Integration Features in your VM

and that seems to work.

A better solution would be:

  1. Install Windows XP Mode
  2. Uninstall Virtual PC
  3. Install Oracle VirtualBox
  4. Open the WindowsXP.vhd in VirtualBox

but sadly Microsoft force you to use their rather second-rate VM solution so it doesn't work.

Thursday, 13 September 2012

Python curries locals

I bloody love Python....

I needed to write some code that composes a command to modify port settings. Here's what it looked like:

def port_assign(io0="unchanged", io1="unchanged",
                io2="unchanged", io3="unchanged"):
    send("IO_ASSIGN "+" ".join([locals()["io%d"%v] for v in range(0,4)]))

so the idea is that
 port_assign()
is equivalent to
 send("IO_ASSIGN unchanged unchanged unchanged unchanged")
and
 port_assign(io2="pulldown")
is equivalent to
 send("IO_ASSIGN unchanged unchanged pulldown unchanged")

Cool.

Except it doesn't work. The problem is locals() is evaluated inside the iterator so it doesn't contain the parameters. The solution is to "curry" (partially evaluate in advance, forming a "closure") the call to locals() so that it picks up the right scope:


def port_assign(io0="unchanged", io1="unchanged",
                io2="unchanged", io3="unchanged"):
    params=locals()
    send("IO_ASSIGN "+" ".join([params["io%d"%v] for v in range(0,4)]))

Wednesday, 22 August 2012

Adding P4V to Ubuntu 12.04 Unity Launcher

The perforce visual client installation is a tar file with a bin/ and lib/ directory that you drop somewhere in your home or in /usr/local if you're installing for a machine. No repo. No updates. Very very Old School.

So I wanted to put this on my Ubuntu 12.04 LTS with Unity desktop. In order to add an application to the Launcher you need to create a file that describes the applications and points to its image.

Here's the one I made for P4V:

[Desktop Entry]
Type=Application
Name=P4V
Comment=Perforce Visual Client
Icon=/usr/local/lib/p4v/P4VResources/icons/p4v_48_high.png
Exec=/usr/local/bin/p4v
Terminal=false
Categories=Development;
  1. Copy the above into a file called p4v.desktop and put it in your ~/Desktop folder.
  2. The file is setup for /usr/local but you could edit it to point wherever you've installed P4V.
  3. Open your Desktop using the Home Folder application
  4. Drag & Drop p4v.desktop into your Launcher bar.