diff -ur a/configure.ac b/configure.ac
--- a/configure.ac	2011-10-14 19:43:58.000000000 -0500
+++ b/configure.ac	2012-12-20 01:04:11.232114517 -0600
@@ -75,13 +75,13 @@
        not clang
 #endif
 ]])],
-[CLANG=yes], [CLANG=no])
+[acv_mesa_CLANG=yes], [acv_mesa_CLANG=no])
 
-AC_MSG_RESULT([$CLANG])
+AC_MSG_RESULT([$acv_mesa_CLANG])
 
 dnl If we're using GCC, make sure that it is at least version 3.3.0.  Older
 dnl versions are explictly not supported.
-if test "x$GCC" = xyes -a "x$CLANG" = xno; then
+if test "x$GCC" = xyes -a "x$acv_mesa_CLANG" = xno; then
     AC_MSG_CHECKING([whether gcc version is sufficient])
     major=0
     minor=0
diff -ur a/docs/news.html b/docs/news.html
--- a/docs/news.html	2011-11-22 19:09:52.000000000 -0600
+++ b/docs/news.html	2012-12-20 01:04:11.233114517 -0600
@@ -11,6 +11,16 @@
 <H1>News</H1>
 
 
+<h2>November 27, 2011</h2>
+
+<p>
+<a href="relnotes-7.11.2.html">Mesa 7.11.2</a> is released.
+This release was made primarily to fix build problems with 7.11.1 on
+Mandriva and to fix problems related to glCopyTexImage to
+luminance-alpha textures.  That later was believed to have been fixed
+in 7.11.1 but was not.
+</p>
+
 <h2>November 17, 2011</h2>
 
 <p>
diff -ur a/docs/relnotes-7.11.2.html b/docs/relnotes-7.11.2.html
--- a/docs/relnotes-7.11.2.html	2011-11-27 16:05:01.000000000 -0600
+++ b/docs/relnotes-7.11.2.html	2012-12-20 01:04:11.235114517 -0600
@@ -28,7 +28,12 @@
 
 <h2>MD5 checksums</h2>
 <pre>
-TBD
+b9e84efee3931c0acbccd1bb5a860554  MesaLib-7.11.2.tar.gz
+0837c52698fe3252369c3fdb5195afcc  MesaLib-7.11.2.tar.bz2
+141273c274d12e0d2bafb497fe937da3  MesaLib-7.11.2.zip
+39ae9926794794503815ffdc069521eb  MesaGLUT-7.11.2.tar.gz
+35ca3a0b54cb6f9d2e0e4eae8f6bb95e  MesaGLUT-7.11.2.tar.bz2
+f8705fcff2510b6c39cd27b575c05dba  MesaGLUT-7.11.2.zip
 </pre>
 
 <h2>New features</h2>
diff -ur a/docs/relnotes.html b/docs/relnotes.html
--- a/docs/relnotes.html	2011-11-22 19:09:52.000000000 -0600
+++ b/docs/relnotes.html	2012-12-20 01:04:11.237114517 -0600
@@ -13,6 +13,7 @@
 </p>
 
 <UL>
+<LI><A HREF="relnotes-7.11.2.html">7.11.2 release notes</A>
 <LI><A HREF="relnotes-7.11.1.html">7.11.1 release notes</A>
 <LI><A HREF="relnotes-7.11.html">7.11 release notes</A>
 <LI><A HREF="relnotes-7.10.3.html">7.10.3 release notes</A>
diff -ur a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
--- a/src/gallium/auxiliary/draw/draw_llvm.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/auxiliary/draw/draw_llvm.c	2012-12-20 01:04:11.238114517 -0600
@@ -96,7 +96,7 @@
  * Create LLVM type for struct draw_jit_texture
  */
 static LLVMTypeRef
