+ if (context >= m->contexts_max) {
+ unsigned k, *n;
+ Window *w;
+
+ /* Increase the number of contexts if necessary, and
+ * make sure we have twice the number of windows */
+
+ k = context * 2;
+ n = realloc(m->by_context, sizeof(unsigned) * k);
+ if (!n)
+ return -ENOMEM;
+ memset(n + m->contexts_max, -1, (k - m->contexts_max) * sizeof(unsigned));
+ m->contexts_max = k;
+ m->by_context = n;
+
+ k = MAX(m->windows_max, m->contexts_max*2);
+ w = realloc(m->windows, sizeof(Window) * k);
+ if (!w)
+ return -ENOMEM;
+
+ m->windows_max = k;
+ m->windows = w;
+ }
+