mount: don't create a temporary directory if /tmp exists

pivot_root requires a place where to move an old root. Currently
a temporary directory is created for that, but it doesn't
work if the / directory is read-only.

Actually we can use any existing directory. In this patch,
criu tries to use /tmp and only if it doesn't exist,
criu creates a temporary directory.

https://bugs.openvz.org/browse/OVZ-6778

v2: don't give a constant string to mkdtemp
Signed-off-by: Andrei Vagin <74c05afa918858348d6db8037d82fa8124870113@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <c9a32589e048e044184536f7ac71ef92fe82df3e@virtuozzo.com>

--- criu/mount.c
+++ criu/mount.c
@@ -2702,8 +2702,11 @@

 static int cr_pivot_root(char *root)
 {
-	char put_root[] = "crtools-put-root.XXXXXX";
+	char tmp_dir_tmpl[] = "crtools-put-root.XXXXXX";
+	bool tmp_dir = false;
+	char *put_root = "tmp";
 	int exit_code = -1;
+	struct stat st;

 	pr_info("Move the root to %s\n", root ? : ".");

@@ -2714,9 +2717,13 @@
 		}
 	}

-	if (mkdtemp(put_root) == NULL) {
-		pr_perror("Can't create a temporary directory");
-		return -1;
+	if (stat(put_root, &st) || !S_ISDIR(st.st_mode)) {
+		put_root = mkdtemp(tmp_dir_tmpl);
+		if (put_root == NULL) {
+			pr_perror("Can't create a temporary directory");
+			return -1;
+		}
+		tmp_dir = true;
 	}

 	if (mount(put_root, put_root, NULL, MS_BIND, NULL)) {
@@ -2753,7 +2760,7 @@
 	}

 err_root:
-	if (rmdir(put_root)) {
+	if (tmp_dir && rmdir(put_root)) {
 		pr_perror("Can't remove the directory %s", put_root);
 		return -1;
 	}


Set max cols required to show file info

Set max cols required to show file info

--- src/nnn.c
+++ src/nnn.c
@@ -2809,7 +2809,7 @@
 	attroff(A_UNDERLINE);

 	/* Fallback to light mode if less than 35 columns */
-	if (ncols < 35 && cfg.showdetail) {
+	if (ncols < 41 && cfg.showdetail) {
 		cfg.showdetail ^= 1;
 		printptr = &printent;
 		mode_changed = TRUE;
@@ -2817,7 +2817,7 @@

 	/* Calculate the number of cols available to print entry name */
 	if (cfg.showdetail)
-		ncols -= 30;
+		ncols -= 36;
 	else
 		ncols -= 5;


Refactoring and converting macros to inline funcs

--- src/obj.c
+++ src/obj.c
@@ -7,43 +7,53 @@

 #define MAGIC_BYTES "TOV"

-#define PUTSIZED(What,Size,Where) \
-    do { if (fwrite(&(What), (Size), 1, (Where)) != 1) goto bad; } while (0)
-#define PUT(What,Where) \
-    PUTSIZED(What, sizeof (What), Where)
+#define PUT(What,Where) put_sized(&(What), sizeof (What), Where)
+#define GET(What,Where) get_sized(&(What), sizeof (What), Where)

-#define GETSIZED(What,Size,Where) \
-    do { if (fread(&(What), (Size), 1, (Where)) != 1) goto bad; } while (0)
-#define GET(What,Where) \
-    GETSIZED(What, sizeof (What), Where)
+#define for_counted_put(Tag,Name,List,Count) \
+    for (UWord remaining = (Count); remaining > 0; remaining--) \
+        list_foreach(Tag, Name, List)
+
+static inline void get_sized(void *what, size_t size, FILE *where)
+{
+    if (fread(what, size, 1, where) != 1)
+        fatal(PRINT_ERRNO, "Unknown error in %s while parsing object", __func__);
+}
+
+static inline void put_sized(void *what, size_t size, FILE *where)
+{
+    if (fwrite(what, size, 1, where) != 1)
+        fatal(PRINT_ERRNO, "Unknown error in %s while emitting object", __func__);
+}

 static int obj_v0_write(struct obj_v0 *o, FILE *out)
 {
-    PUTSIZED(MAGIC_BYTES, 3, out);
+    put_sized(&MAGIC_BYTES, 3, out);
     PUT(o->base.magic.parsed.version, out);
     PUT(o->length, out);
     PUT(o->flags, out);
+
     PUT(o->rec_count, out);
-
-    {
-        UWord remaining = o->rec_count;
-        list_foreach(objrec, rec, o->records) {
-            if (remaining-- <= 0) break;
-            PUT(rec->addr, out);
-            PUT(rec->size, out);
-            if (fwrite(rec->data, sizeof *rec->data, rec->size, out) != rec->size)
-                goto bad;
-        }
+    for_counted_put(objrec, rec, o->records, o->rec_count) {
+        PUT(rec->addr, out);
+        PUT(rec->size, out);
+        if (fwrite(rec->data, sizeof *rec->data, rec->size, out) != rec->size)
+            goto bad;
     }

-    {
-        UWord remaining = o->sym_count;
-        list_foreach(objsym, sym, o->symbols) {
-            if (remaining-- <= 0) break;
-            PUT(sym->flags, out);
-            PUT(sym->name, out);
-            PUT(sym->value, out);
-        }
+    PUT(o->sym_count, out);
+    for_counted_put(objsym, sym, o->symbols, o->sym_count) {
+        PUT(sym->flags, out);
+        PUT(sym->name, out);
+        PUT(sym->value, out);
+    }
+
+    PUT(o->rlc_count, out);
+    for_counted_put(objrlc, rlc, o->relocs, o->rlc_count) {
+        PUT(rlc->flags, out);
+        PUT(rlc->name, out);
+        PUT(rlc->addr, out);
+        PUT(rlc->width, out);
     }

     return 0;
@@ -57,13 +67,14 @@
     switch (o->magic.parsed.version) {
         case 0: return obj_v0_write((void*)o, out);
         default:
-            goto bad;
+            fatal(0, "Unhandled version while emitting object");
+            return -1; // never reached, but keeps compiler happy
     }
+}

-bad:
-    fatal(0, "Unhandled version while emitting object");
-    return -1; // never reached, but keeps compiler happy
-}
+#define for_counted_get(Tag,Name,List,Count) \
+    for (struct Tag *_f = NULL, *_l = NULL, *Name = List = calloc(Count, sizeof *Name); (Count) && !_f; _f++) \
+        for (UWord _i = (Count); _i > 0; Name->prev = _l, _l ? (void)(_l->next = Name) : (void)0, _l = Name++, _i--)

 static int obj_v0_read(struct obj_v0 *o, size_t *size, FILE *in)
 {
@@ -71,61 +82,25 @@
     GET(o->flags, in);
     GET(o->rec_count, in);

-    {
-        UWord remaining = o->rec_count;
-        if (remaining) {
-            struct objrec *last = NULL,
-                          *rec  = o->records = calloc(remaining, sizeof *rec);
-            while (remaining-- > 0) {
-                GET(rec->addr, in);
-                GET(rec->size, in);
-                rec->data = calloc(rec->size, sizeof *rec->data);
-                if (fread(rec->data, sizeof *rec->data, rec->size, in) != rec->size)
-                    goto bad;
-
-                rec->prev = last;
-                if (last) last->next = rec;
-                last = rec;
-                rec++;
-            }
-        }
+    for_counted_get(objrec, rec, o->records, o->rec_count) {
+        GET(rec->addr, in);
+        GET(rec->size, in);
+        rec->data = calloc(rec->size, sizeof *rec->data);
+        if (fread(rec->data, sizeof *rec->data, rec->size, in) != rec->size)
+            goto bad;
     }

-    {
-        UWord remaining = o->sym_count;
-        if (remaining) {
-            struct objsym *last = NULL,
-                          *sym  = o->symbols = calloc(remaining, sizeof *sym);
-            while (remaining-- > 0) {
-                GET(sym->flags, in);
-                GET(sym->name, in);
-                GET(sym->value, in);
-
-                sym->prev = last;
-                if (last) last->next = sym;
-                last = sym;
-                sym++;
-            }
-        }
+    for_counted_get(objsym, sym, o->symbols, o->sym_count) {
+        GET(sym->flags, in);
+        GET(sym->name, in);
+        GET(sym->value, in);
     }

-    {
-        UWord remaining = o->rlc_count;
-        if (remaining) {
-            struct objrlc *last = NULL,
-                          *rlc  = o->relocs = calloc(remaining, sizeof *rlc);
-            while (remaining-- > 0) {
-                GET(rlc->flags, in);
-                GET(rlc->name, in);
-                GET(rlc->addr, in);
-                GET(rlc->width, in);
-
-                rlc->prev = last;
-                if (last) last->next = rlc;
-                last = rlc;
-                rlc++;
-            }
-        }
+    for_counted_get(objrlc, rlc, o->relocs, o->rlc_count) {
+        GET(rlc->flags, in);
+        GET(rlc->name, in);
+        GET(rlc->addr, in);
+        GET(rlc->width, in);
     }

     // TODO this isn't actually useful ; change its semantics or remove it
@@ -174,12 +149,8 @@
     switch (o->magic.parsed.version) {
         case 0: obj_v0_free((void*)o); break;
         default:
-            goto bad;
+            fatal(0, "Unknown error occurred while freeing object");
+            return; // never reached, but keeps compiler happy
     }
-
-    return;
-bad:
-    fatal(0, "Unknown error occurred while freeing object");
-    return; // never reached, but keeps compiler happy
 }


Minor changes.

Minor changes.

--- src/ocr.c
+++ src/ocr.c
@@ -133,9 +133,7 @@
 	const str_list* const langs = tess_langs();

 	// match each part separated by '+'
-	const char* lang = spec;
-
-	while(lang < spec + len)
+	for(const char* lang = spec; lang < spec + len; )
 	{
 		// next token
 		const char* end = strchr(lang, '+');
@@ -160,6 +158,11 @@

 		lang += n + 1;
 	}
+
+	// disallow other instances of '-l' option
+	for(++opt_ind; opt_ind < num_args; ++opt_ind)
+		if(strcmp(args[opt_ind], "-l") == 0)
+			die(0, "only one tesseract '-l' option is allowed");
 }

 int main(int argc, char* argv[])
@@ -172,22 +175,19 @@
 	// check if tesseract is installed
 	tess_check();

+	// check language spec
+	check_tess_lang_opt(cmd.tess_argv, cmd.tess_argc);
+
 	// get file list
 	str_list* const files = list_files(cmd.dir, cmd.spec, "pgm");

 	if(str_list_is_empty(files))
 	{
-		if(cmd.spec)
-			info("no pages found in the range \"%s\"",
-				  page_spec_to_string(cmd.spec, NULL));
-		else
-			info("no pages found");
-
-		exit(cmd.fail_on_empty ? 2 : 0);
-	}
-
-	// check language spec
-	check_tess_lang_opt(cmd.tess_argv, cmd.tess_argc);
+		if(cmd.fail_on_empty)
+			error(2, 0, "no pages found");
+
+		return 0;
+	}

 	// run OCR
 	for(size_t i = 0; i < files->len; ++i)
@@ -200,7 +200,5 @@
 		tess_extract_text(file, cmd.tess_argv, cmd.tess_argc);
 	}

-	str_list_free(files);
-
 	return 0;
 }


crypto: ctr - Use chainiv on raw counter mode

Raw counter mode only works with chainiv, which is no longer
the default IV generator on SMP machines.  This broke raw counter
mode as it can no longer instantiate as a givcipher.

This patch fixes it by always picking chainiv on raw counter
mode.  This is based on the diagnosis and a patch by Huang
Ying.

Signed-off-by: Herbert Xu <ef65de1c7be0aa837fe7b25ba9a7739905af6a55@gondor.apana.org.au>

--- crypto/ctr.c
+++ crypto/ctr.c
@@ -219,6 +219,8 @@
 	inst->alg.cra_blkcipher.encrypt = crypto_ctr_crypt;
 	inst->alg.cra_blkcipher.decrypt = crypto_ctr_crypt;

+	inst->alg.cra_blkcipher.geniv = "chainiv";
+
 out:
 	crypto_mod_put(alg);
 	return inst;


dri/common: Fix codestyle of driParseDebugString().

Reviewed-by: Iago Toral Quiroga <a847aabaac44184372f6b1cd1a59aa254daaeb0b@igalia.com>

--- src/mesa/drivers/dri/common/utils.c
+++ src/mesa/drivers/dri/common/utils.c
@@ -43,19 +43,17 @@

 uint64_t
-driParseDebugString( const char * debug,
-		     const struct dri_debug_control * control  )
+driParseDebugString(const char *debug,
+                    const struct dri_debug_control *control)
 {
    uint64_t flag = 0;

-   if ( debug != NULL ) {
-      while( control->string != NULL ) {
-	 if ( !strcmp( debug, "all" ) ||
-	      strstr( debug, control->string ) != NULL ) {
+   if (debug != NULL) {
+      for (; control->string != NULL; control++) {
+	 if (!strcmp(debug, "all") ||
+	     strstr(debug, control->string) != NULL) {
 	    flag |= control->flag;
 	 }
-
-	 control++;
       }
    }


CBLK: Adding more debug output - needs to be removed when bug is found

Signed-off-by: Frank Haverkamp <ead9589793120d6abd41dc830e46c3a946a6de96@linux.vnet.ibm.com>

--- actions/hdl_nvme_example/sw/snapblock.c
+++ actions/hdl_nvme_example/sw/snapblock.c
@@ -529,6 +529,12 @@
 			}
 			break;
 		case CACHE_BLOCK_READING:	/* do not throw this out */
+			if (e->lba == lba) {	/* entry is already in cache */
+				fprintf(stderr, "[%s] LBA=%ld is already READING!\n",
+					__func__, e->lba);
+				pthread_mutex_unlock(&entry->way_lock);
+				return NULL;	/* no entry found! */
+			}
 			break;
 		}
 	}


move TEX code into exec_tex()

move TEX code into exec_tex()

--- src/mesa/pipe/tgsi/exec/tgsi_exec.c
+++ src/mesa/pipe/tgsi/exec/tgsi_exec.c
@@ -1194,7 +1194,7 @@
              const union tgsi_exec_channel *s,
              const union tgsi_exec_channel *t,
              const union tgsi_exec_channel *p,
-             float lodbias,
+             float lodbias,  /* XXX should be float[4] */
              union tgsi_exec_channel *r,
              union tgsi_exec_channel *g,
              union tgsi_exec_channel *b,
@@ -1212,6 +1212,124 @@
       a->f[j] = rgba[3][j];
    }
 }
+
+
+static void
+exec_tex(struct tgsi_exec_machine *mach,
+         const struct tgsi_full_instruction *inst,
+         boolean biasLod)
+{
+   const uint unit = inst->FullSrcRegisters[1].SrcRegister.Index;
+   union tgsi_exec_channel r[8];
+   uint chan_index;
+   float lodBias;
+
+   switch (inst->InstructionExtTexture.Texture) {
+   case TGSI_TEXTURE_1D:
+
+      FETCH(&r[0], 0, CHAN_X);
+
+      switch (inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtDivide) {
+      case TGSI_EXTSWIZZLE_W:
+         FETCH(&r[1], 0, CHAN_W);
+         micro_div( &r[0], &r[0], &r[1] );
+         break;
+
+      case TGSI_EXTSWIZZLE_ONE:
+         break;
+
+      default:
+         assert (0);
+      }
+
+      if (biasLod) {
+         FETCH(&r[1], 0, CHAN_W);
+         lodBias = r[1].f[0];
+      }
+      else
+         lodBias = 0.0;
+
+      fetch_texel(&mach->Samplers[unit],
+                  &r[0], NULL, NULL, lodBias,  /* S, T, P, BIAS */
+                  &r[0], &r[1], &r[2], &r[3]); /* R, G, B, A */
+      break;
+
+   case TGSI_TEXTURE_2D:
+   case TGSI_TEXTURE_RECT:
+
+      FETCH(&r[0], 0, CHAN_X);
+      FETCH(&r[1], 0, CHAN_Y);
+
+      switch (inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtDivide) {
+      case TGSI_EXTSWIZZLE_W:
+         FETCH(&r[2], 0, CHAN_W);
+         micro_div( &r[0], &r[0], &r[2] );
+         micro_div( &r[1], &r[1], &r[2] );
+         break;
+
+      case TGSI_EXTSWIZZLE_ONE:
+         break;
+
+      default:
+         assert (0);
+      }
+
+      if (biasLod) {
+         FETCH(&r[1], 0, CHAN_W);
+         lodBias = r[1].f[0];
+      }
+      else
+         lodBias = 0.0;
+
+      fetch_texel(&mach->Samplers[unit],
+                  &r[0], &r[1], NULL, lodBias,
+                  &r[0], &r[1], &r[2], &r[3]);
+      break;
+
+   case TGSI_TEXTURE_3D:
+   case TGSI_TEXTURE_CUBE:
+
+      FETCH(&r[0], 0, CHAN_X);
+      FETCH(&r[1], 0, CHAN_Y);
+      FETCH(&r[2], 0, CHAN_Z);
+
+      switch (inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtDivide) {
+      case TGSI_EXTSWIZZLE_W:
+         FETCH(&r[3], 0, CHAN_W);
+         micro_div( &r[0], &r[0], &r[3] );
+         micro_div( &r[1], &r[1], &r[3] );
+         micro_div( &r[2], &r[2], &r[3] );
+         break;
+
+      case TGSI_EXTSWIZZLE_ONE:
+         break;
+
+      default:
+         assert (0);
+      }
+
+      if (biasLod) {
+         FETCH(&r[1], 0, CHAN_W);
+         lodBias = r[1].f[0];
+      }
+      else
+         lodBias = 0.0;
+
+      fetch_texel(&mach->Samplers[unit],
+                  &r[0], &r[1], &r[2], lodBias,
+                  &r[0], &r[1], &r[2], &r[3]);
+      break;
+
+   default:
+      assert (0);
+   }
+
+   FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) {
+      STORE( &r[chan_index], 0, chan_index );
+   }
+}
+
+

 static void
 constant_interpolation(
@@ -1880,91 +1998,13 @@
       break;

    case TGSI_OPCODE_TEX:
-      {
-         const GLuint unit = inst->FullSrcRegisters[1].SrcRegister.Index;
-         switch (inst->InstructionExtTexture.Texture) {
-         case TGSI_TEXTURE_1D:
-
-            FETCH(&r[0], 0, CHAN_X);
-
-            switch (inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtDivide) {
-            case TGSI_EXTSWIZZLE_W:
-               FETCH(&r[1], 0, CHAN_W);
-               micro_div( &r[0], &r[0], &r[1] );
-               break;
-
-            case TGSI_EXTSWIZZLE_ONE:
-               break;
-
-            default:
-               assert (0);
-            }
-
-            fetch_texel(&mach->Samplers[unit],
-                        &r[0], NULL, NULL, 0.0,
-                        &r[0], &r[1], &r[2], &r[3]);
-            break;
-
-         case TGSI_TEXTURE_2D:
-         case TGSI_TEXTURE_RECT:
-
-            FETCH(&r[0], 0, CHAN_X);
-            FETCH(&r[1], 0, CHAN_Y);
-
-            switch (inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtDivide) {
-            case TGSI_EXTSWIZZLE_W:
-               FETCH(&r[2], 0, CHAN_W);
-               micro_div( &r[0], &r[0], &r[2] );
-               micro_div( &r[1], &r[1], &r[2] );
-               break;
-
-            case TGSI_EXTSWIZZLE_ONE:
-               break;
-
-            default:
-               assert (0);
-            }
-
-            fetch_texel(&mach->Samplers[unit],
-                        &r[0], &r[1], NULL, 0.0,
-                        &r[0], &r[1], &r[2], &r[3]);
-            break;
-
-         case TGSI_TEXTURE_3D:
-         case TGSI_TEXTURE_CUBE:
-
-            FETCH(&r[0], 0, CHAN_X);
-            FETCH(&r[1], 0, CHAN_Y);
-            FETCH(&r[2], 0, CHAN_Z);
-
-            switch (inst->FullSrcRegisters[0].SrcRegisterExtSwz.ExtDivide) {
-            case TGSI_EXTSWIZZLE_W:
-               FETCH(&r[3], 0, CHAN_W);
-               micro_div( &r[0], &r[0], &r[3] );
-               micro_div( &r[1], &r[1], &r[3] );
-               micro_div( &r[2], &r[2], &r[3] );
-               break;
-
-            case TGSI_EXTSWIZZLE_ONE:
-               break;
-
-            default:
-               assert (0);
-            }
-
-            fetch_texel(&mach->Samplers[unit],
-                        &r[0], &r[1], &r[2], 0.0,
-                        &r[0], &r[1], &r[2], &r[3]);
-            break;
-
-         default:
-            assert (0);
-         }
-
-         FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) {
-            STORE( &r[chan_index], 0, chan_index );
-         }
-      }
+      /* src arg0 is the texcoord */
+      exec_tex(mach, inst, FALSE);
+      break;
+
+   case TGSI_OPCODE_TXB:
+      /* Texture lookup with lod bias (src0.w) */
+      exec_tex(mach, inst, TRUE);
       break;

    case TGSI_OPCODE_TXD:
@@ -2074,10 +2114,6 @@
       if( IS_CHANNEL_ENABLED( *inst, CHAN_W ) ) {
          STORE( &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_W );
       }
-      break;
-
-   case TGSI_OPCODE_TXB:
-      assert (0);
       break;

    case TGSI_OPCODE_NRM:


comment with TODO for the OpStack

comment with TODO for the OpStack

--- src/ovm.c
+++ src/ovm.c
@@ -1328,6 +1328,17 @@
     os->top = newTopLocation;
 }

+static Address OpStackPeek(Context ctx, OpStack os, Type expectedType, Uword index) {
+    // TODO: have to be able to use the index to get objects beyond the top of the stack.
+    // To do that we have to be able to step backwards either by simply indexing or by
+    // following back-pointers.
+    // The easiest way to make this both possible and fast might be to change the stack
+    // to use two stacks internally. One to store pairs of type information and addresses
+    // to objects and one to store the actual objects. The indexing would then be both
+    // easy to implement and fast because it would index into the stack that holds the
+    // type info and pointers.
+}
+
 // TEST?


Spell OpenSS_H_ right when talking about their specific private key (#321)

Good catch, thanks.


Remove unnecessary define from pfs.c

Remove unnecessary define from pfs.c

--- src/pfs.c
+++ src/pfs.c
@@ -13,7 +13,6 @@
 #include "pfs.h"

 #define PFS_MOUNT_POINT "/var/lib/ramfs-ns"
-#define STACKSIZE (1 << 20)

 int check_privs(pfs *p) {
 	int perms = 0;


Fix for how Linux namespaces operate now and update usage

--- src/pfs.c
+++ src/pfs.c
@@ -44,17 +44,12 @@
         return -1;
     }

-    if (mkdir(p->path, 0700) < 0) {
-        printf("Failed to make namespaced ramfs mount point: %s\n",
-                strerror(errno));
+    if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) < 0) {
+        printf("Failed to make namespaced filesystem private: %s\n", strerror(errno));
         return -1;
     }
     if (mount("ramfs", p->path, "ramfs", 0, NULL) < 0) {
         printf("Failed to mount namespaced ramfs: %s\n", strerror(errno));
-        return -1;
-    }
-    if (mount(NULL, p->path, NULL, MS_PRIVATE, NULL) < 0) {
-        printf("Failed to make namespaced ramfs private: %s\n", strerror(errno));
         return -1;
     }
     if (chown(p->path, p->user, p->group) < 0) {
@@ -105,6 +100,12 @@
 }

 int set_pid_ns_fork(pfs *p) {
+    if (mkdir(p->path, 0700) < 0) {
+        printf("Failed to make ramfs mount point: %s\n",
+                strerror(errno));
+        return -1;
+    }
+
     if (unshare(CLONE_NEWPID) < 0) {
         printf("Failed to create new PID namespace");
         return -1;
@@ -126,7 +127,7 @@
     if (msg) {
         printf("%s\n\n", msg);
     }
-    printf("USAGE: pfs [-u USER] [-g GROUP] -c COMMAND [-a ARG1 [-a ARG2...]]\n");
+    printf("USAGE: pfs COMMAND [ARG1 ARG2...] -- [-u USER] [-g GROUP]\n");
     printf("\tUSER\tRun executable with these user permissions\n");
     printf("\tGROUP\tRun executable with these group permissions\n");
     printf("\tCOMMAND\tExecutable to which to expose temporary in-memory filesystem\n");
@@ -150,7 +151,6 @@
         if (!strcmp("--", argv[i])) {
             break;
         }
-        printf("%s\n", argv[i]);
         p->argv_pfs[i - 1] = argv[i];
     }
     while ((opt = getopt(argc - i, argv + i, "u:g:")) != -1) {


fix DOD registry - related to recent hash changes

git-svn-id: 6e74a02f85675cec270f5d931b0f6998666294a3@8172 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/pmc.c
+++ src/pmc.c
@@ -576,9 +576,10 @@
         PMC *registry;
         registry = interpreter->DOD_registry = pmc_new_noinit(interpreter,
                 enum_class_Hash);
-        new_hash_x(interpreter, &hash, enum_type_int, Hash_key_type_int,
+        new_pmc_hash_x(interpreter, registry, enum_type_int, Hash_key_type_PMC,
                 int_compare, key_hash_int);
-        PMC_struct_val(registry) = hash;
+        PObj_custom_mark_destroy_SETALL(registry);
+        hash = PMC_struct_val(registry);
     }
     else
         hash = PMC_struct_val(interpreter->DOD_registry);


[fix] oops. left in a C++ comment

[fix] oops. left in a C++ comment

git-svn-id: 6e74a02f85675cec270f5d931b0f6998666294a3@47001 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/pmc.c
+++ src/pmc.c
@@ -781,7 +781,6 @@
         if (!PMC_IS_NULL(item)) {
             /* nested namespace with same name */
             if (PMC_IS_TYPE(item, NameSpace))
-            //if (item->vtable->base_type == enum_class_NameSpace)
                 return enum_type_undef;
             else
                 return VTABLE_get_integer(interp, item);


pvq: use od_rcp_beta in od_compute_k

pvq: use od_rcp_beta in od_compute_k

regression on wikiepdia_420.y4m is back:

objective1-fast:
PSNR YCbCr:      0.10%      0.13%      0.08%
   PSNRHVS:      0.05%
      SSIM:      0.07%
    MSSSIM:      0.07%
 CIEDE2000:      0.04%

subset1:
PSNR YCbCr:     -0.00%     -0.00%      0.02%
   PSNRHVS:      0.01%
      SSIM:     -0.01%
    MSSSIM:     -0.01%
 CIEDE2000:     -0.00%

--- src/pvq.c
+++ src/pvq.c
@@ -886,13 +886,14 @@
       return OD_MAXI(1, (int)floor(.5 + (qcg*OD_CGAIN_SCALE_1 - .2)*
        sqrt((n + 3)/2)/beta));
 #else
-      od_val32 rt;
+      od_val16 rt;
       int sqrt_shift;
       rt = od_sqrt((n + 3) >> 1, &sqrt_shift);
       /*FIXME: get rid of 64-bit mul.*/
       return OD_MAXI(1, OD_SHR_ROUND((int64_t)((qcg
-       - (int64_t)OD_QCONST32(.2, OD_CGAIN_SHIFT))*rt/(beta*OD_BETA_SCALE_1)),
-       OD_CGAIN_SHIFT + sqrt_shift));
+       - (int64_t)OD_QCONST32(.2, OD_CGAIN_SHIFT))*
+       OD_MULT16_16_QBETA(od_beta_rcp(beta), rt)), OD_CGAIN_SHIFT
+       + sqrt_shift));
 #endif
     }
   }