-create_jit_texture_type(struct gallivm_state *gallivm)
+create_jit_texture_type(struct gallivm_state *gallivm, const char *struct_name)
 {
    LLVMTargetDataRef target = gallivm->target;
    LLVMTypeRef texture_type;
@@ -120,13 +120,21 @@
    elem_types[DRAW_JIT_TEXTURE_BORDER_COLOR] = 
       LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
 
+#if HAVE_LLVM >= 0x0300
+   texture_type = LLVMStructCreateNamed(gallivm->context, struct_name);
+   LLVMStructSetBody(texture_type, elem_types,
+                     Elements(elem_types), 0);
+#else
    texture_type = LLVMStructTypeInContext(gallivm->context, elem_types,
                                           Elements(elem_types), 0);
 
+   LLVMAddTypeName(gallivm->module, struct_name, texture_type);
+
    /* Make sure the target's struct layout cache doesn't return
     * stale/invalid data.
     */
    LLVMInvalidateStructLayout(gallivm->target, texture_type);
+#endif
 
    LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, width,
                           target, texture_type,
@@ -176,7 +184,7 @@
  */
 static LLVMTypeRef
 create_jit_context_type(struct gallivm_state *gallivm,
-                        LLVMTypeRef texture_type)
+                        LLVMTypeRef texture_type, const char *struct_name)
 {
    LLVMTargetDataRef target = gallivm->target;
    LLVMTypeRef float_type = LLVMFloatTypeInContext(gallivm->context);
@@ -189,11 +197,17 @@
    elem_types[3] = LLVMPointerType(float_type, 0); /* viewport */
    elem_types[4] = LLVMArrayType(texture_type,
                                  PIPE_MAX_VERTEX_SAMPLERS); /* textures */
-
+#if HAVE_LLVM >= 0x0300
+   context_type = LLVMStructCreateNamed(gallivm->context, struct_name);
+   LLVMStructSetBody(context_type, elem_types,
+                     Elements(elem_types), 0);
+#else
    context_type = LLVMStructTypeInContext(gallivm->context, elem_types,
                                           Elements(elem_types), 0);
+   LLVMAddTypeName(gallivm->module, struct_name, context_type);
 
    LLVMInvalidateStructLayout(gallivm->target, context_type);
+#endif
 
    LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, vs_constants,
                           target, context_type, 0);
@@ -215,7 +229,7 @@
  * Create LLVM type for struct pipe_vertex_buffer
  */
 static LLVMTypeRef
-create_jit_vertex_buffer_type(struct gallivm_state *gallivm)
+create_jit_vertex_buffer_type(struct gallivm_state *gallivm, const char *struct_name)
 {
    LLVMTargetDataRef target = gallivm->target;
    LLVMTypeRef elem_types[3];
@@ -225,10 +239,17 @@
    elem_types[1] = LLVMInt32TypeInContext(gallivm->context);
    elem_types[2] = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0); /* vs_constants */
 
+#if HAVE_LLVM >= 0x0300
+   vb_type = LLVMStructCreateNamed(gallivm->context, struct_name);
+   LLVMStructSetBody(vb_type, elem_types,
+                     Elements(elem_types), 0);
+#else
    vb_type = LLVMStructTypeInContext(gallivm->context, elem_types,
                                      Elements(elem_types), 0);
+   LLVMAddTypeName(gallivm->module, struct_name, vb_type);
 
    LLVMInvalidateStructLayout(gallivm->target, vb_type);
+#endif
 
    LP_CHECK_MEMBER_OFFSET(struct pipe_vertex_buffer, stride,
                           target, vb_type, 0);
@@ -258,10 +279,17 @@
    elem_types[1]  = LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
    elem_types[2]  = LLVMArrayType(elem_types[1], data_elems);
 
+#if HAVE_LLVM >= 0x0300
+   vertex_header = LLVMStructCreateNamed(gallivm->context, struct_name);
+   LLVMStructSetBody(vertex_header, elem_types,
+                     Elements(elem_types), 0);
+#else
    vertex_header = LLVMStructTypeInContext(gallivm->context, elem_types,
                                            Elements(elem_types), 0);
+   LLVMAddTypeName(gallivm->module, struct_name, vertex_header);
 
    LLVMInvalidateStructLayout(gallivm->target, vertex_header);
+#endif
 
    /* these are bit-fields and we can't take address of them
       LP_CHECK_MEMBER_OFFSET(struct vertex_header, clipmask,
@@ -284,8 +312,6 @@
                           target, vertex_header,
                           DRAW_JIT_VERTEX_DATA);
 
-   LLVMAddTypeName(gallivm->module, struct_name, vertex_header);
-
    return vertex_header;
 }
 
@@ -299,19 +325,15 @@
    struct gallivm_state *gallivm = llvm->gallivm;
    LLVMTypeRef texture_type, context_type, buffer_type, vb_type;
 
-   texture_type = create_jit_texture_type(gallivm);
-   LLVMAddTypeName(gallivm->module, "texture", texture_type);
+   texture_type = create_jit_texture_type(gallivm, "texture");
 
-   context_type = create_jit_context_type(gallivm, texture_type);
-   LLVMAddTypeName(gallivm->module, "draw_jit_context", context_type);
+   context_type = create_jit_context_type(gallivm, texture_type, "draw_jit_context");
    llvm->context_ptr_type = LLVMPointerType(context_type, 0);
 
    buffer_type = LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 8), 0);
-   LLVMAddTypeName(gallivm->module, "buffer", buffer_type);
    llvm->buffer_ptr_type = LLVMPointerType(buffer_type, 0);
 
-   vb_type = create_jit_vertex_buffer_type(gallivm);
-   LLVMAddTypeName(gallivm->module, "pipe_vertex_buffer", vb_type);
+   vb_type = create_jit_vertex_buffer_type(gallivm, "pipe_vertex_buffer");
    llvm->vb_ptr_type = LLVMPointerType(vb_type, 0);
 }
 
diff -ur a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp	2012-12-20 01:04:11.239114517 -0600
@@ -27,17 +27,23 @@
 
 #include <llvm-c/Core.h>
 #include <llvm/Target/TargetMachine.h>
-#include <llvm/Target/TargetRegistry.h>
-#include <llvm/Target/TargetSelect.h>
 #include <llvm/Target/TargetInstrInfo.h>
 #include <llvm/Support/raw_ostream.h>
 #include <llvm/Support/MemoryObject.h>
 
+#if HAVE_LLVM >= 0x0300
+#include <llvm/Support/TargetRegistry.h>
+#include <llvm/Support/TargetSelect.h>
+#else /* HAVE_LLVM < 0x0300 */
+#include <llvm/Target/TargetRegistry.h>
+#include <llvm/Target/TargetSelect.h>
+#endif /* HAVE_LLVM < 0x0300 */
+
 #if HAVE_LLVM >= 0x0209
 #include <llvm/Support/Host.h>
-#else
+#else /* HAVE_LLVM < 0x0209 */
 #include <llvm/System/Host.h>
-#endif
+#endif /* HAVE_LLVM < 0x0209 */
 
 #if HAVE_LLVM >= 0x0207
 #include <llvm/MC/MCDisassembler.h>
@@ -193,14 +199,23 @@
 
    InitializeAllDisassemblers();
 
+#if HAVE_LLVM >= 0x0300
+   OwningPtr<const MCAsmInfo> AsmInfo(T->createMCAsmInfo(Triple));
+#else
    OwningPtr<const MCAsmInfo> AsmInfo(T->createAsmInfo(Triple));
+#endif
 
    if (!AsmInfo) {
       debug_printf("error: no assembly info for target %s\n", Triple.c_str());
       return;
    }
 
+#if HAVE_LLVM >= 0x0300
+   const MCSubtargetInfo *STI = T->createMCSubtargetInfo(Triple, sys::getHostCPUName(), "");
+   OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler(*STI));
+#else 
    OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler());
+#endif 
    if (!DisAsm) {
       debug_printf("error: no disassembler for target %s\n", Triple.c_str());
       return;
@@ -213,7 +228,11 @@
 #else
    int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
 #endif
-#if HAVE_LLVM >= 0x0208
+
+#if HAVE_LLVM >= 0x0300
+   OwningPtr<MCInstPrinter> Printer(
+         T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *STI));
+#elif HAVE_LLVM >= 0x0208
    OwningPtr<MCInstPrinter> Printer(
          T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo));
 #else
@@ -253,7 +272,11 @@
 
       if (!DisAsm->getInstruction(Inst, Size, memoryObject,
                                  pc,
-                                 nulls())) {
+#if HAVE_LLVM >= 0x0300
+				  nulls(), nulls())) {
+#else
+				  nulls())) {
+#endif
          debug_printf("invalid\n");
          pc += 1;
       }
@@ -276,7 +299,9 @@
        * Print the instruction.
        */
 
-#if HAVE_LLVM >= 0x208
+#if HAVE_LLVM >= 0x0300
+      Printer->printInst(&Inst, Out, "");
+#elif HAVE_LLVM >= 0x208
       Printer->printInst(&Inst, Out);
 #else
       Printer->printInst(&Inst);
@@ -289,7 +314,11 @@
 
       pc += Size;
 
+#if HAVE_LLVM >= 0x0300
+      const MCInstrDesc &TID = TII->get(Inst.getOpcode());
+#else
       const TargetInstrDesc &TID = TII->get(Inst.getOpcode());
+#endif
 
       /*
        * Keep track of forward jumps to a nearby address.
diff -ur a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c
--- a/src/gallium/auxiliary/gallivm/lp_bld_type.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c	2012-12-20 01:04:11.240114517 -0600
@@ -325,16 +325,18 @@
       return "LLVMArrayTypeKind";
    case LLVMPointerTypeKind:
       return "LLVMPointerTypeKind";
+#if HAVE_LLVM < 0x0300
    case LLVMOpaqueTypeKind:
       return "LLVMOpaqueTypeKind";
+#endif
    case LLVMVectorTypeKind:
       return "LLVMVectorTypeKind";
    case LLVMMetadataTypeKind:
       return "LLVMMetadataTypeKind";
-   /* Only in LLVM 2.7 and later???
+#if HAVE_LLVM == 0x0207
    case LLVMUnionTypeKind:
       return "LLVMUnionTypeKind";
-   */
+#endif
    default:
       return "unknown LLVMTypeKind";
    }