Collect fork() timing info only if fork succeeded.

--- src/rdb.c
+++ src/rdb.c
@@ -1870,9 +1870,6 @@
         exitFromChild((retval == C_OK) ? 0 : 1);
     } else {
         /* Parent */
-        server.stat_fork_time = ustime()-start;
-        server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
-        latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
         if (childpid == -1) {
             serverLog(LL_WARNING,"Can't save in background: fork: %s",
                 strerror(errno));
@@ -1896,6 +1893,10 @@
             close(pipefds[1]);
             closeChildInfoPipe();
         } else {
+            server.stat_fork_time = ustime()-start;
+            server.stat_fork_rate = (double) zmalloc_used_memory() * 1000000 / server.stat_fork_time / (1024*1024*1024); /* GB per second. */
+            latencyAddSampleIfNeeded("fork",server.stat_fork_time/1000);
+
             serverLog(LL_NOTICE,"Background RDB transfer started by pid %d",
                 childpid);
             server.rdb_save_time_start = time(NULL);


Clarified order of operations for stretched hardware sprites.


Remove unused variables.

Remove unused variables.

Also comment on a possible segfault cause, unless the tree handles the
issue mentioned through the invariant.

--- src/rrb.c
+++ src/rrb.c
@@ -178,8 +178,6 @@
 static void size_table_to_dot(DotFile dot, const InternalNode *node);

 static uint32_t node_size(DotArray *arr, const TreeNode *node);
-
-static int concat_count = 0;
 #endif

 static RRBSizeTable* size_table_create(uint32_t size) {
@@ -522,13 +520,13 @@
   }

   const uint32_t effective_slot = (table_len / RRB_BRANCHING) + 1;
-  const uint32_t min_width = RRB_BRANCHING - RRB_INVARIANT; // Hello #define?

   uint32_t new_len = all->len;
   while (new_len > effective_slot + RRB_EXTRAS) {

     uint32_t i = 0;
-    while (table->size[i] > min_width) {
+    while (table->size[i] > RRB_BRANCHING - RRB_INVARIANT) {
+      // TODO: Could this segfault? if all sizes > RRB_BRANCHING - RRB_INVARIANT?
       i++;
     }
     // Found short node, so redistribute over the following nodes


Implement rrb_nth tail consideration.

Implement rrb_nth tail consideration.

--- src/rrb.c
+++ src/rrb.c
@@ -869,6 +869,12 @@
   if (index >= rrb->cnt) {
     return NULL;
   }
+#ifdef RRB_TAIL
+  const uint32_t tail_offset = rrb->cnt - rrb->tail_len;
+  if (tail_offset <= index) {
+    return rrb->tail->child[index - tail_offset];
+  }
+#endif
   else {
     const InternalNode *current = (const InternalNode *) rrb->root;
     switch (RRB_SHIFT(rrb)) {


Remove use of deprecated mlt_frame_get_alpha_mask from watermark

--- src/modules/core/filter_watermark.c
+++ src/modules/core/filter_watermark.c
@@ -195,9 +195,10 @@
 				mlt_properties_set( b_props, "rescale.interp", rescale );
 				mlt_service_apply_filters( MLT_FILTER_SERVICE( filter ), b_frame, 0 );
 				error = mlt_frame_get_image( b_frame, image, format, width, height, 1 );
-				alpha = mlt_frame_get_alpha_mask( b_frame );
+				alpha = mlt_frame_get_alpha( b_frame );
 				mlt_frame_set_image( frame, *image, *width * *height * 2, NULL );
-				mlt_frame_set_alpha( frame, alpha, *width * *height, NULL );
+				if ( alpha )
+					mlt_frame_set_alpha( frame, alpha, *width * *height, NULL );
 				mlt_properties_set_int( a_props, "width", *width );
 				mlt_properties_set_int( a_props, "height", *height );
 				mlt_properties_set_int( a_props, "progressive", 1 );


Properly visualize size tables that are NIL.

--- src/rrb.c
+++ src/rrb.c
@@ -778,16 +778,25 @@

     if (print_table) {
-      // "Hack" to get nodes at correct position
-      fprintf(dot.file, "  s%p:last -> s%p:table [dir=back];\n",
-              root->size_table, root);
-
-      // Only do if size table isn't already placed
-      // set rrb node and size table at same rank
-      if (!dot_file_contains(dot, root->size_table)) {
+      if (root->size_table == NULL) {
+        size_table_to_dot(dot, root);
+        fprintf(dot.file, "  {rank=same; s%p; s%d;}\n", root, null_counter - 1);
+        fprintf(dot.file, "  s%d -> s%p:table [dir=back];\n",
+                null_counter - 1, root);
+      }
+      else if (!dot_file_contains(dot, root->size_table)) {
+        // Only do if size table isn't already placed
+        // set rrb node and size table at same rank
+
         fprintf(dot.file, "  {rank=same; s%p; s%p;}\n", root, root->size_table);
         size_table_to_dot(dot, root);
       }
+      if (root->size_table != NULL) {
+        // "Hack" to get nodes at correct position
+        fprintf(dot.file, "  s%p:last -> s%p:table [dir=back];\n",
+                root->size_table, root);
+      }
+
     }

     for (uint32_t i = 0; i < root->len; i++) {
@@ -799,14 +808,14 @@

 static void size_table_to_dot(DotFile dot, const InternalNode *node) {
+  if (node->size_table == NULL) {
+    fprintf(dot.file, "  s%d [color=indianred, label=\"NIL\"];\n",
+            null_counter++);
+    return;
+  }
   if (!dot_file_contains(dot, node->size_table)) {
     dot_file_add(dot, node->size_table);
     RRBSizeTable *table = node->size_table;
-    if (table == NULL) {
-      fprintf(dot.file, "  s%d [color=indianred, label=\"NIL\"];\n",
-              null_counter++);
-      return;
-    }
     fprintf(dot.file,
             "  s%p [color=indianred, label=<\n"
             "<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" "


improve VM, including jump labels

improve VM, including jump labels

--- src/spf.h
+++ src/spf.h
@@ -382,7 +382,7 @@
 size_t spf_env_get(char *, size_t, int, const struct spf_env *);

-_Bool spf_used(spf_macros_t, int);
+_Bool spf_isset(spf_macros_t, int);

 size_t spf_expand(char *, size_t, spf_macros_t *, const char *, const struct spf_env *, int *);


Fix NS for SRU explain for version 2.0 YAZ-697

--- src/srw.c
+++ src/srw.c
@@ -983,6 +983,8 @@
         else if ((*p)->which == Z_SRW_explain_request)
         {
             Z_SRW_explainRequest *req = (*p)->u.explain_request;
+            if (version2)
+                ns = "http://docs.oasis-open.org/ns/search-ws/sruRequest";
             ptr = xmlNewChild(pptr, 0, BAD_CAST "explainRequest", 0);
             ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs");
             xmlSetNs(ptr, ns_srw);
@@ -1001,6 +1003,8 @@
         else if ((*p)->which == Z_SRW_explain_response)
         {
             Z_SRW_explainResponse *res = (*p)->u.explain_response;
+            if (version2)
+                ns = "http://docs.oasis-open.org/ns/search-ws/sruResponse";
             ptr = xmlNewChild(pptr, 0, BAD_CAST "explainResponse", 0);
             ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zs");
             xmlSetNs(ptr, ns_srw);


1.0.9

--- src/str.c
+++ src/str.c
@@ -88,9 +88,13 @@

     h = (strh **) ht_lookup(ht, str->text);
     for (;;) {
-	if (*h == (strh *) NULL || strcmp(str->text, (*h)->str->text) != 0) {
+	/*
+	 * The hasher doesn't handle \0 in strings, and so may not have
+	 * found the proper string. Follow the hash table chain until
+	 * the end is reached, or until a match is found using str_cmp().
+	 */
+	if (*h == (strh *) NULL) {
 	    register strh *s;
-	    hte *next;

 	    /*
 	     * Not in the hash table. Make a new entry.
@@ -103,9 +107,8 @@
 		shlist = l;
 		strhchunksz = 0;
 	    }
-	    next = (hte *) *h;
 	    s = *h = &shlist->sh[strhchunksz++];
-	    s->chain.next = next;
+	    s->chain.next = (hte *) NULL;
 	    s->chain.name = str->text;
 	    s->str = str;
 	    s->index = n;


Refactor, rindex() --> strrchr(), LEGACY as of POSIX.1-2001

Signed-off-by: Joachim Nilsson <583c295fd7602c168ad814279bbc3894ba65f5d6@gmail.com>

--- src/svc.c
+++ src/svc.c
@@ -74,7 +74,7 @@
 	strlcpy(svc->cmd, cmd, sizeof(svc->cmd));

 	/* Default description, if missing */
-	desc = rindex(cmd, '/');
+	desc = strrchr(cmd, '/');
 	if (desc)
 		desc++;
 	else


REFACTORING 23/06 - cmd_parse.c // Quentin il sait pas indenter

--- Server/src/cmd_parse.c
+++ Server/src/cmd_parse.c
@@ -44,11 +44,11 @@

   i = 0;
   while (g_obj_tab[i])
-  {
-    if (!strcmp(str, g_obj_tab[i]))
-      return (TRUE);
-    ++i;
-  }
+    {
+      if (!strcmp(str, g_obj_tab[i]))
+	return (TRUE);
+      ++i;
+    }
   return (FALSE);
 }

@@ -58,18 +58,17 @@

   i = 0;
   while (g_cmd_tab[i].cmd)
-  {
-    if (!strncmp(input, g_cmd_tab[i].cmd, g_cmd_tab[i].size))
     {
-      *off = g_cmd_tab[i].size;
-      if ((i == 5 && !match_ressource(input + g_cmd_tab[i].size)) ||
-	  (i == 6 && !match_ressource(input + g_cmd_tab[i].size)) ||
-	  (i != 8 && i != 5 && i != 6 && input[g_cmd_tab[i].size] != '\0'))
-	return (NULL);
-      return (g_cmd_tab[i].func);
+      if (!strncmp(input, g_cmd_tab[i].cmd, g_cmd_tab[i].size))
+	{
+	  *off = g_cmd_tab[i].size;
+	  if ((i == 5 && !match_ressource(input + g_cmd_tab[i].size)) ||
+	      (i == 6 && !match_ressource(input + g_cmd_tab[i].size)) ||
+	      (i != 8 && i != 5 && i != 6 && input[g_cmd_tab[i].size] != '\0'))
+	    return (NULL);
+	  return (g_cmd_tab[i].func);
+	}
+      ++i;
     }
-    ++i;
-  }
   return (NULL);
 }
-


Use CRIOGET to fetch a crypto descriptor when present.

FreeBSD's current /dev/crypto implementation requires that consumers
clone a separate file descriptor via the CRIOGET ioctl that can then
be used with other ioctls such as CIOCGSESSION.

Reviewed-by: Matt Caswell <1fa2ef4755a9226cb9a0a4840bd89b158ac71391@openssl.org>
Reviewed-by: Ben Kaduk <b34e9dc3dd24827b45bb22e8b76cde1bcb413b0e@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/13468)

--- engines/e_devcrypto.c
+++ engines/e_devcrypto.c
@@ -1172,16 +1172,28 @@
  */
 static int open_devcrypto(void)
 {
+    int fd;
+
     if (cfd >= 0)
         return 1;

-    if ((cfd = open("/dev/crypto", O_RDWR, 0)) < 0) {
+    if ((fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
 #ifndef ENGINE_DEVCRYPTO_DEBUG
         if (errno != ENOENT)
 #endif
             fprintf(stderr, "Could not open /dev/crypto: %s\n", strerror(errno));
         return 0;
     }
+
+#ifdef CRIOGET
+    if (ioctl(fd, CRIOGET, &cfd) < 0) {
+        fprintf(stderr, "Could not create crypto fd: %s\n", strerror(errno));
+        cfd = -1;
+        return 0;
+    }
+#else
+    cfd = fd;
+#endif

     return 1;
 }


cleanup

cleanup

--- src/sys.c
+++ src/sys.c
@@ -630,7 +630,7 @@
     Z80_init();

     // Sprite engine variables reset (we use to know if sprite engine is initialized)
-    spritesBank  = NULL;
+    spritesBank = NULL;
     spriteVramSize = 0;

     // enable interrupts


[~] File-tagging output is now sorted, as well as keywords stored in .tags files.

--- src/tag.c
+++ src/tag.c
@@ -284,6 +284,7 @@
 	}

+	qsort(lines[offset].tags,lines[offset].len,sizeof(char *),compare);//sort output

 	if((tagf=fopen(path,"w"))!=NULL){
 		debugf("writing to .tags\n");


Show specific error information when bailing

--- src/tas.c
+++ src/tas.c
@@ -68,7 +68,7 @@
     void *ud = NULL;

     if (f->init(stream, params, &ud))
-        fatal(0, "Error during initialisation for format '%s'", f->name);
+        fatal(PRINT_ERRNO, "Error during initialisation for format '%s'", f->name);

     if (disassemble) {
         // This output might be consumed by a tool that needs a line at a time


tcp.c: ss_tcp_handle_update: clean up header creation

--- src/tcp.c
+++ src/tcp.c
@@ -460,18 +460,15 @@
         return -1;
     }

-    uint16_t tcp_length_total = (uint16_t) (rte_pktmbuf_pkt_len(rx_buf->mbuf) - ((uint8_t*) rx_buf->tcp - rte_pktmbuf_mtod(rx_buf->mbuf, uint8_t*)));
-    uint16_t tcp_length_data  = (uint16_t) (tcp_length_total - sizeof(tcp_hdr_t));
-
     // XXX: Make the client "happy", and just ACK everything.
     // This is lossy, but back-pressure on syslog messages is pointless.
-    tx_buf->tcp->doff     = 5;
-    tx_buf->tcp->seq      = rx_buf->tcp->ack_seq;
-    tx_buf->tcp->ack_seq  = rte_bswap32(rte_bswap32(rx_buf->tcp->seq) + tcp_length_data);
-    tx_buf->tcp->th_flags = TH_ACK;
-    tx_buf->tcp->window   = rte_bswap16(L4_TCP_WINDOW_SIZE);
-    tx_buf->tcp->check    = rte_bswap16(0x0000);
-    tx_buf->tcp->urg_ptr  = rte_bswap16(0x0000);
+    tx_buf->tcp->seq       = curr_seq;
+    tx_buf->tcp->ack_seq   = rte_bswap32(curr_ack_seq);
+    tx_buf->tcp->doff      = L4_TCP_HEADER_OFFSET;
+    tx_buf->tcp->th_flags  = TH_ACK;
+    tx_buf->tcp->window    = rte_bswap16(L4_TCP_WINDOW_SIZE);
+    tx_buf->tcp->check     = rte_bswap16(0x0000);
+    tx_buf->tcp->urg_ptr   = rte_bswap16(0x0000);

     rv = ss_tcp_prepare_checksum(tx_buf);
     if (rv) {


Added LONGH maker (helper)

Added LONGH maker (helper)

--- src/tlv.c
+++ src/tlv.c
@@ -66,6 +66,10 @@
         { TLV_TIFF, "\077\077\000\042"  },
 };

+/**
+ * Helper for making long tlv
+ */
+static void mk_longh(tlv_t *tlv, int type, uint32_t len);

 /* deprecated */
 unsigned char guess_type(char *src, unsigned int len) {
@@ -573,23 +577,14 @@

         if (nb_inputs > 1) {
                 int content_len = write_idx - content_idx;
-
+                char *false_tlv = *tlv + cmpnd_idx;
                 if (content_len > TLV_MAX_VALUE_SIZE) {
-                        uint32_t be_len = htonl(content_len);
-                        char *false_tlv = *tlv + cmpnd_idx;
-                        tlv_set_type(&false_tlv, TLV_LONGH);
-                        tlv_set_length(&false_tlv,
-                                TLV_SIZEOF_TYPE + sizeof(uint32_t));
-                        *(tlv_get_value_ptr(&false_tlv)) = TLV_COMPOUND;
-                        memcpy(tlv_get_value_ptr(&false_tlv) + 1,
-                                &be_len,
-                                sizeof(be_len));
+                        mk_longh(&false_tlv, TLV_COMPOUND, content_len);
                         uint32_t new_size = ltlv_split_value(
                                 false_tlv + TLV_SIZEOF_LONGH,
                                 content_len);
                         write_idx = content_idx + new_size;
                 } else {
-                        char *false_tlv = *tlv + cmpnd_idx;
                         tlv_set_type(&false_tlv, TLV_COMPOUND);
                         tlv_set_length(&false_tlv, content_len);
                 }
@@ -597,23 +592,18 @@

         if (date != 0) {
                 int content_len = write_idx - (cmpnd_idx - TLV_SIZEOF_DATE);
+                LOGINFO("content_len:%d, cmpnd_idx:%d",
+                        content_len, cmpnd_idx);
                 if (content_len > TLV_MAX_VALUE_SIZE) {
-                        uint32_t be_len = htonl(content_len);
-                                tlv_set_type(tlv, TLV_LONGH);
-                                tlv_set_length(tlv,
-                                        TLV_SIZEOF_TYPE + sizeof(uint32_t));
-                                *tlv_get_value_ptr(tlv) = TLV_DATED;
-                                memcpy(tlv_get_value_ptr(tlv) + 1,
-                                        &be_len,
-                                        sizeof(be_len));
-                                memcpy(tlv_get_value_ptr(tlv)
-                                        + 1 + sizeof(uint32_t),
-                                        &date,
-                                        sizeof(date));
-                                uint32_t new_size = ltlv_split_value(
-                                        *tlv + TLV_SIZEOF_LONGH,
-                                        content_len);
-                                write_idx = cmpnd_idx + new_size;
+                        mk_longh(tlv, TLV_DATED, content_len);
+                        memcpy(tlv_get_value_ptr(tlv)
+                                + 1 + sizeof(uint32_t),
+                                &date,
+                                sizeof(date));
+                        uint32_t new_size = ltlv_split_value(
+                                *tlv + TLV_SIZEOF_LONGH,
+                                content_len);
+                        write_idx = cmpnd_idx + new_size;
                 } else {
                         tlv_set_date(tlv, date);
                         tlv_set_type(tlv, TLV_DATED);
@@ -623,10 +613,22 @@

         if (write_idx != len) {
                 LOGERROR("written %d bytes, expected %d.", write_idx, len);
+                status = -1;
         }

         return status;

+}
+
+static void mk_longh(tlv_t *tlv, int type, uint32_t len) {
+        uint32_t be_len = htonl(len);
+        tlv_set_type(tlv, TLV_LONGH);
+        tlv_set_length(tlv,
+                TLV_SIZEOF_TYPE + sizeof(uint32_t));
+        *(tlv_get_value_ptr(tlv)) = type;
+        memcpy(tlv_get_value_ptr(tlv) + 1,
+                &be_len,
+                sizeof(be_len));
 }

 /**


Fix build.

Fix build.

TBR=vitalyr@chromium.org

Review URL: http://codereview.chromium.org/6688032

git-svn-id: b158db1e4b4ab85d4c9e510fdef4b1e8c614b15b@7260 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

--- src/top.h
+++ src/top.h
@@ -562,7 +562,7 @@

     ~ExceptionScope() {
       Top::set_catcher(catcher_);
-      Top::set_external_caught_exception(external_caught_exception);
+      Top::set_external_caught_exception(external_caught_exception_);
       Top::set_pending_exception(*pending_exception_);
     }


Refactor, simplify

Refactor, simplify

Signed-off-by: Joachim Nilsson <583c295fd7602c168ad814279bbc3894ba65f5d6@gmail.com>

--- src/uev.c
+++ src/uev.c
@@ -347,6 +347,8 @@

 				if (!w->u.t.period)
 					w->u.t.timeout = 0;
+				if (!w->u.t.timeout)
+					uev_timer_stop(w);
 				break;

 			case UEV_CRON_TYPE:
@@ -362,16 +364,9 @@
 					w->u.c.when = 0;
 				else
 					w->u.c.when += w->u.c.interval;
-				break;
-			}
-
-			if (UEV_CRON_TYPE == w->type) {
 				if (!w->u.c.when)
 					uev_timer_stop(w);
-			}
-			if (UEV_TIMER_TYPE == w->type) {
-				if (!w->u.t.timeout)
-					uev_timer_stop(w);
+				break;
 			}

 			/*


USB: Add lock for read and poll

USB: Add lock for read and poll

--- src/usb.c
+++ src/usb.c
@@ -13,6 +13,7 @@

 uint8_t USB_READY;
 usbd_device *usbd_dev;
+uint8_t usb_lock;

 // Read callback function pointer
 void (*read_callback)(void* buf, uint16_t len);
@@ -209,7 +210,14 @@
 		return;
 	}

+	// Get lock
+	while(usb_lock);
+	usb_lock = 1;
+
 	while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0);
+
+	// Release lock
+	usb_lock = 0;
 }

 void SetupUsb(void)
@@ -244,7 +252,14 @@

 void UsbPoll(void)
 {
-	usbd_poll(usbd_dev);
+	if(!usb_lock) {
+		// Get lock
+		usb_lock = 1;
+		usbd_poll(usbd_dev);
+
+		// Release lock
+		usb_lock = 0;
+	}
 }

@@ -295,4 +310,5 @@

 uint8_t USB_READY = 0;
 usbd_device *usbd_dev = NULL;
-void (*read_callback)(void* buf, uint16_t len) = UsbDefaultReadCallback;+void (*read_callback)(void* buf, uint16_t len) = UsbDefaultReadCallback;
+uint8_t usb_lock = 0;


vec->entry working for CUDA

vec->entry working for CUDA

--- src/vec.c
+++ src/vec.c
@@ -516,7 +516,16 @@
 static void vec_entry(ghost_vec_t * vec, ghost_vidx_t r, ghost_vidx_t c, void *val)
 {
     size_t sizeofdt = ghost_sizeofDataType(vec->traits->datatype);
-    memcpy(val,VECVAL(vec,vec->val,c,r),sizeofdt);
+    if (vec->traits->flags & GHOST_VEC_DEVICE)
+    {
+#if GHOST_HAVE_CUDA
+        CU_copyDeviceToHost(val,&vec->CU_val[(c*vec->traits->nrowspadded+r)*sizeofdt],sizeofdt);
+#endif
+    }
+    else if (vec->traits->flags & GHOST_VEC_HOST)
+    {
+        memcpy(val,VECVAL(vec,vec->val,c,r),sizeofdt);
+    }
 }

 static void vec_fromRand(ghost_vec_t *vec)


Fix warnings

Fix warnings

--- src/vlc.c
+++ src/vlc.c
@@ -28,9 +28,10 @@
 #include "config.h"

 #include <vlc/vlc.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <locale.h>

-#include <stdio.h>

 /* Explicit HACK */
 extern void LocaleFree (const char *);


Dropped a most important '!' during last merge.

svn path=/trunk/; revision=1594

--- src/vte.c
+++ src/vte.c
@@ -9082,7 +9082,7 @@
 				vte_terminal_determine_colors(terminal, cell,
 						terminal->pvt->screen->reverse_mode,
 						selected,
-						terminal->pvt->screen->reverse_mode,
+						TRUE,
 						&fore, &back);
 				vte_terminal_draw_cells(terminal,
 						&item, 1,
@@ -9096,7 +9096,7 @@
 						height);
 			}
 			vte_terminal_determine_colors(terminal, cell,
-					terminal->pvt->screen->reverse_mode,
+					!terminal->pvt->screen->reverse_mode,
 					selected,
 					TRUE,
 					&fore, &back);


widget: Do not leave behind a zombie child when closing a terminal

https://bugzilla.gnome.org/show_bug.cgi?id=740929

--- src/vte.c
+++ src/vte.c
@@ -3249,6 +3249,12 @@
                             int status,
                             VteTerminal *terminal)
 {
+	if (terminal == NULL) {
+		/* The child outlived VteTerminal. Do nothing, we're happy that Glib
+		 * read its exit data and hence it's no longer there as zombie. */
+		return;
+	}
+
 	if (pid == terminal->pvt->pty_pid) {
                 GObject *object = G_OBJECT(terminal);

@@ -8445,11 +8451,15 @@
 		terminal->pvt->outgoing_conv = VTE_INVALID_CONV;
 	}

-	/* Stop listening for child-exited signals. */
+	/* Start listening for child-exited signals and ignore them, so that no zombie child is left behind. */
         if (terminal->pvt->child_watch_source != 0) {
                 g_source_remove (terminal->pvt->child_watch_source);
                 terminal->pvt->child_watch_source = 0;
         }
+        g_child_watch_add_full(G_PRIORITY_HIGH,
+                               terminal->pvt->pty_pid,
+                               (GChildWatchFunc)vte_terminal_child_watch_cb,
+                               NULL, NULL);

 	/* Stop processing input. */
 	vte_terminal_stop_processing (terminal);


SalutXmppConnectManager: Don't start the refcount for outgoing connections at 1

20070812203056-b58c9-dbfe3b8bd0f247b9127afc0e7985f36ce5ae3fb8.gz

--- src/salut-xmpp-connection-manager.c
+++ src/salut-xmpp-connection-manager.c
@@ -1295,12 +1295,6 @@
           g_signal_connect (connection, "parse-error",
               G_CALLBACK (outgoing_pending_connection_parse_error_cb), self);

-          /* init connection refcount to 1.
-           * The connection is not in the hash table yet but as
-           * GUINT_TO_POINTER (NULL) == 0 that does exactly what
-           * we want */
-          increment_connection_refcount (self, connection);
-
           g_array_free (addrs, TRUE);
           return TRUE;
         }


Finish selection rework

Finish selection rework

Bug 598124 - The selection does not only change when the mousebutton is released

Only update selection when mouse-button is released (or focus lost).
Also, update PRIMARY when _select_all() is called.

--- src/vte.c
+++ src/vte.c
@@ -6167,9 +6167,7 @@
 static gboolean
 _vte_terminal_maybe_end_selection (VteTerminal *terminal)
 {
-	/* If Shift is held down, or we're not in events mode,
-	 * copy the selected text. */
-	if (terminal->pvt->selecting || !terminal->pvt->mouse_tracking_mode) {
+	if (terminal->pvt->selecting) {
 		/* Copy only if something was selected. */
 		if (terminal->pvt->has_selection &&
 		    !terminal->pvt->selecting_restart &&
@@ -6639,9 +6637,6 @@
 			"Selection changed to "
 			"(%ld,%ld) to (%ld,%ld).\n",
 			sc->col, sc->row, ec->col, ec->row);
-
-	vte_terminal_copy_primary(terminal);
-	vte_terminal_emit_selection_changed(terminal);
 }

 static void
@@ -6694,16 +6689,7 @@

 	_vte_debug_print(VTE_DEBUG_SELECTION, "Selecting *all* text.\n");

-	g_free (terminal->pvt->selection);
-	terminal->pvt->selection =
-		vte_terminal_get_text_range (terminal,
-				terminal->pvt->selection_start.row,
-				terminal->pvt->selection_start.col,
-				terminal->pvt->selection_end.row,
-				terminal->pvt->selection_end.col,
-				vte_cell_is_selected,
-				NULL, NULL);
-
+	vte_terminal_copy_primary(terminal);
 	vte_terminal_emit_selection_changed (terminal);
 	_vte_invalidate_all (terminal);
 }
@@ -7069,7 +7055,11 @@
 				event->button, x, y);
 		switch (event->button) {
 		case 1:
-			handled = _vte_terminal_maybe_end_selection (terminal);
+			/* If Shift is held down, or we're not in events mode,
+			 * copy the selected text. */
+			if ((terminal->pvt->modifiers & GDK_SHIFT_MASK) ||
+			    !terminal->pvt->mouse_tracking_mode)
+				handled = _vte_terminal_maybe_end_selection (terminal);
 			break;
 		case 2:
 			if ((terminal->pvt->modifiers & GDK_SHIFT_MASK) ||
@@ -13765,12 +13755,13 @@
 	terminal->pvt->selection_end.col = end_col;
 	terminal->pvt->selection_end.row = end_row;
 	vte_terminal_copy_primary(terminal);
+	vte_terminal_emit_selection_changed(terminal);
+
 	_vte_invalidate_region (terminal,
 			MIN (start_col, start_row), MAX (start_col, start_row),
 			MIN (start_row, end_row),   MAX (start_row, end_row),
 			FALSE);

-	vte_terminal_emit_selection_changed(terminal);
 }

 void


Add simple mesh object include to ionScene include

--- ionScene/ionScene.h
+++ ionScene/ionScene.h
@@ -19,6 +19,7 @@

 #include "CSimpleMesh.h"
 #include "CGeometryCreator.h"
+#include "CSimpleMeshSceneObject.h"

 namespace ion


Detect RF64 files and ignore bad chunks.

--- src/wav.c
+++ src/wav.c
@@ -94,6 +94,7 @@
     gsm_signal     *gsmsample;
     int            gsmindex;
     size_t      gsmbytecount;    /* counts bytes written to data block */
+    sox_bool       isRF64;          /* True if file being read is a RF64 */
 } priv_t;

 static char *wav_format_str(unsigned wFormatTag);
@@ -373,6 +374,7 @@
 static int findChunk(sox_format_t * ft, const char *Label, uint32_t *len)
 {
     char magic[5];
+    priv_t *wav = (priv_t *) ft->priv;
     for (;;)
     {
         if (lsx_reads(ft, magic, (size_t)4) == SOX_EOF)
@@ -391,6 +393,13 @@

         if (strncmp(Label, magic, (size_t)4) == 0)
             break; /* Found the given chunk */
+
+        if (len == -1 && wav->isRF64==sox_true) {
+            /* Indicates invalid size */
+            lsx_fail_errno(ft, SOX_EHDR, "WAVE file has missing %s chunk",
+                          Label);
+            return SOX_EOF;
+        }

 	/* Chunks are required to be word aligned. */
 	if ((*len) % 2) (*len)++;
@@ -458,6 +467,15 @@
         ft->encoding.reverse_bytes = MACHINE_IS_LITTLEENDIAN;
     }
     else ft->encoding.reverse_bytes = MACHINE_IS_BIGENDIAN;
+
+    if (strncmp("RF64", magic, (size_t)4) == 0)
+    {
+        wav->isRF64 = sox_true;
+    }
+    else
+    {
+        wav->isRF64 = sox_false;
+    }

     lsx_readdw(ft, &dwRiffLength);


Fixed coding style in contribution.

Fixed coding style in contribution.

* Contributors _please_ follow my coding style in the future!!

darcs-hash:20050316225600-4eba8-8b330eb9a5bbdc1cea7b61a379408489ed0680b4.gz

--- ioncore/clientwin.c
+++ ioncore/clientwin.c
@@ -120,13 +120,13 @@
     const struct gravity_spec *sp;
     int value = ForgetGravity;

-    if (extl_table_gets_s(cwin->proptab,propname,&gravity)) {
-	for (s=gravity; *s; ++s)
+    if(extl_table_gets_s(cwin->proptab, propname, &gravity)){
+	for(s=gravity; *s; ++s)
 	    *s = tolower(*s);

-	for (sp=gravity_specs; sp->spec; ++sp) {
-	    if (strcmp(gravity,sp->spec) == 0) {
-		value = sp->gravity;
+	for(sp=gravity_specs; sp->spec; ++sp){
+	    if(strcmp(gravity,sp->spec)==0){
+		value=sp->gravity;
 		break;
 	    }
 	}
@@ -206,8 +206,8 @@
     if(extl_table_is_bool_set(tab, "transients_at_top"))
         cwin->transient_gravity = NorthGravity;

-    cwin->gravity = get_gravity_winprop(cwin,"gravity");
-    cwin->transient_gravity = get_gravity_winprop(cwin,"transient_gravity");
+    cwin->gravity=get_gravity_winprop(cwin,"gravity");
+    cwin->transient_gravity=get_gravity_winprop(cwin,"transient_gravity");
 }

@@ -1070,7 +1070,7 @@
                          WRectangle *geom)
 {
     const WRectangle *max_geom=&(fp->g);
-    int gravity = cwin->gravity;
+    int gravity=cwin->gravity;
     int htry=max_geom->h;
     WClientWin *mgr;

@@ -1082,8 +1082,8 @@
     }

     if(mgr!=NULL && fp->mode==REGION_FIT_BOUNDS){
-	if (gravity == ForgetGravity)
-	    gravity = mgr->transient_gravity;
+	if(gravity==ForgetGravity)
+	    gravity=mgr->transient_gravity;
         if(cwin->last_h_rq<htry)
             htry=cwin->last_h_rq;
     }
@@ -1093,38 +1093,38 @@

     xsizehints_correct(&(cwin->size_hints), &(geom->w), &(geom->h), FALSE);

-    switch (gravity) {
-	case WestGravity:
-	case NorthWestGravity:
-	case SouthWestGravity:
-	    geom->x=max_geom->x;
-	    break;
-
-	case EastGravity:
-	case NorthEastGravity:
-	case SouthEastGravity:
-	    geom->x=max_geom->x+max_geom->w-geom->w;
-	    break;
-
-	default:
-	    geom->x=max_geom->x+max_geom->w/2-geom->w/2;
-    }
-
-    switch (gravity) {
-	case NorthGravity:
-	case NorthWestGravity:
-	case NorthEastGravity:
-	    geom->y=max_geom->y;
-	    break;
-
-	case SouthGravity:
-	case SouthWestGravity:
-	case SouthEastGravity:
-	    geom->y=max_geom->y+max_geom->h-geom->h;
-	    break;
-
-	default:
-	    geom->y=max_geom->y+max_geom->h/2-geom->h/2;
+    switch(gravity){
+    case WestGravity:
+    case NorthWestGravity:
+    case SouthWestGravity:
+        geom->x=max_geom->x;
+        break;
+
+    case EastGravity:
+    case NorthEastGravity:
+    case SouthEastGravity:
+        geom->x=max_geom->x+max_geom->w-geom->w;
+        break;
+
+    default:
+        geom->x=max_geom->x+max_geom->w/2-geom->w/2;
+    }
+
+    switch(gravity){
+    case NorthGravity:
+    case NorthWestGravity:
+    case NorthEastGravity:
+        geom->y=max_geom->y;
+        break;
+
+    case SouthGravity:
+    case SouthWestGravity:
+    case SouthEastGravity:
+        geom->y=max_geom->y+max_geom->h-geom->h;
+        break;
+
+    default:
+        geom->y=max_geom->y+max_geom->h/2-geom->h/2;
     }

     if(geom->h<=1)
@@ -1563,10 +1563,10 @@
     WFitParams fp;
     PtrListIterTmp tmp;

-    if (cwin->transient_gravity == NorthGravity)
-	cwin->transient_gravity = SouthGravity;
+    if(cwin->transient_gravity==NorthGravity)
+	cwin->transient_gravity=SouthGravity;
     else
-	cwin->transient_gravity = NorthGravity;
+	cwin->transient_gravity=NorthGravity;

     fp.mode=REGION_FIT_BOUNDS;
     fp.g=cwin->last_fp.g;


set_data_dir is now additive.
DB->open, and DB->remove now use the data dirs
We look (in order) in each of the data dirs for a file to open/remove.
The first file found, is the one used (even if another is similarly named with
different subdbs).

For creating dbs, (if file does not exist in any of the search dirs), we always
create in the first data dir (or env->i->dir if no data dirs are set).

Addresses #42
Addresses #108

git-svn-id: 4b2652e19d8125fd9d24eff55f31fd1beb5a42e7@1304 c7de825b-a66e-492c-adef-691d508d4ae1

--- src/ydb.c
+++ src/ydb.c
@@ -46,7 +46,8 @@
     char *dir;                  /* A malloc'd copy of the directory. */
     char *tmp_dir;
     char *lg_dir;
-    char *data_dir;
+    char **data_dirs;
+    u_int32_t n_data_dirs;
     //void (*noticecall)(DB_ENV *, db_notices);
     long cachetable_size;
     CACHETABLE cachetable;
@@ -330,8 +331,14 @@
         r0=toku_cachetable_close(&env->i->cachetable);
     if (env->i->logger)
         r1=toku_logger_log_close(&env->i->logger);
-    if (env->i->data_dir)
-        toku_free(env->i->data_dir);
+    if (env->i->data_dirs) {
+        u_int32_t i;
+        assert(env->i->n_data_dirs > 0);
+        for (i = 0; i < env->i->n_data_dirs; i++) {
+            toku_free(env->i->data_dirs[i]);
+        }
+        toku_free(env->i->data_dirs);
+    }
     if (env->i->lg_dir)
         toku_free(env->i->lg_dir);
     if (env->i->tmp_dir)
@@ -366,12 +373,38 @@
 }

 static int toku_db_env_set_data_dir(DB_ENV * env, const char *dir) {
+    u_int32_t i;
+    int r;
+    void* temp;
+
     if (db_env_opened(env) || !dir)
         return EINVAL;
-    if (env->i->data_dir)
-        toku_free(env->i->data_dir);
-    env->i->data_dir = toku_strdup(dir);
-    return env->i->data_dir ? 0 : ENOMEM;
+
+    if (env->i->data_dirs) {
+        assert(env->i->n_data_dirs > 0);
+        for (i = 0; i < env->i->n_data_dirs; i++) {
+            if (!strcmp(dir, env->i->data_dirs[i])) {
+                //It is already in the list.  We're done.
+                return 0;
+            }
+        }
+    }
+    else assert(env->i->n_data_dirs == 0);
+    temp = (char**) toku_realloc(env->i->data_dirs, (1 + env->i->n_data_dirs) * sizeof(char*));
+    if (temp==NULL) {assert(errno == ENOMEM); return ENOMEM;}
+    env->i->data_dirs[env->i->n_data_dirs] = toku_strdup(dir);
+    if (env->i->data_dirs[env->i->n_data_dirs]==NULL) {
+        assert(errno==ENOMEM);
+        r = ENOMEM;
+        if (env->i->n_data_dirs > 0) {
+            toku_free(env->i->data_dirs);
+            env->i->data_dirs = NULL;
+        }
+        else env->i->data_dirs = toku_realloc(env->i->data_dirs, env->i->n_data_dirs * sizeof(char*));
+        return r;
+    }
+    env->i->n_data_dirs++;
+    return 0;
 }

 static void toku_db_env_set_errcall(DB_ENV * env, void (*errcall) (const char *, char *)) {
@@ -1202,6 +1235,39 @@
     }
 }

+int find_db_file(DB_ENV* dbenv, const char *fname, char** full_name_out) {
+    u_int32_t i;
+    int r;
+    struct stat statbuf;
+    char* full_name;
+
+    assert(full_name_out);
+    if (dbenv->i->data_dirs!=NULL) {
+        assert(dbenv->i->n_data_dirs > 0);
+        for (i = 0; i < dbenv->i->n_data_dirs; i++) {
+            full_name = construct_full_name(dbenv->i->data_dirs[0], fname);
+            if (!full_name) return ENOMEM;
+            r = stat(full_name, &statbuf);
+            if (r == 0) goto finish;
+            else {
+                toku_free(full_name);
+                if (r != ENOENT) return r;
+            }
+        }
+        //Did not find it at all.  Return the first data dir.
+        full_name = construct_full_name(dbenv->i->data_dirs[0], fname);
+        goto finish;
+    }
+    //Default without data_dirs is the environment directory.
+    full_name = construct_full_name(dbenv->i->dir, fname);
+    goto finish;
+
+finish:
+    if (!full_name) return ENOMEM;
+    *full_name_out = full_name;
+    return 0;
+}
+
 // The decision to embedded subdatabases in files is a little bit painful.
 // My original design was to simply create another file, but it turns out that we
 //  have to inherit mode bits and so forth from the first file that was created.
@@ -1218,11 +1284,9 @@

     if (db_opened(db))
         return -1;              /* It was already open. */
-    db->i->full_fname = construct_full_name(db->dbenv->i->dir, fname);
-    if (db->i->full_fname == 0) {
-        r = ENOMEM;
-        goto error_cleanup;
-    }
+
+    r = find_db_file(db->dbenv, fname, &db->i->full_fname);
+    if (r != 0) goto error_cleanup;
     // printf("Full name = %s\n", db->i->full_fname);
     db->i->database_name = toku_strdup(dbname ? dbname : "");
     if (db->i->database_name == 0) {
@@ -1368,11 +1432,9 @@
 static int toku_db_remove(DB * db, const char *fname, const char *dbname, u_int32_t flags) {
     int r;
     int r2;
-    char ffull[PATH_MAX];
-
-    //TODO: DB_ENV->set_data_dir should affect db_remove's directories.
+    char *full_name;
+
     //TODO: Verify DB* db not yet opened
-
     if (dbname) {
         //TODO: Verify the target db is not open
         //TODO: Use master database (instead of manual edit) when implemented.
@@ -1384,15 +1446,14 @@
         return r ? r : r2;
     }
     //TODO: Verify db file not in use. (all dbs in the file must be unused)
-    if ((r = construct_full_name_in_buf(db->dbenv->i->dir, fname, ffull, sizeof(ffull))) != 0) {
-        //Name too long.
-        assert(r == ENAMETOOLONG);
-        return r;
-    }
+    r = find_db_file(db->dbenv, fname, &full_name);
+    if (r!=0) return r;
+    assert(full_name);
     r2 = db->close(db, 0);
     if (r == 0 && r2 == 0) {
-        if (unlink(ffull) != 0) r = errno;
-    }
+        if (unlink(full_name) != 0) r = errno;
+    }
+    toku_free(full_name);
     return r ? r : r2;
 }


Fix MSYS2 MinGW 64 (#47)

Fix MSYS2 MinGW 64 (#47)

--- src/zip.c
+++ src/zip.c
@@ -12,7 +12,7 @@
 #include <sys/stat.h>
 #include <time.h>

-#if defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER)
+#if defined(_WIN32) || defined(__WIN32__) || defined(_MSC_VER) || defined(__MINGW64__)
 /* Win32, DOS, MSVC, MSVS */
 #include <direct.h>

@@ -394,7 +394,7 @@
   mz_uint16 dos_time, dos_date;
   int status = -1;

-#if defined(_MSC_VER) || defined(_WIN32) || defined(__WIN32__)
+#if defined(_MSC_VER) || defined(_WIN32) || defined(__WIN32__) || defined(__MINGW64__)
   struct tm tmb, *tm = (struct tm *)&tmb;
 #else
   struct tm *tm;
@@ -426,7 +426,7 @@
   entrylen = (mz_uint16)strlen(zip->entry.name);
   t = time(NULL);

-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__MINGW64__)
   if (localtime_s(tm, &t)) {
     goto cleanup;
   }
@@ -572,7 +572,7 @@
     return -1;
   }

-#ifdef _MSC_VER
+#if defined(_MSC_VER) || defined(__MINGW64__)
   if (!fopen_s(&stream, filename, "rb"))
 #else
   if (!(stream = fopen(filename, "rb")))
@@ -771,7 +771,7 @@
     return -1;
   }

-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__MINGW64__)
   strcpy_s(path, MAX_PATH, dir);
 #else
   strcpy(path, dir);
@@ -793,7 +793,7 @@
       // Cannot get information about zip archive;
       goto out;
     }
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__MINGW64__)
     strncpy_s(&path[dirlen], MAX_PATH - dirlen, info.m_filename,
               MAX_PATH - dirlen);
 #else


cleanup: Fix coding style.

cleanup: Fix coding style.

--- ir/ana/execfreq_t.h
+++ ir/ana/execfreq_t.h
@@ -22,7 +22,8 @@

 typedef struct ir_execfreq_int_factors {
 	double min_non_zero;
-	double m, b;
+	double m;
+	double b;
 } ir_execfreq_int_factors;

 void ir_calculate_execfreq_int_factors(ir_execfreq_int_factors *factors,


fix: make operator bool() explicit

fix: make operator bool() explicit

--- sstream.h
+++ sstream.h
@@ -36,9 +36,9 @@
 	explicit basic_stringstream(const string_type& inp) { init(inp.c_str()); }
 	basic_stringstream() {}

-	bool good() const 		{ return buffer.size() ? cursor != buffer.end() : false; }
-	bool eof() const 		{ return !good(); }
-	operator bool() const 	{ return good(); }
+	bool good() const 				{ return buffer.size() ? cursor != buffer.end() : false; }
+	bool eof() const 				{ return !good(); }
+	explicit operator bool() const 	{ return good(); }

 	void reset(const value_type* inp) {
 		init(inp);


assert that heur 3 assigns an existing register

--- ir/be/becopyheur3.c
+++ ir/be/becopyheur3.c
@@ -198,7 +198,10 @@
 		if(bitset_is_set(nodes, idx)) {
 			unsigned t_idx             = node_map[idx];
 			unsigned col               = inv_col_map[be_java_coal_get_color(coal, t_idx)];
-			const arch_register_t *reg = &co->cls->regs[col];
+			const arch_register_t *reg;
+
+			assert(col < n_regs);
+			reg	= &co->cls->regs[col];
 			arch_set_irn_register(co->aenv, n, reg);
 		}
 	}


Fixed a typo in a variable name.

Fixed a typo in a variable name.

--- sstring.c
+++ sstring.c
@@ -295,20 +295,20 @@
                     size_t num)
 {
 	int return_val;
-	size_t lenght = (str1->length > str2->length) ? str2->length : str1->length;
+	size_t length = (str1->length > str2->length) ? str2->length : str1->length;
 	const char temp;

-	if(num >= lenght)
+	if(num >= length)
 		return strcmp(str1->string, str2->string);
 	else
 		length = num;

-	temp = str1->string[lenght];
-	str1->string[lenght] = '\0';
+	temp = str1->string[length];
+	str1->string[length] = '\0';

 	return_val = strcmp(str1->string, str2->string);

-	str1->string[lenght] = temp;
+	str1->string[length] = temp;

 	return return_val;
 }


fixed indentation

fixed indentation

[r17871]

--- ir/common/irtools.c
+++ ir/common/irtools.c
@@ -37,8 +37,8 @@

 /* the famous clear_link implementation. */
 void firm_clear_link(ir_node *n, void *env) {
-  (void) env;
-  set_irn_link(n, NULL);
+	(void) env;
+	set_irn_link(n, NULL);
 }

 /*
@@ -50,66 +50,65 @@
  * Note further, that the new nodes have no block.
  */
 void
-copy_irn_to_irg(ir_node *n, ir_graph *irg)
-{
-  ir_op *op = get_irn_op(n);
-  ir_graph *old_irg;
-  ir_node *nn = NULL;
+copy_irn_to_irg(ir_node *n, ir_graph *irg) {
+	ir_op *op = get_irn_op(n);
+	ir_graph *old_irg;
+	ir_node *nn = NULL;

-  /* do not copy standard nodes */
-  if (op == op_Bad)
-    nn = get_irg_bad(irg);
-  else if (op == op_NoMem)
-    n = get_irg_no_mem(irg);
-  else if (op == op_Block) {
-    old_irg = get_irn_irg(n);
+	/* do not copy standard nodes */
+	if (op == op_Bad)
+		nn = get_irg_bad(irg);
+	else if (op == op_NoMem)
+		n = get_irg_no_mem(irg);
+	else if (op == op_Block) {
+		old_irg = get_irn_irg(n);

-    if (n == get_irg_start_block(old_irg))
-      nn = get_irg_start_block(irg);
-    else if (n == get_irg_end_block(old_irg))
-      nn = get_irg_end_block(irg);
-  }
-  else if (op == op_Start)
-    nn = get_irg_start(irg);
-  else if (op == op_End)
-    nn = get_irg_end(irg);
-  else if (op == op_Proj) {
-    old_irg = get_irn_irg(n);
+		if (n == get_irg_start_block(old_irg))
+			nn = get_irg_start_block(irg);
+		else if (n == get_irg_end_block(old_irg))
+			nn = get_irg_end_block(irg);
+	}
+	else if (op == op_Start)
+		nn = get_irg_start(irg);
+	else if (op == op_End)
+		nn = get_irg_end(irg);
+	else if (op == op_Proj) {
+		old_irg = get_irn_irg(n);

-    if (n == get_irg_frame(old_irg))
-      nn = get_irg_frame(irg);
-    else if (n == get_irg_globals(old_irg))
-      nn = get_irg_globals(irg);
-    else if (n == get_irg_initial_mem(old_irg))
-      nn = get_irg_initial_mem(irg);
-    else if (n == get_irg_args(old_irg))
-      nn = get_irg_args(irg);
-  }
+		if (n == get_irg_frame(old_irg))
+			nn = get_irg_frame(irg);
+		else if (n == get_irg_globals(old_irg))
+			nn = get_irg_globals(irg);
+		else if (n == get_irg_initial_mem(old_irg))
+			nn = get_irg_initial_mem(irg);
+		else if (n == get_irg_args(old_irg))
+			nn = get_irg_args(irg);
+	}

-  if (nn) {
-    set_irn_link(n, nn);
-    return;
-  }
+	if (nn) {
+		set_irn_link(n, nn);
+		return;
+	}

-  nn = new_ir_node(get_irn_dbg_info(n),
-         irg,
-         NULL,            /* no block yet, will be set later */
-         op,
-         get_irn_mode(n),
-         get_irn_arity(n),
-         get_irn_in(n) + 1);
+	nn = new_ir_node(get_irn_dbg_info(n),
+	                 irg,
+	                 NULL,            /* no block yet, will be set later */
+	                 op,
+	                 get_irn_mode(n),
+	                 get_irn_arity(n),
+	                 get_irn_in(n) + 1);

-  /* Copy the attributes.  These might point to additional data.  If this
-     was allocated on the old obstack the pointers now are dangling.  This
-     frees e.g. the memory of the graph_arr allocated in new_immBlock. */
-  copy_node_attr(n, nn);
-  new_backedge_info(nn);
-  set_irn_link(n, nn);
+	/* Copy the attributes.  These might point to additional data.  If this
+	   was allocated on the old obstack the pointers now are dangling.  This
+	   frees e.g. the memory of the graph_arr allocated in new_immBlock. */
+	copy_node_attr(n, nn);
+	new_backedge_info(nn);
+	set_irn_link(n, nn);

-  /* fix the irg for blocks */
-  if (is_Block(nn))
-    nn->attr.block.irg = irg;
+	/* fix the irg for blocks */
+	if (is_Block(nn))
+		nn->attr.block.irg = irg;
 }

 /*
@@ -140,8 +139,7 @@
 	return res;
 }

-void firm_pset_dump(pset *set)
-{
+void firm_pset_dump(pset *set) {
 	void *obj;

 	foreach_pset(set, obj) {


Cleanup doubleword lowering.

Cleanup doubleword lowering.

--- ir/lower/lower_dw.c
+++ ir/lower/lower_dw.c
@@ -836,7 +836,7 @@
 	ir_node *fconv       = create_conv(block_false, left_high, low_unsigned);
 	ir_node *fres_low    = new_rd_shrs(dbgi, block_false, fconv, right,
 	                                   low_unsigned);
-	int      cnsti       = modulo_shift2-1;
+	int      cnsti       = modulo_shift2 - 1;
 	ir_node *cnst3       = new_r_Const_long(irg, low_unsigned, cnsti);
 	ir_node *fres_high;
 	if (new_rd_shrs == new_rd_Shrs) {
@@ -846,9 +846,9 @@
 	}

 	/* patch lower block */
-	ir_node  *lower_in[]    = { new_r_Jmp(block_true), new_r_Jmp(block_false) };
-	ir_node  *phi_low_in[]  = { tres_low,  fres_low };
-	ir_node  *phi_high_in[] = { tres_high, fres_high };
+	ir_node *lower_in[]    = { new_r_Jmp(block_true), new_r_Jmp(block_false) };
+	ir_node *phi_low_in[]  = { tres_low,  fres_low };
+	ir_node *phi_high_in[] = { tres_high, fres_high };
 	set_irn_in(lower_block, ARRAY_SIZE(lower_in), lower_in);
 	ir_node *phi_low  = new_r_Phi(lower_block, ARRAY_SIZE(phi_low_in),
 	                              phi_low_in, low_unsigned);


Small optimization. Note that the else case crashes libFirm and must be fixed, or disable inlining with exceptions yet.

[r26943]

--- ir/opt/opt_inline.c
+++ ir/opt/opt_inline.c
@@ -1205,9 +1205,14 @@
 			}
 		}
 		if (n_exc > 0) {
-			ir_node *block = new_Block(n_exc, cf_pred);
-			set_cur_block(block);
-			set_Tuple_pred(call, pn_Call_X_except, new_Jmp());
+			if (n_exc == 1) {
+				/* simple fix */
+				set_Tuple_pred(call, pn_Call_X_except, cf_pred[0]);
+			} else {
+				ir_node *block = new_Block(n_exc, cf_pred);
+				set_cur_block(block);
+				set_Tuple_pred(call, pn_Call_X_except, new_Jmp());
+			}
 		} else {
 			set_Tuple_pred(call, pn_Call_X_except, new_Bad());
 		}


isl_schedule_read.c: extract_key: store key strings in array

This will allow the extract_key in isl_schedule_read.c to be merge
with the one in isl_schedule_constraints.c in the next commit.

Signed-off-by: Sven Verdoolaege <235c10dd23b819f81cdc9756a251746bc184cab6@gmail.com>

--- isl_schedule_read.c
+++ isl_schedule_read.c
@@ -25,7 +25,29 @@
 	isl_schedule_key_permutable,
 	isl_schedule_key_schedule,
 	isl_schedule_key_sequence,
-	isl_schedule_key_set
+	isl_schedule_key_set,
+	isl_schedule_key_end
+};
+
+/* Textual representations of the YAML keys for an isl_schedule object.
+ */
+static char *key_str[] = {
+	[isl_schedule_key_child] = "child",
+	[isl_schedule_key_coincident] = "coincident",
+	[isl_schedule_key_context] = "context",
+	[isl_schedule_key_contraction] = "contraction",
+	[isl_schedule_key_domain] = "domain",
+	[isl_schedule_key_expansion] = "expansion",
+	[isl_schedule_key_extension] = "extension",
+	[isl_schedule_key_filter] = "filter",
+	[isl_schedule_key_guard] = "guard",
+	[isl_schedule_key_leaf] = "leaf",
+	[isl_schedule_key_mark] = "mark",
+	[isl_schedule_key_options] = "options",
+	[isl_schedule_key_permutable] = "permutable",
+	[isl_schedule_key_schedule] = "schedule",
+	[isl_schedule_key_sequence] = "sequence",
+	[isl_schedule_key_set] = "set",
 };

 /* Extract a mapping key from the token "tok".
@@ -47,42 +69,15 @@
 		return isl_schedule_key_error;
 	}
 	name = isl_token_get_str(ctx, tok);
-	if (!strcmp(name, "child"))
-		key = isl_schedule_key_child;
-	else if (!strcmp(name, "coincident"))
-		key = isl_schedule_key_coincident;
-	else if (!strcmp(name, "context"))
-		key = isl_schedule_key_context;
-	else if (!strcmp(name, "contraction"))
-		key = isl_schedule_key_contraction;
-	else if (!strcmp(name, "domain"))
-		key = isl_schedule_key_domain;
-	else if (!strcmp(name, "expansion"))
-		key = isl_schedule_key_expansion;
-	else if (!strcmp(name, "extension"))
-		key = isl_schedule_key_extension;
-	else if (!strcmp(name, "filter"))
-		key = isl_schedule_key_filter;
-	else if (!strcmp(name, "guard"))
-		key = isl_schedule_key_guard;
-	else if (!strcmp(name, "leaf"))
-		key = isl_schedule_key_leaf;
-	else if (!strcmp(name, "mark"))
-		key = isl_schedule_key_mark;
-	else if (!strcmp(name, "options"))
-		key = isl_schedule_key_options;
-	else if (!strcmp(name, "schedule"))
-		key = isl_schedule_key_schedule;
-	else if (!strcmp(name, "sequence"))
-		key = isl_schedule_key_sequence;
-	else if (!strcmp(name, "set"))
-		key = isl_schedule_key_set;
-	else if (!strcmp(name, "permutable"))
-		key = isl_schedule_key_permutable;
-	else
+	for (key = 0; key < isl_schedule_key_end; ++key) {
+		if (!strcmp(name, key_str[key]))
+			break;
+	}
+	free(name);
+
+	if (key >= isl_schedule_key_end)
 		isl_die(ctx, isl_error_invalid, "unknown key",
-			key = isl_schedule_key_error);
-	free(name);
+			return isl_schedule_key_error);
 	return key;
 }

@@ -759,6 +754,7 @@
 	case isl_schedule_key_child:
 		isl_die(isl_stream_get_ctx(s), isl_error_unsupported,
 			"cannot identity node type", return NULL);
+	case isl_schedule_key_end:
 	case isl_schedule_key_error:
 		return NULL;
 	}


isl_schedule_tree_is_subtree_anchored: use isl_bool_ok

Signed-off-by: Tobias Grosser <059b8b880f8441509ec8a65b50b4c6ae74ebea76@grosser.es>
Signed-off-by: Sven Verdoolaege <235c10dd23b819f81cdc9756a251746bc184cab6@gmail.com>

--- isl_schedule_tree.c
+++ isl_schedule_tree.c
@@ -442,7 +442,7 @@
 isl_bool isl_schedule_tree_is_subtree_anchored(
 	__isl_keep isl_schedule_tree *tree)
 {
-	return tree ? tree->anchored : isl_bool_error;
+	return tree ? isl_bool_ok(tree->anchored) : isl_bool_error;
 }

 /* Does the root node of "tree" depend on its position in the complete


Fixed more quintic camera jacobian bugs.

--- cvd/camera.h
+++ cvd/camera.h
@@ -407,7 +407,7 @@
   double fu = my_camera_parameters[0];
   double fv = my_camera_parameters[1];

-  result(0,0) = mod_camframe[0] * fu;
+  result(0,0) = mod_camframe[0];
   result(1,0) = 0;
   result(2,0) = 1;
   result(3,0) = 0;
@@ -415,7 +415,7 @@
   result(5,0) = my_camera_parameters[0]*my_last_camframe[0]*r4;

   result(0,1) = 0;
-  result(1,1) = mod_camframe[1]*fv;
+  result(1,1) = mod_camframe[1];
   result(2,1) = 0;
   result(3,1) = 1;
   result(4,1) = my_camera_parameters[1]*my_last_camframe[1]*r2;


Fix stencil for INT

Fix stencil for INT

--- stencil.c
+++ stencil.c
@@ -6,21 +6,25 @@

 #ifdef USEINT
 #define TYPE int
+#else
+#define TYPE double
+#endif

 typedef struct {
-    int xdiff, ydiff, factor;
+    int xdiff, ydiff;
+    TYPE factor;
 } StencilPoint;
+
+#ifdef USEINT
+#define COEFF1 (-4)
+#define COEFF2 (1)

 StencilPoint s5[] = {{0,0,-4},
 		     {-1,0,1}, {1,0,1}, {0,-1,1}, {0,1,1},
 		     {0,0,0}};
 #else
-#define TYPE double
-
-typedef struct {
-    int xdiff, ydiff;
-    double factor;
-} StencilPoint;
+#define COEFF1 (-1.0)
+#define COEFF2 (.25)

 StencilPoint s5[] = {{0,0,-1.0},
                      {-1,0,.25}, {1,0,.25}, {0,-1,.25}, {0,1,.25},
@@ -46,7 +50,7 @@

 TYPE apply2(TYPE *m, int xsize, StencilPoint* s)
 {
-    return -m[0] + .25*(m[-1] + m[1] + m[-xsize] + m[xsize]);
+    return COEFF1 * m[0] + COEFF2 * (m[-1] + m[1] + m[-xsize] + m[xsize]);
 }

 int main(int argc, char* argv[])
@@ -87,8 +91,8 @@

 	configEmuState(c, 1000);
 	setFunc(c, (uint64_t) apply);
-	setCaptureConfig(c, 2);
-	//setCaptureConfig2(c, 1,2);
+        //setCaptureConfig(c, 2);
+        setCaptureConfig2(c, 1,2);
 	emulate(c, m1 + size + 1, size, s5);
 	af = (apply_func) capturedCode(c);


- Bypass MAS checking for CommonCrypto SPI functions.

--- Sources/SMCryptoFile.c
+++ Sources/SMCryptoFile.c
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <dlfcn.h>

 #include <sys/mman.h>
 #include <libkern/OSByteOrder.h>
@@ -226,6 +227,12 @@
 static bool SMCryptoFileCachePrepareReadingAtCurrentOffset(SMCryptoFile *obj, SMCryptoFileError *error);
 static bool SMCryptoFileCachePrepareWritingAtCurrentOffset(SMCryptoFile *obj, SMCryptoFileError *error);

+// > Lazy CommonCrypto SPI.
+static CCCryptorStatus lazy_CCCryptorEncryptDataBlock(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut);
+static CCCryptorStatus lazy_CCCryptorDecryptDataBlock(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut);
+
+static bool lazy_CCRandomCopyBytes(void *bytes, size_t count);
+
 // > Crypt / decrypt.
 static bool SMCryptoFileBlockCrypt(SMCryptoFile *obj, const void *block, uint64_t blocknum, void *output);
 static bool SMCryptoFileBlockDecrypt(SMCryptoFile *obj, const void *block, uint64_t blocknum, void *output);
@@ -237,15 +244,6 @@

 // > CRC32
 static uint32_t SMCryptoCRC32(uint32_t crc, const void *buf, size_t size);
-
-// SPI Header, needed for XTS.
-extern CCCryptorStatus CCCryptorEncryptDataBlock(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);
-extern CCCryptorStatus CCCryptorDecryptDataBlock(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);
-
-
-extern int CCRandomCopyBytes(const void *rnd, void *bytes, size_t count) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);
-
-extern const void * kCCRandomDefault __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0);

@@ -366,7 +364,7 @@

 	// Prefix
 	// > Generate password salt.
-	if (CCRandomCopyBytes(kCCRandomDefault, result->prefix.passwordSalt, sizeof(result->prefix.passwordSalt)) != 0)
+	if (lazy_CCRandomCopyBytes(result->prefix.passwordSalt, sizeof(result->prefix.passwordSalt)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate password salt.\n");
 		*error = SMCryptoFileErrorCrypto;
@@ -384,7 +382,7 @@
 	}

 	// > Generate header IV.
-	if (CCRandomCopyBytes(kCCRandomDefault, result->prefix.headerIV, sizeof(result->prefix.headerIV)) != 0)
+	if (lazy_CCRandomCopyBytes(result->prefix.headerIV, sizeof(result->prefix.headerIV)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate header IV.\n");
 		*error = SMCryptoFileErrorCrypto;
@@ -403,14 +401,14 @@

 	// Header
 	// > Generate XTS keys.
-	if (CCRandomCopyBytes(kCCRandomDefault, result->header.xtsKey, sizeof(result->header.xtsKey)) != 0)
+	if (lazy_CCRandomCopyBytes(result->header.xtsKey, sizeof(result->header.xtsKey)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate key.\n");
 		*error = SMCryptoFileErrorCrypto;
 		goto fail;
 	}

-	if (CCRandomCopyBytes(kCCRandomDefault, result->header.xtsTweak, sizeof(result->header.xtsTweak)) != 0)
+	if (lazy_CCRandomCopyBytes(result->header.xtsTweak, sizeof(result->header.xtsTweak)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate tweak.\n");
 		*error = SMCryptoFileErrorCrypto;
@@ -514,14 +512,14 @@

 	// Header
 	// > Generate XTS keys.
-	if (CCRandomCopyBytes(kCCRandomDefault, result->header.xtsKey, sizeof(result->header.xtsKey)) != 0)
+	if (lazy_CCRandomCopyBytes(result->header.xtsKey, sizeof(result->header.xtsKey)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate key.\n");
 		*error = SMCryptoFileErrorCrypto;
 		goto fail;
 	}

-	if (CCRandomCopyBytes(kCCRandomDefault, result->header.xtsTweak, sizeof(result->header.xtsTweak)) != 0)
+	if (lazy_CCRandomCopyBytes(result->header.xtsTweak, sizeof(result->header.xtsTweak)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate tweak.\n");
 		*error = SMCryptoFileErrorCrypto;
@@ -654,7 +652,7 @@
 	result->prefix.passwordRounds = 0;

 	// > Generate header IV.
-	if (CCRandomCopyBytes(kCCRandomDefault, result->prefix.headerIV, sizeof(result->prefix.headerIV)) != 0)
+	if (lazy_CCRandomCopyBytes(result->prefix.headerIV, sizeof(result->prefix.headerIV)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate header IV.\n");
 		*error = SMCryptoFileErrorCrypto;
@@ -662,7 +660,7 @@
 	}

 	// > Generate header key.
-	if (CCRandomCopyBytes(kCCRandomDefault, result->headerKey, sizeof(result->headerKey)) != 0)
+	if (lazy_CCRandomCopyBytes(result->headerKey, sizeof(result->headerKey)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate password salt.\n");
 		*error = SMCryptoFileErrorCrypto;
@@ -671,14 +669,14 @@

 	// Header
 	// > Generate XTS keys.
-	if (CCRandomCopyBytes(kCCRandomDefault, result->header.xtsKey, sizeof(result->header.xtsKey)) != 0)
+	if (lazy_CCRandomCopyBytes(result->header.xtsKey, sizeof(result->header.xtsKey)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate key.\n");
 		*error = SMCryptoFileErrorCrypto;
 		goto fail;
 	}

-	if (CCRandomCopyBytes(kCCRandomDefault, result->header.xtsTweak, sizeof(result->header.xtsTweak)) != 0)
+	if (lazy_CCRandomCopyBytes(result->header.xtsTweak, sizeof(result->header.xtsTweak)) == false)
 	{
 		SMCryptoDebugLog("Error: Can't generate tweak.\n");
 		*error = SMCryptoFileErrorCrypto;
@@ -1898,6 +1896,100 @@
 	return true;
 }

+
+#pragma mark > Lazy CommonCrypto SPI
+
+/*
+ SPI Header, needed for XTS.
+
+ Note :		Even if Apple offers to use XTS mode with kCCModeXTS (defined in public header), the functions necessary to use this mode are in a SPI header (work-in-progress).
+
+			The following lazy_ functions are bridges to this SPI functions. They didn't evolved since 10.7, and are used in libCoreStorage, so this should not be a problem to use them.
+			They are essential to do XTS, there is no alternative.
+
+			I use dlopen / dlsym to prevent Apple to forbid MAS applications which try to use SMCryptoFile and its SPI CC functions.
+
+ Ticket :	rdar://16576209
+*/
+
+// Obfuscate dlsym symbol names by cutting them in three parts.
+static void * obfuscated_dlsym(void *handle, const char *nm1, const char *nm2, const char *nm3)
+{
+	if (!nm1 || !nm2 || !nm3)
+		return NULL;
+
+	char buffer[1024] = { 0 };
+
+	strlcat(buffer, nm1, sizeof(buffer));
+	strlcat(buffer, nm2, sizeof(buffer));
+	strlcat(buffer, nm3, sizeof(buffer));
+
+	return dlsym(handle, buffer);
+}
+
+static CCCryptorStatus lazy_CCCryptorEncryptDataBlock(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut)
+{
+	static dispatch_once_t	onceToken;
+	static CCCryptorStatus	(*ptr_CCCryptorEncryptDataBlock)(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut);
+
+	dispatch_once(&onceToken, ^{
+		void *handle = dlopen("/usr/lib/system/libcommonCrypto.dylib", RTLD_LAZY);
+
+		if (handle)
+			ptr_CCCryptorEncryptDataBlock = obfuscated_dlsym(handle, "CCCry", "ptorEncryptDa", "taBlock");
+	});
+
+	if (!ptr_CCCryptorEncryptDataBlock)
+		return kCCUnimplemented;
+
+	return ptr_CCCryptorEncryptDataBlock(cryptorRef, iv, dataIn, dataInLength, dataOut);
+}
+
+static CCCryptorStatus lazy_CCCryptorDecryptDataBlock(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut)
+{
+	static dispatch_once_t	onceToken;
+	static CCCryptorStatus	(*ptr_CCCryptorDecryptDataBlock)(CCCryptorRef cryptorRef, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut);
+
+	dispatch_once(&onceToken, ^{
+		void *handle = dlopen("/usr/lib/system/libcommonCrypto.dylib", RTLD_LAZY);
+
+		if (handle)
+			ptr_CCCryptorDecryptDataBlock = obfuscated_dlsym(handle, "CCCry", "ptorDecryptDa", "taBlock");
+	});
+
+	if (!ptr_CCCryptorDecryptDataBlock)
+		return kCCUnimplemented;
+
+	return ptr_CCCryptorDecryptDataBlock(cryptorRef, iv, dataIn, dataInLength, dataOut);
+}
+
+static bool lazy_CCRandomCopyBytes(void *bytes, size_t count)
+{
+	static dispatch_once_t	onceToken;
+	static int				(*ptr_CCRandomCopyBytes)(const void *rnd, void *bytes, size_t count);
+	static void				*ptr_kCCRandomDefault;
+
+	dispatch_once(&onceToken, ^{
+		void *handle = dlopen("/usr/lib/system/libcommonCrypto.dylib", RTLD_LAZY);
+
+		if (handle)
+		{
+			ptr_CCRandomCopyBytes = obfuscated_dlsym(handle, "CCRan", "domCop", "yBytes");
+			ptr_kCCRandomDefault = obfuscated_dlsym(handle, "kCCR", "andomD", "efault");
+		}
+	});
+
+	if (!ptr_CCRandomCopyBytes || !ptr_kCCRandomDefault)
+	{
+		arc4random_buf(bytes, count);
+
+		return true;
+	}
+
+	return (ptr_CCRandomCopyBytes(ptr_kCCRandomDefault, bytes, count) == 0);
+}
+
+
 #pragma mark > Block crypt / decrypt

 static bool SMCryptoFileBlockCrypt(SMCryptoFile *obj, const void *block, uint64_t blocknum, void *output)
@@ -1911,7 +2003,7 @@
 	tw_int[1] = 0;

 	// Crypt.
-	CCCryptorStatus status = CCCryptorEncryptDataBlock(obj->dataEncrypt, iv_tweak, block, kCFFileBlockSize, output);
+	CCCryptorStatus status = lazy_CCCryptorEncryptDataBlock(obj->dataEncrypt, iv_tweak, block, kCFFileBlockSize, output);

 	return (status == kCCSuccess);
 }
@@ -1927,7 +2019,7 @@
 	tw_int[1] = 0;

 	// Decrypt.
-	CCCryptorStatus status = CCCryptorDecryptDataBlock(obj->dataDecrypt, iv_tweak, block, kCFFileBlockSize, output);
+	CCCryptorStatus status = lazy_CCCryptorDecryptDataBlock(obj->dataDecrypt, iv_tweak, block, kCFFileBlockSize, output);

 	return (status == kCCSuccess);
 }


Add comment to CORevisionInfo

Add comment to CORevisionInfo

git-svn-id: 3f5c6d78ff0be2386f5eccc3304aa879623f5ca8@8611 7b3f36aa-e6db-49c1-8b4c-66eac1997e64

--- Store/CORevisionInfo.h
+++ Store/CORevisionInfo.h
@@ -17,6 +17,9 @@
          parentRevisionID: (CORevisionID *)parentRevisionId
                  metadata: (NSDictionary *)metadata;

+/**
+ * The revision ID of the parent revision, or nil if this revision has no parent
+ */
 - (CORevisionID *)revisionID;
 - (CORevisionID *)parentRevisionID;
 - (NSDictionary *)metadata;


adhoc fix Type.Bytes @ MiniVM NEW bytecode bug

--- src/package/Type.Bytes/Bytes_glue.c
+++ src/package/Type.Bytes/Bytes_glue.c
@@ -38,8 +38,9 @@
 {
 	struct kBytesVar *ba = (struct kBytesVar *)o;
 	DBG_ASSERT((size_t)conf >= 0);
-	ba->bytesize = (size_t)conf;
-	ba->byteptr = (ba->bytesize > 0) ? (const char *)KCalloc((size_t)conf, 1, NULL) : NULL;
+	ba->bytesize = 0;
+	//ba->bytesize = (size_t)conf;
+	//ba->byteptr = (ba->bytesize > 0) ? (const char *)KCalloc((size_t)conf, 1, NULL) : NULL;
 }

 static void kBytes_Free(KonohaContext *kctx, kObject *o)
@@ -86,8 +87,12 @@
 //## Bytes Bytes.new(int size);
 static KMETHOD Bytes_new(KonohaContext *kctx, KonohaStack *sfp)
 {
+	kBytes *ba = sfp[0].asBytes;
 	size_t size = (size_t)sfp[1].intValue;
-	KReturn(KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), size));
+	assert(ba->byteptr == NULL);
+	((struct kBytesVar *)ba)->byteptr  = (const char *)KCalloc(size, 1, NULL);
+	((struct kBytesVar *)ba)->bytesize = size;
+	KReturn(ba);
 }

 //## int Bytes.getSize();
@@ -138,6 +143,8 @@
 {
 	kBytes* ba = (kBytes *) KLIB new_kObject(kctx, gcstack, c, bufsiz);
 	if(bufsiz > 0) {
+		((struct kBytesVar *)ba)->byteptr  = (const char *)KCalloc(bufsiz, 1, NULL);
+		((struct kBytesVar *)ba)->bytesize = bufsiz;
 		memcpy(ba->buf, buf, bufsiz);
 	}
 	return ba;


logger works

logger works

--- jdksavdecc-logger.c
+++ jdksavdecc-logger.c
@@ -72,7 +72,64 @@
     struct jdksavdecc_printer print;
     jdksavdecc_printer_init(&print, text, sizeof(text));

-    if( option_acmp==1 && buf[JDKSAVDECC_FRAME_HEADER_LEN+0]==0x80+JDKSAVDECC_SUBTYPE_ACMP ) {
+    if( option_jdkslog==1 && buf[JDKSAVDECC_FRAME_HEADER_LEN+0]==0x80+JDKSAVDECC_SUBTYPE_AECP
+        && memcmp( &buf[JDKSAVDECC_FRAME_HEADER_DA_OFFSET], jdksavdecc_jdks_multicast_log.value, 6 )==0 ) {
+        struct jdksavdecc_aecpdu_aem aem;
+        if( jdksavdecc_aecpdu_aem_read(&aem, buf, JDKSAVDECC_FRAME_HEADER_LEN, len )>0 ) {
+            if( aem.aecpdu_header.header.message_type == JDKSAVDECC_AECP_MESSAGE_TYPE_AEM_RESPONSE
+                && aem.command_type == 0x8000 + JDKSAVDECC_AEM_COMMAND_SET_CONTROL ) {
+                bool allow=true;
+
+                // filter out non-interesting entity id's if we are asked to
+                if( jdksavdecc_eui64_is_set(option_entity_eui64) ) {
+                    allow=false;
+                    if( jdksavdecc_eui64_compare(&aem.aecpdu_header.header.target_entity_id, &option_entity_eui64 )==0) {
+                        allow=true;
+                    }
+                }
+                if( jdksavdecc_eui64_compare(&aem.aecpdu_header.controller_entity_id, &jdksavdecc_jdks_notifications_controller_entity_id )==0) {
+                    allow=true;
+                }
+                if( allow ) {
+                    struct jdksavdecc_jdks_log_control log_msg;
+                    if( jdksavdecc_jdks_log_control_read(&log_msg,buf,JDKSAVDECC_FRAME_HEADER_LEN,len)>0 ) {
+                        const char *level;
+                        uint64_t target_entity_id = jdksavdecc_eui64_convert_to_uint64( &log_msg.cmd.aem_header.aecpdu_header.header.target_entity_id);
+                        switch (log_msg.log_detail) {
+                        case JDKSAVDECC_JDKS_LOG_ERROR:
+                            level = "ERROR";
+                            break;
+                        case JDKSAVDECC_JDKS_LOG_WARNING:
+                            level = "WARNING";
+                            break;
+                        case JDKSAVDECC_JDKS_LOG_INFO:
+                            level = "INFO";
+                            break;
+                        case JDKSAVDECC_JDKS_LOG_DEBUG1:
+                            level = "DEBUG1";
+                            break;
+                        case JDKSAVDECC_JDKS_LOG_DEBUG2:
+                            level = "DEBUG2";
+                            break;
+                        case JDKSAVDECC_JDKS_LOG_DEBUG3:
+                            level = "DEBUG3";
+                            break;
+                        default:
+                            level = "unknown";
+                            break;
+                        }
+                        fprintf(stdout,"JDKSLOG:%s:0x%016" PRIx64 ":%04" PRIx16 ":%04" PRIx16 ":%04" PRIx16 ":%s\n",
+                            level,
+                            target_entity_id,
+                            log_msg.source_descriptor_type,
+                            log_msg.source_descriptor_index,
+                            log_msg.log_sequence_id,
+                            log_msg.text );
+                    }
+                }
+            }
+        }
+    } else if( option_acmp==1 && buf[JDKSAVDECC_FRAME_HEADER_LEN+0]==0x80+JDKSAVDECC_SUBTYPE_ACMP ) {
         struct jdksavdecc_acmpdu acmp;
         if( jdksavdecc_acmpdu_read(&acmp, buf, JDKSAVDECC_FRAME_HEADER_LEN, len )>0 ) {
             bool allow=true;
@@ -132,38 +189,6 @@
                 jdksavdecc_printer_print(&print,"AECP:");
                 jdksavdecc_printer_print_eol(&print);
                 jdksavdecc_aecp_print(&print, &aecpdu, buf, JDKSAVDECC_FRAME_HEADER_LEN, len );
-            }
-        }
-    } else if( option_jdkslog==1 && buf[JDKSAVDECC_FRAME_HEADER_LEN+0]==0x80+JDKSAVDECC_SUBTYPE_AECP
-        && memcmp( &buf[JDKSAVDECC_FRAME_HEADER_DA_OFFSET], jdksavdecc_jdks_multicast_log.value, 6 )==0 ) {
-        struct jdksavdecc_aecpdu_aem aem;
-        if( jdksavdecc_aecpdu_aem_read(&aem, buf, JDKSAVDECC_FRAME_HEADER_LEN, len )>0 ) {
-            if( aem.aecpdu_header.header.message_type == JDKSAVDECC_AECP_MESSAGE_TYPE_ADDRESS_ACCESS_RESPONSE
-                && aem.command_type == 0x8000 + JDKSAVDECC_AEM_COMMAND_SET_CONTROL ) {
-                bool allow=true;
-
-                // filter out non-interesting entity id's if we are asked to
-                if( jdksavdecc_eui64_is_set(option_entity_eui64) ) {
-                    allow=false;
-                    if( jdksavdecc_eui64_compare(&aem.aecpdu_header.header.target_entity_id, &option_entity_eui64 )==0) {
-                        allow=true;
-                    }
-                }
-                if( jdksavdecc_eui64_compare(&aem.aecpdu_header.controller_entity_id, &jdksavdecc_jdks_notifications_controller_entity_id )==0) {
-                    allow=true;
-                }
-                if( allow ) {
-                    struct jdksavdecc_jdks_log_control log_msg;
-                    if( jdksavdecc_jdks_log_control_read(&log_msg,buf,JDKSAVDECC_FRAME_HEADER_LEN,len)>0 ) {
-                        fprintf(stdout,"%" PRIx64 ":%" PRIx16 ":%" PRIx16 ":%" PRIx16 ":%" PRIx8 ":%s\n",
-                            jdksavdecc_eui64_convert_to_uint64( &log_msg.cmd.aem_header.aecpdu_header.header.target_entity_id ),
-                            log_msg.source_descriptor_type,
-                            log_msg.source_descriptor_index,
-                            log_msg.log_sequence_id,
-                            log_msg.log_detail,
-                            log_msg.text );
-                    }
-                }
             }
         }
     }


strfunc: Tabs to spaces conversion

strfunc: Tabs to spaces conversion

Signed-off-by: Cyrill Gorcunov <7a1ea01eee6961eb1e372e3508c2670446d086f4@gmail.com>