diff -ur a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c
--- a/src/gallium/drivers/llvmpipe/lp_jit.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/drivers/llvmpipe/lp_jit.c	2012-12-20 01:04:11.241114517 -0600
@@ -68,10 +68,17 @@
       elem_types[LP_JIT_TEXTURE_BORDER_COLOR] = 
          LLVMArrayType(LLVMFloatTypeInContext(lc), 4);
 
+#if HAVE_LLVM >= 0x0300
+   texture_type = LLVMStructCreateNamed(gallivm->context, "texture");
+   LLVMStructSetBody(texture_type, elem_types,
+                     Elements(elem_types), 0);
+#else
       texture_type = LLVMStructTypeInContext(lc, elem_types,
                                              Elements(elem_types), 0);
+      LLVMAddTypeName(gallivm->module, "texture", texture_type);
 
       LLVMInvalidateStructLayout(gallivm->target, texture_type);
+#endif
 
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, width,
                              gallivm->target, texture_type,
@@ -112,8 +119,6 @@
 
       LP_CHECK_STRUCT_SIZE(struct lp_jit_texture,
                            gallivm->target, texture_type);
-
-      LLVMAddTypeName(gallivm->module, "texture", texture_type);
    }
 
    /* struct lp_jit_context */
@@ -129,11 +134,19 @@
       elem_types[LP_JIT_CTX_TEXTURES] = LLVMArrayType(texture_type,
                                                       PIPE_MAX_SAMPLERS);
 
+#if HAVE_LLVM >= 0x0300
+   context_type = LLVMStructCreateNamed(gallivm->context, "context");
+   LLVMStructSetBody(context_type, elem_types,
+                     Elements(elem_types), 0);
+#else
       context_type = LLVMStructTypeInContext(lc, elem_types,
                                              Elements(elem_types), 0);
 
       LLVMInvalidateStructLayout(gallivm->target, context_type);
 
+      LLVMAddTypeName(gallivm->module, "context", context_type);
+#endif
+
       LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, constants,
                              gallivm->target, context_type,
                              LP_JIT_CTX_CONSTANTS);
@@ -155,8 +168,6 @@
       LP_CHECK_STRUCT_SIZE(struct lp_jit_context,
                            gallivm->target, context_type);
 
-      LLVMAddTypeName(gallivm->module, "context", context_type);
-
       lp->jit_context_ptr_type = LLVMPointerType(context_type, 0);
    }
 
diff -ur a/src/gallium/drivers/nv50/nv50_context.c b/src/gallium/drivers/nv50/nv50_context.c
--- a/src/gallium/drivers/nv50/nv50_context.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/drivers/nv50/nv50_context.c	2012-12-20 01:04:11.242114517 -0600
@@ -60,13 +60,13 @@
 void
 nv50_default_flush_notify(struct nouveau_channel *chan)
 {
-   struct nv50_context *nv50 = chan->user_private;
+   struct nv50_screen *screen = chan->user_private;
 
-   if (!nv50)
+   if (!screen)
       return;
 
-   nouveau_fence_update(&nv50->screen->base, TRUE);
-   nouveau_fence_next(&nv50->screen->base);
+   nouveau_fence_update(&screen->base, TRUE);
+   nouveau_fence_next(&screen->base);
 }
 
 static void
@@ -100,10 +100,8 @@
 
    draw_destroy(nv50->draw);
 
-   if (nv50->screen->cur_ctx == nv50) {
-      nv50->screen->base.channel->user_private = NULL;
+   if (nv50->screen->cur_ctx == nv50)
       nv50->screen->cur_ctx = NULL;
-   }
 
    FREE(nv50);
 }
@@ -140,7 +138,6 @@
 
    if (!screen->cur_ctx)
       screen->cur_ctx = nv50;
-   screen->base.channel->user_private = nv50;
    screen->base.channel->flush_notify = nv50_default_flush_notify;
 
    nv50_init_query_functions(nv50);
diff -ur a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c
--- a/src/gallium/drivers/nv50/nv50_screen.c	2011-11-22 19:09:52.000000000 -0600
+++ b/src/gallium/drivers/nv50/nv50_screen.c	2012-12-20 01:04:11.243114517 -0600
@@ -215,6 +215,8 @@
       nouveau_fence_wait(screen->base.fence.current);
       nouveau_fence_ref (NULL, &screen->base.fence.current);
    }
+   if (screen->base.channel)
+      screen->base.channel->user_private = NULL;
 
    nouveau_bo_ref(NULL, &screen->code);
    nouveau_bo_ref(NULL, &screen->tls_bo);
@@ -304,6 +306,7 @@
       FAIL_SCREEN_INIT("nouveau_screen_init failed: %d\n", ret);
 
    chan = screen->base.channel;
+   chan->user_private = screen;
 
    pscreen->winsys = ws;
    pscreen->destroy = nv50_screen_destroy;
diff -ur a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c
--- a/src/gallium/drivers/nv50/nv50_state_validate.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/drivers/nv50/nv50_state_validate.c	2012-12-20 01:04:11.243114517 -0600
@@ -282,8 +282,7 @@
    if (!ctx_to->zsa)
       ctx_to->dirty &= ~NV50_NEW_ZSA;
 
-   ctx_to->screen->base.channel->user_private = ctx_to->screen->cur_ctx =
-      ctx_to;
+   ctx_to->screen->cur_ctx = ctx_to;
 }
 
 static struct state_validate {
diff -ur a/src/gallium/drivers/nv50/nv50_vbo.c b/src/gallium/drivers/nv50/nv50_vbo.c
--- a/src/gallium/drivers/nv50/nv50_vbo.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/drivers/nv50/nv50_vbo.c	2012-12-20 01:04:11.244114516 -0600
@@ -389,11 +389,11 @@
 static void
 nv50_draw_vbo_flush_notify(struct nouveau_channel *chan)
 {
-   struct nv50_context *nv50 = chan->user_private;
+   struct nv50_screen *screen = chan->user_private;
 
-   nouveau_fence_update(&nv50->screen->base, TRUE);
+   nouveau_fence_update(&screen->base, TRUE);
 
-   nv50_bufctx_emit_relocs(nv50);
+   nv50_bufctx_emit_relocs(screen->cur_ctx);
 }
 
 static void
@@ -650,7 +650,6 @@
    nv50_state_validate(nv50);
 
    chan->flush_notify = nv50_draw_vbo_flush_notify;
-   chan->user_private = nv50;
 
    if (nv50->vbo_fifo) {
       nv50_push_vbo(nv50, info);
diff -ur a/src/gallium/drivers/nvc0/nvc0_context.c b/src/gallium/drivers/nvc0/nvc0_context.c
--- a/src/gallium/drivers/nvc0/nvc0_context.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/drivers/nvc0/nvc0_context.c	2012-12-20 01:04:11.245114516 -0600
@@ -89,10 +89,8 @@
 
    draw_destroy(nvc0->draw);
 
-   if (nvc0->screen->cur_ctx == nvc0) {
-      nvc0->screen->base.channel->user_private = NULL;
+   if (nvc0->screen->cur_ctx == nvc0)
       nvc0->screen->cur_ctx = NULL;
-   }
 
    FREE(nvc0);
 }
@@ -100,13 +98,13 @@
 void
 nvc0_default_flush_notify(struct nouveau_channel *chan)
 {
-   struct nvc0_context *nvc0 = chan->user_private;
+   struct nvc0_screen *screen = chan->user_private;
 
-   if (!nvc0)
+   if (!screen)
       return;
 
-   nouveau_fence_update(&nvc0->screen->base, TRUE);
-   nouveau_fence_next(&nvc0->screen->base);
+   nouveau_fence_update(&screen->base, TRUE);
+   nouveau_fence_next(&screen->base);
 }
 
 struct pipe_context *
@@ -141,7 +139,6 @@
 
    if (!screen->cur_ctx)
       screen->cur_ctx = nvc0;
-   screen->base.channel->user_private = nvc0;
    screen->base.channel->flush_notify = nvc0_default_flush_notify;
 
    nvc0_init_query_functions(nvc0);
diff -ur a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c
--- a/src/gallium/drivers/nvc0/nvc0_screen.c	2011-11-22 19:09:52.000000000 -0600
+++ b/src/gallium/drivers/nvc0/nvc0_screen.c	2012-12-20 01:04:11.246114516 -0600
@@ -198,8 +198,12 @@
 {
    struct nvc0_screen *screen = nvc0_screen(pscreen);
 
-   nouveau_fence_wait(screen->base.fence.current);
-   nouveau_fence_ref(NULL, &screen->base.fence.current);
+   if (screen->base.fence.current) {
+      nouveau_fence_wait(screen->base.fence.current);
+      nouveau_fence_ref(NULL, &screen->base.fence.current);
+   }
+   if (screen->base.channel)
+      screen->base.channel->user_private = NULL;
 
    nouveau_bo_ref(NULL, &screen->text);
    nouveau_bo_ref(NULL, &screen->tls);
@@ -362,6 +366,7 @@
       return NULL;
    }
    chan = screen->base.channel;
+   chan->user_private = screen;
 
    pscreen->winsys = ws;
    pscreen->destroy = nvc0_screen_destroy;
diff -ur a/src/gallium/drivers/nvc0/nvc0_state_validate.c b/src/gallium/drivers/nvc0/nvc0_state_validate.c
--- a/src/gallium/drivers/nvc0/nvc0_state_validate.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/drivers/nvc0/nvc0_state_validate.c	2012-12-20 01:04:11.247114516 -0600
@@ -428,8 +428,7 @@
    if (!ctx_to->zsa)
       ctx_to->dirty &= ~NVC0_NEW_ZSA;
 
-   ctx_to->screen->base.channel->user_private = ctx_to->screen->cur_ctx =
-      ctx_to;
+   ctx_to->screen->cur_ctx = ctx_to;
 }
 
 static struct state_validate {
diff -ur a/src/gallium/drivers/nvc0/nvc0_vbo.c b/src/gallium/drivers/nvc0/nvc0_vbo.c
--- a/src/gallium/drivers/nvc0/nvc0_vbo.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/gallium/drivers/nvc0/nvc0_vbo.c	2012-12-20 01:04:11.248114516 -0600
@@ -367,11 +367,11 @@
 static void
 nvc0_draw_vbo_flush_notify(struct nouveau_channel *chan)
 {
-   struct nvc0_context *nvc0 = chan->user_private;
+   struct nvc0_screen *screen = chan->user_private;
 
-   nouveau_fence_update(&nvc0->screen->base, TRUE);
+   nouveau_fence_update(&screen->base, TRUE);
 
-   nvc0_bufctx_emit_relocs(nvc0);
+   nvc0_bufctx_emit_relocs(screen->cur_ctx);
 }
 
 static void
@@ -587,7 +587,6 @@
    nvc0_state_validate(nvc0);
 
    chan->flush_notify = nvc0_draw_vbo_flush_notify;
-   chan->user_private = nvc0;
 
    if (nvc0->vbo_fifo) {
       nvc0_push_vbo(nvc0, info);
diff -ur a/src/glsl/ast.h b/src/glsl/ast.h
--- a/src/glsl/ast.h	2011-10-14 19:43:58.000000000 -0500
+++ b/src/glsl/ast.h	2012-12-20 01:04:11.249114516 -0600
@@ -372,7 +372,7 @@
     * \note
     * This field is only valid if \c explicit_location is set.
     */
-   unsigned location;
+   int location;
 
    /**
     * Return true if and only if an interpolation qualifier is present.
diff -ur a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
--- a/src/glsl/ast_to_hir.cpp	2011-10-14 19:43:58.000000000 -0500
+++ b/src/glsl/ast_to_hir.cpp	2012-12-20 01:04:11.250114516 -0600
@@ -1140,7 +1140,7 @@
 	 error_emitted = true;
       }
 
-      type = op[0]->type;
+      type = error_emitted ? glsl_type::error_type : op[0]->type;
       result = new(ctx) ir_expression(ir_unop_bit_not, type, op[0], NULL);
       break;
 
diff -ur a/src/glsl/lower_vec_index_to_swizzle.cpp b/src/glsl/lower_vec_index_to_swizzle.cpp
--- a/src/glsl/lower_vec_index_to_swizzle.cpp	2011-10-14 18:58:44.000000000 -0500
+++ b/src/glsl/lower_vec_index_to_swizzle.cpp	2012-12-20 01:04:11.251114516 -0600
@@ -33,6 +33,7 @@
 #include "ir_visitor.h"
 #include "ir_optimization.h"
 #include "glsl_types.h"
+#include "main/macros.h"
 
 /**
  * Visitor class for replacing expressions with ir_constant values.
@@ -76,8 +77,25 @@
 
    void *ctx = ralloc_parent(ir);
    this->progress = true;
-   return new(ctx) ir_swizzle(deref->array,
-			      ir_constant->value.i[0], 0, 0, 0, 1);
+
+   /* Page 40 of the GLSL 1.20 spec says:
+    *
+    *     "When indexing with non-constant expressions, behavior is undefined
+    *     if the index is negative, or greater than or equal to the size of
+    *     the vector."
+    *
+    * The quoted spec text mentions non-constant expressions, but this code
+    * operates on constants.  These constants are the result of non-constant
+    * expressions that have been optimized to constants.  The common case here
+    * is a loop counter from an unrolled loop that is used to index a vector.
+    *
+    * The ir_swizzle constructor gets angry if the index is negative or too
+    * large.  For simplicity sake, just clamp the index to [0, size-1].
+    */
+   const int i = MIN2(MAX2(ir_constant->value.i[0], 0),
+		      (deref->array->type->vector_elements - 1));
+
+   return new(ctx) ir_swizzle(deref->array, i, 0, 0, 0, 1);
 }
 
 ir_visitor_status
diff -ur a/src/glw/GLwDrawA.c b/src/glw/GLwDrawA.c
--- a/src/glw/GLwDrawA.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/glw/GLwDrawA.c	2012-12-20 01:04:11.252114516 -0600
@@ -270,7 +270,7 @@
 static XtResource otherColorResources[] = {
   {XmNforeground,XmCForeground,XmRPixel, 
    sizeof(Pixel),XtOffset(GLwDrawingAreaWidget,primitive.foreground),
-   XmRString,(XtPointer)"lighgrey"},
+   XmRString,(XtPointer)"lightgrey"},
    /*XmRCallProc, (XtPointer) _XmForegroundColorDefault},*/
 
   {XmNhighlightColor,XmCHighlightColor,XmRPixel,sizeof(Pixel),
diff -ur a/src/glx/apple/apple_glx_drawable.c b/src/glx/apple/apple_glx_drawable.c
--- a/src/glx/apple/apple_glx_drawable.c	2010-05-14 17:47:04.000000000 -0500
+++ b/src/glx/apple/apple_glx_drawable.c	2012-12-20 01:04:11.253114516 -0600
@@ -135,6 +135,7 @@
 static bool
 destroy_drawable(struct apple_glx_drawable *d)
 {
+   int err;
 
    d->lock(d);
 
@@ -172,6 +173,15 @@
 
    apple_glx_diagnostic("%s: freeing %p\n", __func__, (void *) d);
 
+   /* Stupid recursive locks */
+   while (pthread_mutex_unlock(&d->mutex) == 0);
+
+   err = pthread_mutex_destroy(&d->mutex);
+   if (err) {
+      fprintf(stderr, "pthread_mutex_destroy error: %s\n", strerror(err));
+      abort();
+   }
+   
    free(d);
 
    /* So that the locks are balanced and the caller correctly unlocks. */
diff -ur a/src/glx/apple/apple_glx_surface.c b/src/glx/apple/apple_glx_surface.c
--- a/src/glx/apple/apple_glx_surface.c	2011-11-22 19:09:52.000000000 -0600
+++ b/src/glx/apple/apple_glx_surface.c	2012-12-20 01:04:11.254114516 -0600
@@ -206,6 +206,7 @@
    if (d) {
       d->types.surface.pending_destroy = true;
       d->release(d);
+
       /* 
        * We release 2 references to the surface.  One was acquired by
        * the find, and the other was leftover from a context, or 
@@ -216,8 +217,9 @@
        * to actually destroy it when the pending_destroy is processed
        * by a glViewport callback (see apple_glx_context_update()).
        */
-      d->destroy(d);
-
-      d->unlock(d);
+      if (!d->destroy(d)) {
+          /* apple_glx_drawable_find_by_uid returns a locked drawable */
+          d->unlock(d);
+      }
    }
 }
diff -ur a/src/glx/apple/apple_visual.c b/src/glx/apple/apple_visual.c
--- a/src/glx/apple/apple_visual.c	2011-07-08 20:37:10.000000000 -0500
+++ b/src/glx/apple/apple_visual.c	2012-12-20 01:04:11.255114516 -0600
@@ -116,7 +116,7 @@
       *uses_stereo = false;
    }
 
-   if (mode->doubleBufferMode) {
+   if (!offscreen && mode->doubleBufferMode) {
       attr[numattr++] = kCGLPFADoubleBuffer;
       *double_buffered = true;
    }
diff -ur a/src/mapi/glapi/glapi_gentable.c b/src/mapi/glapi/glapi_gentable.c
--- a/src/mapi/glapi/glapi_gentable.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/mapi/glapi/glapi_gentable.c	2012-12-20 01:04:11.257114516 -0600
@@ -77,7 +77,7 @@
 
 struct _glapi_table *
 _glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
-    struct _glapi_table *disp = calloc(1, sizeof(struct _glapi_table));
+    struct _glapi_table *disp = calloc(_glapi_get_dispatch_table_size(), sizeof(void *));
     char symboln[512];
 
     if(!disp)
diff -ur a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c	2012-12-20 01:04:11.258114516 -0600
@@ -283,10 +283,10 @@
 
    surf[1] = bo->offset; /* reloc */
 
-   surf[2] = (((w & 0x7f) - 1) << BRW_SURFACE_WIDTH_SHIFT |
-	      (((w >> 7) & 0x1fff) - 1) << BRW_SURFACE_HEIGHT_SHIFT);
+   surf[2] = ((w & 0x7f) << BRW_SURFACE_WIDTH_SHIFT |
+	      ((w >> 7) & 0x1fff) << BRW_SURFACE_HEIGHT_SHIFT);
 
-   surf[3] = ((((w >> 20) & 0x7f) - 1) << BRW_SURFACE_DEPTH_SHIFT |
+   surf[3] = (((w >> 20) & 0x7f) << BRW_SURFACE_DEPTH_SHIFT |
 	      (width * 16 - 1) << BRW_SURFACE_PITCH_SHIFT);
 
    surf[4] = 0;
diff -ur a/src/mesa/drivers/dri/i965/gen7_viewport_state.c b/src/mesa/drivers/dri/i965/gen7_viewport_state.c
--- a/src/mesa/drivers/dri/i965/gen7_viewport_state.c	2011-10-14 19:43:58.000000000 -0500
+++ b/src/mesa/drivers/dri/i965/gen7_viewport_state.c	2012-12-20 01:04:11.259114516 -0600
@@ -36,7 +36,7 @@
    const GLfloat *v = ctx->Viewport._WindowMap.m;
    struct gen7_sf_clip_viewport *vp;
 
-   vp = brw_state_batch(brw, sizeof(vp), 64, &brw->sf.vp_offset);
+   vp = brw_state_batch(brw, sizeof(*vp), 64, &brw->sf.vp_offset);
    /* Also assign to clip.vp_offset in case something uses it. */
    brw->clip.vp_offset = brw->sf.vp_offset;
 
diff -ur a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
--- a/src/mesa/drivers/dri/intel/intel_screen.c	2011-11-22 19:10:52.000000000 -0600
+++ b/src/mesa/drivers/dri/intel/intel_screen.c	2012-12-20 01:04:11.260114516 -0600
@@ -108,13 +108,15 @@
    GET_CURRENT_CONTEXT(ctx);
    struct intel_context *intel = intel_context(ctx);
 
-   if (intel->gen < 4)
-      INTEL_FIREVERTICES(intel);
+   if (intel != NULL) {
+      if (intel->gen < 4)
+	 INTEL_FIREVERTICES(intel);
 
-   intel->need_throttle = GL_TRUE;
+      intel->need_throttle = GL_TRUE;
 
-   if (intel->batch.used)
-      intel_batchbuffer_flush(intel);
+      if (intel->batch.used)
+	 intel_batchbuffer_flush(intel);
+   }
 }
 
 static const struct __DRI2flushExtensionRec intelFlushExtension = {
diff -ur a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
--- a/src/mesa/main/texgetimage.c	2011-11-22 19:09:52.000000000 -0600
+++ b/src/mesa/main/texgetimage.c	2012-12-20 01:04:11.261114516 -0600
@@ -713,6 +713,9 @@
    texObj = _mesa_get_current_tex_object(ctx, target);
    texImage = _mesa_select_tex_image(ctx, texObj, target, level);
 
+   if (_mesa_is_zero_size_texture(texImage))
+      return;
+
    if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
       _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
                   " dstFmt=0x%x, dstType=0x%x\n",
@@ -846,6 +849,9 @@
    texObj = _mesa_get_current_tex_object(ctx, target);
    texImage = _mesa_select_tex_image(ctx, texObj, target, level);
 
+   if (_mesa_is_zero_size_texture(texImage))
+      return;
+
    if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
       _mesa_debug(ctx,
                   "glGetCompressedTexImage(tex %u) format = %s, w=%d, h=%d\n",
diff -ur a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
--- a/src/mesa/main/teximage.h	2011-10-14 19:43:58.000000000 -0500
+++ b/src/mesa/main/teximage.h	2012-12-20 01:04:11.262114516 -0600
@@ -42,6 +42,14 @@
 extern void
 _mesa_free_texmemory(void *m);
 
+/** Is any of the dimensions of given texture equal to zero? */
+static inline GLboolean
+_mesa_is_zero_size_texture(const struct gl_texture_image *texImage)
+{
+   return (texImage->Width == 0 ||
+           texImage->Height == 0 ||
+           texImage->Depth == 0);
+}
 
 /** \name Internal functions */
 /*@{*/
