Add support for floats; speed-up calls

Add support for floats; speed-up calls

--- toolchain/vbcc/machines/mark/machine.c
+++ toolchain/vbcc/machines/mark/machine.c
@@ -335,7 +335,7 @@

     //make space for auto variables at stack
     for(int i = 0; i < zm2l(offset); i++){
-        emit(f, "\tPUSH \t R0\n");
+        emit(f, "\tDEC \t %s %s\n", regnames[SP], regnames[SP]);
     }

     //store backend registers
@@ -522,13 +522,13 @@
                             case EXTERN:
                                 emit(f, "\tCALL \t %s\n", p->q1.v->identifier);
                                 for(int i = 0; i < (p->q2.val.vmax); i++){
-                                    emit(f, "\tPOP \t R0\n");
+                                    emit(f, "\tINC \t %s %s\n", regnames[SP], regnames[SP]);
                                 }
                                 break;
                             case STATIC:
                                 emit(f, "\tCALL \t L_%ld\n", zm2l(p->q1.v->offset));
                                 for(int i = 0; i < (p->q2.val.vmax); i++){
-                                    emit(f, "\tPOP \t R0\n");
+                                    emit(f, "\tINC \t %s %s\n", regnames[SP], regnames[SP]);
                                 }
                                 break;
                             default:
@@ -812,17 +812,11 @@
     printf("Called gen_dc(FILE *f,int t,struct const_list *p)\n");
     #endif

-    //FIXME: generování DC
-    // tady je blbě to šaškování s floatem, šaškovat se musí to je jasný,  říká to doku ale
-    // formát je úplně blbě, však MARK ještě float vůbec neřešil
-
     if(!p->tree){
         if(ISFLOAT(t)){
-            #ifdef DEBUG_MARK
-            printf("Float numbers are not supported!\n");
-            #else
-            ierror(0);
-            #endif
+            emit(f,"\t.DAT \t ");
+            emit(f,"0x%x", *(unsigned int*)&p->val);
+            emit(f,"\n");
         }
         else{
             emit(f,"\t.DAT \t ");
@@ -896,60 +890,75 @@
     }

     //emit compare code
-    switch(branch_ic->code){
-        case BEQ:
-            emit(f, "\tCMP \t EQ %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-            break;
-        case BNE:
-            emit(f, "\tCMP \t NEQ %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-            break;
-        case BLT:
-            if((p->typf & UNSIGNED) == UNSIGNED){
-                emit(f, "\tCMP \t LU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-            }
-            else{
-                emit(f, "\tCMP \t L %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-            }
-            break;
-        case BGE:
-            if((p->typf & UNSIGNED) == UNSIGNED){
-                emit(f, "\tCMP \t GEU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-            }
-            else{
-                emit(f, "\tCMP \t GE %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-            }
-            break;
-        case BLE:
-            if((p->typf & UNSIGNED) == UNSIGNED){
-                emit(f, "\tCMP \t LU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-                emit(f, "\tCMP \t EQ %s %s %s\n", regnames[q2reg], regnames[q1reg], regnames[q2reg]);
-                emit(f, "\tOR  \t %s R4 R4\n", regnames[q2reg]);
-            }
-            else{
-                emit(f, "\tCMP \t L %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-                emit(f, "\tCMP \t EQ %s %s %s\n", regnames[q2reg], regnames[q1reg], regnames[q2reg]);
-                emit(f, "\tOR  \t %s R4 R4\n", regnames[q2reg]);
-            }
-            break;
-        case BGT:
-            if((p->typf & UNSIGNED) == UNSIGNED){
-                emit(f, "\tCMP \t GEU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-                emit(f, "\tCMP \t NEQ %s %s %s\n", regnames[q2reg], regnames[q1reg], regnames[q2reg]);
-                emit(f, "\tAND \t %s R4 R4\n", regnames[q2reg]);
-            }
-            else{
-                emit(f, "\tCMP \t GE %s %s R4\n", regnames[q2reg], regnames[q1reg]);
-                emit(f, "\tCMP \t NEQ %s %s %s\n", regnames[q2reg], regnames[q1reg], regnames[q2reg]);
-                emit(f, "\tAND \t %s R4 R4\n", regnames[q2reg]);
-            }
-            break;
-        default:
-            #ifdef DEBUG_MARK
-            printf("\tunknown condition!\n");
-            #else
-            ierror(0);
-            #endif
-            break;
+    if (((p->typf) & FLOAT) == FLOAT || ((p->typf) & DOUBLE) == DOUBLE || ((p->typf) & LDOUBLE) == LDOUBLE){
+        switch(branch_ic->code){
+            case BEQ:
+                emit(f, "\tCMPF \t EQ %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            case BNE:
+                emit(f, "\tCMPF \t NEQ %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            case BLT:
+                emit(f, "\tCMPF \t L %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            case BGE:
+                emit(f, "\tCMPF \t GE %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            case BLE:
+                emit(f, "\tCMPF \t LE %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            case BGT:
+                emit(f, "\tCMPF \t G %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            default:
+                ierror(0);
+                break;
+        }
+    }
+    else{
+        switch(branch_ic->code){
+            case BEQ:
+                emit(f, "\tCMPI \t EQ %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            case BNE:
+                emit(f, "\tCMPI \t NEQ %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                break;
+            case BLT:
+                if((p->typf & UNSIGNED) == UNSIGNED){
+                    emit(f, "\tCMPI \t LU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                else{
+                    emit(f, "\tCMPI \t L %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                break;
+            case BGE:
+                if((p->typf & UNSIGNED) == UNSIGNED){
+                    emit(f, "\tCMPI \t GEU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                else{
+                    emit(f, "\tCMPI \t GE %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                break;
+            case BLE:
+                if((p->typf & UNSIGNED) == UNSIGNED){
+                    emit(f, "\tCMPI \t LEU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                else{
+                    emit(f, "\tCMPI \t LE %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                break;
+            case BGT:
+                if((p->typf & UNSIGNED) == UNSIGNED){
+                    emit(f, "\tCMPI \t GU %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                else{
+                    emit(f, "\tCMPI \t G %s %s R4\n", regnames[q2reg], regnames[q1reg]);
+                }
+                break;
+            default:
+                ierror(0);
+                break;
+        }
     }
 }

@@ -1324,7 +1333,6 @@
         isunsigned = 1;
     }

-
     if(((p->code) == MINUS) || ((p->code) == KOMPLEMENT)){
         unary = 1;
     }
@@ -1358,80 +1366,101 @@
         movez = 1;
     }

-    //emit instruction opcode
-    switch(p->code){
-        case OR:
-            emit(f, "\tOR  \t ");
-            break;
-        case XOR:
-            emit(f, "\tXOR \t ");
-            break;
-        case AND:
-            emit(f, "\tAND \t ");
-            break;
-        case LSHIFT:
-            emit(f, "\tLSL \t ");
-            break;
-        case RSHIFT:
-            if(isunsigned == 1) {
-                emit(f, "\tLSR \t ");
-            }
-            else{
-                emit(f, "\tASR \t ");
-            }
-            break;
-        case ADD:
-            emit(f, "\tADD \t ");
-            break;
-        case SUB:
-            emit(f, "\tSUB \t ");
-            break;
-        case MULT:
-            if(isunsigned == 1) {
-                emit(f, "\tMULU \t ");
-            }
-            else{
-                emit(f, "\tMUL \t ");
-            }
-            break;
-        case DIV:
-            if(isunsigned == 1) {
-                emit(f, "\tDIVU \t ");
-            }
-            else{
-                emit(f, "\tDIV \t ");
-            }
-            break;
-        case MOD:
-            if(isunsigned == 1) {
-                emit(f, "\tREMU \t ");
-            }
-            else{
-                emit(f, "\tREM \t ");
-            }
-            break;
-        case ADDI2P:
-            emit(f, "\tADD \t ");
-            break;
-        case SUBIFP:
-            emit(f, "\tSUB \t ");
-            break;
-        case SUBPFP:
-            emit(f, "\tSUB \t ");
-            break;
-        case MINUS:
-            emit(f, "\tDEC \t ");
-            break;
-        case KOMPLEMENT:
-            emit(f, "\tNOT \t ");
-            break;
-        default:
-            #ifdef DEBUG_MARK
-            printf("\tPassed invalid IC into arithmetic()\n\tp->code: %d\n", p->code);
-            #else
-            ierror(0);
-            #endif
-            break;
+    if (((p->typf) & FLOAT) == FLOAT || ((p->typf) & DOUBLE) == DOUBLE || ((p->typf) & LDOUBLE) == LDOUBLE){
+        switch(p->code){
+            case ADD:
+                emit(f, "\tFADD \t ");
+                break;
+            case SUB:
+                emit(f, "\tFSUB \t ");
+                break;
+            case MULT:
+                emit(f, "\tFMUL \t ");
+                break;
+            case DIV:
+                emit(f, "\tFDIV \t ");
+                break;
+            default:
+                ierror(0);
+        }
+    }
+    else{
+
+        //emit instruction opcode
+        switch(p->code){
+            case OR:
+                emit(f, "\tOR  \t ");
+                break;
+            case XOR:
+                emit(f, "\tXOR \t ");
+                break;
+            case AND:
+                emit(f, "\tAND \t ");
+                break;
+            case LSHIFT:
+                emit(f, "\tLSL \t ");
+                break;
+            case RSHIFT:
+                if(isunsigned == 1) {
+                    emit(f, "\tLSR \t ");
+                }
+                else{
+                    emit(f, "\tASR \t ");
+                }
+                break;
+            case ADD:
+                emit(f, "\tADD \t ");
+                break;
+            case SUB:
+                emit(f, "\tSUB \t ");
+                break;
+            case MULT:
+                if(isunsigned == 1) {
+                    emit(f, "\tMULU \t ");
+                }
+                else{
+                    emit(f, "\tMUL \t ");
+                }
+                break;
+            case DIV:
+                if(isunsigned == 1) {
+                    emit(f, "\tDIVU \t ");
+                }
+                else{
+                    emit(f, "\tDIV \t ");
+                }
+                break;
+            case MOD:
+                if(isunsigned == 1) {
+                    emit(f, "\tREMU \t ");
+                }
+                else{
+                    emit(f, "\tREM \t ");
+                }
+                break;
+            case ADDI2P:
+                emit(f, "\tADD \t ");
+                break;
+            case SUBIFP:
+                emit(f, "\tSUB \t ");
+                break;
+            case SUBPFP:
+                emit(f, "\tSUB \t ");
+                break;
+            case MINUS:
+                emit(f, "\tDEC \t ");
+                break;
+            case KOMPLEMENT:
+                emit(f, "\tNOT \t ");
+                break;
+            default:
+                #ifdef DEBUG_MARK
+                printf("\tPassed invalid IC into arithmetic()\n\tp->code: %d\n", p->code);
+                #else
+                ierror(0);
+                #endif
+                break;
+        }
     }

     //emit instruction arguments
@@ -1458,6 +1487,6 @@
         emit(f, "\t.MVI \t %s %ld\n", regnames[reg], value);
     }
     else{
-        emit(f, "\t.MVI \t %s %x\n", regnames[reg], value);
-    }
-}
+        emit(f, "\t.MVI \t %s 0x%x\n", regnames[reg], value);
+    }
+}


Now that streaming replication switches between streaming mode and
restoring from archive, the last WAL segment is not necessarily open at
the end of recovery. Fix assertion that assumed that.

Fujii Masao, fixing the assertion failure reported by Martin Pihlak.

--- src/backend/access/transam/xlog.c
+++ src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.369 2010/02/08 09:08:51 heikki Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.370 2010/02/10 08:25:25 heikki Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -5085,16 +5085,14 @@
 	UpdateMinRecoveryPoint(InvalidXLogRecPtr, true);

 	/*
-	 * We should have the ending log segment currently open.  Verify, and then
-	 * close it (to avoid problems on Windows with trying to rename or delete
-	 * an open file).
-	 */
-	Assert(readFile >= 0);
-	Assert(readId == endLogId);
-	Assert(readSeg == endLogSeg);
-
-	close(readFile);
-	readFile = -1;
+	 * If the ending log segment is still open, close it (to avoid
+	 * problems on Windows with trying to rename or delete an open file).
+	 */
+	if (readFile >= 0)
+	{
+		close(readFile);
+		readFile = -1;
+	}

 	/*
 	 * If the segment was fetched from archival storage, we want to replace


Put #ifdef NOT_USED around posix_fadvise call.  We may want to resurrect this someday, but right now it seems that posix_fadvise is immature to the point of being broken on many platforms ... and we don't have any benchmark evidence proving it's worth spending time on.

--- src/backend/access/transam/xlog.c
+++ src/backend/access/transam/xlog.c
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.241 2006/06/22 20:42:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.242 2006/06/27 18:59:17 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2153,7 +2153,16 @@
 {
 	Assert(openLogFile >= 0);

-#if defined(HAVE_DECL_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
+	/*
+	 * posix_fadvise is problematic on many platforms: on older x86 Linux
+	 * it just dumps core, and there are reports of problems on PPC platforms
+	 * as well.  The following is therefore disabled for the time being.
+	 * We could consider some kind of configure test to see if it's safe to
+	 * use, but since we lack hard evidence that there's any useful performance
+	 * gain to be had, spending time on that seems unprofitable for now.
+	 */
+#ifdef NOT_USED
+
 	/*
 	 * WAL segment files will not be re-read in normal operation, so we advise
 	 * OS to release any cached pages.  But do not do so if WAL archiving is
@@ -2163,9 +2172,12 @@
 	 * While O_DIRECT works for O_SYNC, posix_fadvise() works for fsync()
 	 * and O_SYNC, and some platforms only have posix_fadvise().
 	 */
+#if defined(HAVE_DECL_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
 	if (!XLogArchivingActive())
 		posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED);
 #endif
+
+#endif /* NOT_USED */

 	if (close(openLogFile))
 		ereport(PANIC,


Remove long-dead 'fix for SELECT NULL' to stop current coredump.

--- src/backend/executor/execTuples.c
+++ src/backend/executor/execTuples.c
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.50 2001/10/28 06:25:43 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.51 2002/03/21 06:21:04 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -593,8 +593,7 @@
 			TupleDescInitEntry(typeInfo,
 							   resdom->resno,
 							   resdom->resname,
-			/* fix for SELECT NULL ... */
-							   (restype ? restype : UNKNOWNOID),
+							   restype,
 							   resdom->restypmod,
 							   0,
 							   false);


Rewrite / simplify code

Rewrite / simplify code

--- m-snapshot.h
+++ m-snapshot.h
@@ -344,7 +344,7 @@
   } while (!atomic_compare_exchange_weak(&s->lastNext, &previous, newNext));
   if (SNAPSHOTI_MRSW_INT_FLAG_N(previous)) {
     // Reuse previous buffer as it was not used by any reader
-    s->currentWrite = SNAPSHOTI_MRSW_INT_FLAG_W(previous);
+    idx = SNAPSHOTI_MRSW_INT_FLAG_W(previous);
   } else {
     // Free the write index
     idx = SNAPSHOTI_MRSW_INT_FLAG_W(previous);
@@ -352,14 +352,16 @@
     assert (c != 0 && c <= s->n + 1);
     // Get a new buffer.
     if (c != 1)
+      // If someone else keeps a ref on the buffer, we can't reuse it
+      // get another free one
       idx = genint_pop(s->freeList);
-    s->currentWrite = idx;
     assert (idx < s->n + SNAPSHOTI_MRSW_EXTRA_BUFFER);
     assert (atomic_load(&s->cptTab[idx]) == 0);
     atomic_store(&s->cptTab[idx], 1);
   }
-  SNAPSHOTI_MRSW_INT_CONTRACT(s);
-  return s->currentWrite;
+  s->currentWrite = idx;
+  SNAPSHOTI_MRSW_INT_CONTRACT(s);
+  return idx;
 }

 static inline unsigned int snapshot_mrsw_int_read_start(snapshot_mrsw_int_t s)


Fix from Vadim for simple-minded case SELECT 1 WHERE 1 IN (SELECT 1)  used in regression tests. No longer core dumps.

--- src/backend/executor/nodeResult.c
+++ src/backend/executor/nodeResult.c
@@ -27,7 +27,7 @@
  *				   SeqScan (emp.all)
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.6 1998/02/13 03:26:52 vadim Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.7 1998/02/18 07:19:34 thomas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -291,7 +291,8 @@
 	 * if chgParam of subnode is not null then plan
 	 * will be re-scanned by first ExecProcNode.
 	 */
-	if (((Plan*) node)->lefttree->chgParam == NULL)
+	if (((Plan*) node)->lefttree &&
+			((Plan*) node)->lefttree->chgParam == NULL)
 		ExecReScan (((Plan*) node)->lefttree, exprCtxt, (Plan *) node);

 }


Update obsolete comment.

Update obsolete comment.

--- src/backend/executor/nodeUnique.c
+++ src/backend/executor/nodeUnique.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/executor/nodeUnique.c,v 1.41 2003/11/29 19:51:48 pgsql Exp $
+ *	  $PostgreSQL: pgsql/src/backend/executor/nodeUnique.c,v 1.42 2004/03/02 22:05:24 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -104,9 +104,13 @@
 	 *
 	 * Note that we manage the copy ourselves.	We can't rely on the result
 	 * tuple slot to maintain the tuple reference because our caller may
-	 * replace the slot contents with a different tuple (see junk filter
-	 * handling in execMain.c).  We assume that the caller will no longer
-	 * be interested in the current tuple after he next calls us.
+	 * replace the slot contents with a different tuple.  We assume that
+	 * the caller will no longer be interested in the current tuple after
+	 * he next calls us.
+	 *
+	 * tgl 3/2004: the above concern is no longer valid; junkfilters used to
+	 * modify their input's return slot but don't anymore, and I don't think
+	 * anyplace else does either.  Not worth changing this code though.
 	 */
 	if (node->priorTuple != NULL)
 		heap_freetuple(node->priorTuple);


Fix variable and type name in comment.

Fix variable and type name in comment.

Kyotaro Horiguchi

Discussion: b4f823aad3c973dfa9d4025f8158660cd0713b59@lab.ntt.co.jp

--- src/backend/storage/ipc/standby.c
+++ src/backend/storage/ipc/standby.c
@@ -587,10 +587,10 @@
  * one transaction on one relation.
  *
  * We keep a single dynamically expandible list of locks in local memory,
- * RelationLockList, so we can keep track of the various entries made by
+ * RecoveryLockList, so we can keep track of the various entries made by
  * the Startup process's virtual xid in the shared lock table.
  *
- * List elements use type xl_rel_lock, since the WAL record type exactly
+ * List elements use type xl_standby_lock, since the WAL record type exactly
  * matches the information that we need to keep track of.
  *
  * We use session locks rather than normal locks so we don't need


Check for out-of-range varoattno in deparse_context_for_subplan. I have seen this case in CVS tip due to new "physical tlist" optimization for subqueries.  I believe it probably can't happen in existing releases, but the check is not going to hurt anything, so backpatch to 8.0 just in case.

--- src/backend/utils/adt/ruleutils.c
+++ src/backend/utils/adt/ruleutils.c
@@ -3,7 +3,7 @@
  *				back to source text
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.203 2005/07/02 17:01:50 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.204 2005/07/15 18:39:59 tgl Exp $
  *
  *	  This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -1510,11 +1510,17 @@
 			if (var->varnoold > 0 && var->varnoold <= rtablelength)
 			{
 				RangeTblEntry *varrte = rt_fetch(var->varnoold, rtable);
-				char	   *varname;
-
-				varname = get_rte_attribute_name(varrte, var->varoattno);
-				attrs = lappend(attrs, makeString(varname));
-				continue;
+				AttrNumber varattnum = var->varoattno;
+
+				/* need this test in case it's referencing a resjunk col */
+				if (varattnum <= list_length(varrte->eref->colnames))
+				{
+					char	   *varname;
+
+					varname = get_rte_attribute_name(varrte, varattnum);
+					attrs = lappend(attrs, makeString(varname));
+					continue;
+				}
 			}
 		}
 		/* Fallback if can't get name */


Encode call by immediate address and register

--- src/backend/x86_64/instructions.c
+++ src/backend/x86_64/instructions.c
@@ -305,6 +305,28 @@
     return c;
 }

+static struct code call(enum instr_optype optype, union operand op)
+{
+    struct code c = {{0}};
+
+    if (optype == OPT_IMM) {
+        assert(op.imm.type == IMM_ADDR);
+        assert(op.imm.d.addr.sym);
+
+        c.val[c.len++] = 0xE8;
+        elf_add_relocation(op.imm.d.addr.sym, c.len, op.imm.d.addr.disp);
+        c.len += 4;
+    } else {
+        assert(optype == OPT_REG);
+
+        c.val[c.len++] = REX | W(op.reg) | R(op.reg);
+        c.val[c.len++] = 0xFF;
+        c.val[c.len++] = 0xD0 | reg(op.reg);
+    }
+
+    return c;
+}
+
 static struct code cmp(
     enum instr_optype optype,
     union operand a,
@@ -430,6 +452,8 @@
     switch (instr.opcode) {
     case INSTR_ADD:
         return add(instr.optype, instr.source, instr.dest);
+    case INSTR_CALL:
+        return call(instr.optype, instr.source);
     case INSTR_CMP:
         return cmp(instr.optype, instr.source, instr.dest);
     case INSTR_MOV:


Don't leak memory in test_sharedbook to please asan.

--- lib/sharedbook.c
+++ lib/sharedbook.c
@@ -581,6 +581,7 @@
       exit(1);
     }
   }
+  free(out);
 }

 int main(){


v0.07

--- shanks.c
+++ shanks.c
@@ -21,6 +21,7 @@
          i++;
      }
      s[i] = '\0';
+     printf("%d",i);
      fclose(f);
      Lexemes *liste = al(s);//analyse lexicale
      Lexemes_toString(liste);


Fix old sigaction display

Fix old sigaction display

* signal.c (sys_sigaction): Fix display of sigaction with
SIG_DFL/SIG_IGN handlers.

Signed-off-by: Denys Vlasenko <50fbbd36fe0f9c8261d4a3c762c8c29ffb35e48f@redhat.com>

--- signal.c
+++ signal.c
@@ -1022,20 +1022,20 @@
 			}
 #endif /* !USE_PROCFS */
 			tprintf("{%#lx, ", (long) sa.SA_HANDLER);
+		}
 #ifndef LINUX
-			printsigmask(&sa.sa_mask, 0);
+		printsigmask(&sa.sa_mask, 0);
 #else
-			long_to_sigset(sa.sa_mask, &sigset);
-			printsigmask(&sigset, 0);
-#endif
-			tprints(", ");
-			printflags(sigact_flags, sa.sa_flags, "SA_???");
+		long_to_sigset(sa.sa_mask, &sigset);
+		printsigmask(&sigset, 0);
+#endif
+		tprints(", ");
+		printflags(sigact_flags, sa.sa_flags, "SA_???");
 #ifdef SA_RESTORER
-			if (sa.sa_flags & SA_RESTORER)
-				tprintf(", %p", sa.sa_restorer);
-#endif
-			tprints("}");
-		}
+		if (sa.sa_flags & SA_RESTORER)
+			tprintf(", %p", sa.sa_restorer);
+#endif
+		tprints("}");
 	}
 	if (entering(tcp))
 		tprints(", ");


2005-04-05  Anton Blanchard  <anton@samba.org>

	* signal.c (signame): Don't try and dereference negative index.

--- signal.c
+++ signal.c
@@ -267,7 +267,7 @@
 int sig;
 {
 	static char buf[30];
-	if (sig < nsignals) {
+	if (sig >= 0 && sig < nsignals) {
 		return signalent[sig];
 #ifdef SIGRTMIN
 	} else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {


Engage two-nearest.

Engage two-nearest.

--- simwin.c
+++ simwin.c
@@ -1037,6 +1037,9 @@
 		case (MAPMIGRANT_NEAREST):
 			ms = kml_migration_nearest(kml->kmls, maptop);
 			break;
+		case (MAPMIGRANT_TWONEAREST):
+			ms = kml_migration_twonearest(kml->kmls, maptop);
+			break;
 		default:
 			break;
 		}


Better comparison between shared ptrs even if from different classes (ex base/inherited)

--- src/chrono/core/ChSmartpointers.h
+++ src/chrono/core/ChSmartpointers.h
@@ -233,17 +233,17 @@
 // Comparisons operators are required for using the shared pointer
 // class in an STL container

-template <typename T>
-bool operator==(const ChSmartPtr<T>& left, const ChSmartPtr<T>& right) {
+template <typename T, typename R>
+bool operator==(const ChSmartPtr<T>& left, const ChSmartPtr<R>& right) {
     if (left.get_ptr() == right.get_ptr())
         return true;
-    return *left == *right;
-}
-template <typename T>
-bool operator<(const ChSmartPtr<T>& left, const ChSmartPtr<T>& right) {
-    if (left.get_ptr() == right.get_ptr())
-        return false;
-    return *left < *right;
+    return false;
+}
+template <typename T, typename R>
+bool operator<(const ChSmartPtr<T>& left, const ChSmartPtr<R>& right) {
+    if (left.get_ptr() < right.get_ptr())
+        return true;
+    return false;
 }

 // Trick to avoid problems as in  http://www.artima.com/cppsource/safebool2.html
@@ -453,17 +453,17 @@
 // Comparisons operators are required for using the shared pointer
 // class in an STL container

-template <typename T>
-bool operator==(const ChSharedPtr<T>& left, const ChSharedPtr<T>& right) {
+template <typename T,typename R>
+bool operator==(const ChSharedPtr<T>& left, const ChSharedPtr<R>& right) {
     if (left.get_ptr() == right.get_ptr())
         return true;
-    return *left == *right;
-}
-template <typename T>
-bool operator<(const ChSharedPtr<T>& left, const ChSharedPtr<T>& right) {
-    if (left.get_ptr() == right.get_ptr())
-        return false;
-    return *left < *right;
+    return false;
+}
+template <typename T,typename R>
+bool operator<(const ChSharedPtr<T>& left, const ChSharedPtr<R>& right) {
+    if (left.get_ptr() < right.get_ptr())
+        return true;
+    return false;
 }

 // Trick to avoid problems as in  http://www.artima.com/cppsource/safebool2.html


parameters struct created

parameters struct created

--- src/communication/communication.c
+++ src/communication/communication.c
@@ -11,8 +11,13 @@
 #define IP "127.0.0.1"
 #define REDIS_ECONNECT -1

+struct priv_data
+{
+	void (*f)(int err, char *data);
+	int port;
+}
+
 redisAsyncContext *c;
-

 int initCommunication(int redis_port)
 {
@@ -28,38 +33,40 @@
 	return 0;
 }

-int openConnection (int communication_port, void (*f)(int err, char *data))
-{
-
-}
-
 void onMessage(redisAsyncContext *c, void *reply, void *privdata) {
     int j;
+    char *data;
+    char *token;
+    char *port_temp;
+    int port;
     redisReply *r = reply;
     if (reply == NULL) return;

     if (r->type == REDIS_REPLY_ARRAY) {
         for (j = 0; j < r->elements; j++) {
-            printf("%u) %s\n", j, r->element[j]->str);
+            data = r->element[j]->str);
+			if(strchr(data, ":"))
+			{
+				token = strtok(data, ":");
+				strcpy(port_temp, token);
+				int port = atoi(port_temp);
+				token = strtok(NULL, ":");
+				if(port == privdatap->port)
+			}
         }
     }
 }

-void *m()
+int openConnection (int communication_port, void (*f)(int err, char *data))
 {
-
+	struct priv_data *pd = malloc(sizeof(struct priv_data));
+	pd->f = f;
+	pd->port = communication_port;
 	struct event_base *base = event_base_new();
 	initCommunication(6379);
 	redisLibeventAttach(c, base);
-    redisAsyncCommand(c, onMessage, NULL, "SUBSCRIBE a");
-    event_base_dispatch(base);
-}
-
-int main()
-{
-	pthread_t a;
-	pthread_create(&a, NULL, &m, NULL);
-	printf("ana");
+    redisAsyncCommand(c, onMessage, pd, "SUBSCRIBE communication");
+    event_base_dispatch(base);
 }


Add dummy "syscall()" routine for AIX so we can at least test compiling and linking.

--- src/condor_ckpt/condor_syscalls.c
+++ src/condor_ckpt/condor_syscalls.c
@@ -48,3 +48,10 @@
 	abort();
 	return -1;
 }
+
+#if defined(AIX32)	/* Just to test linking */
+int syscall( int num, ... )
+{
+	return 0;
+}
+#endif


disk_analyzer: error printout fix

disk_analyzer: error printout fix

--- src/disk_analyzer/disk_analyzer.c
+++ src/disk_analyzer/disk_analyzer.c
@@ -55,7 +55,7 @@
     if (disk == NULL)
     {
         fprintf_light_red(stderr, "Error opening raw disk file '%s'. "
-                                  "Does it exist?\n", args[2]);
+                                  "Does it exist?\n", args[1]);
         return EXIT_FAILURE;
     }


Don't #include errno.h on Windows. VC10 or later intentionally changed the values of error numbers like EINTR, EWOULDBLOCK.

--- socket.h
+++ socket.h
@@ -17,9 +17,9 @@
 #include <gssapi/gssapi.h>
 #endif
 #endif
+
+#ifndef WIN32
 #include <errno.h>
-
-#ifndef WIN32
 #define	WSAAPI
 #ifdef	HAVE_POLL
 #include <poll.h>
@@ -96,6 +96,9 @@
 #define SOCKETFD SOCKET
 #define SOCK_ERRNO		(WSAGetLastError())
 #define SOCK_ERRNO_SET(e)	WSASetLastError(e)
+#ifndef	EINTR
+#define	EINTR	WSAEINTR
+#endif /* EINTR */
 #ifndef	EWOULDBLOCK
 #define	EWOULDBLOCK	WSAEWOULDBLOCK
 #endif /* EWOULDBLOCK */


Add option for specifying whitelisted words file. These words will not be matched for spell checks.

--- spell2.c
+++ spell2.c
@@ -46,13 +46,13 @@
 }

 static void
-do_bigram(FILE *f)
+do_bigram(FILE *inputf, const char *whitelist_filepath)
 {

 	char *word = NULL;
 	size_t wordsize = 0;
 	ssize_t bytesread;
-	spell_t *spellt = spell_init("dict/bigram.txt");
+	spell_t *spellt = spell_init("dict/bigram.txt", whitelist_filepath);
 	char *line = NULL;
 	size_t linesize = 0;
 	ssize_t bytes_read;
@@ -66,7 +66,7 @@
 	char *correction = NULL;
 	size_t i;

-	while ((bytes_read = getline(&line, &linesize, f)) != -1) {
+	while ((bytes_read = getline(&line, &linesize, inputf)) != -1) {
 		line[bytes_read - 1] = 0;
 		char *templine = line;
 		while (*templine) {
@@ -104,6 +104,11 @@

 			if (is_known_word(word))
 				continue;
+
+			if (is_whitelisted_word(spellt, word)) {
+				sentence_end = 1;
+				continue;
+			}

 			if (correction != NULL) {
 				free(correction);
@@ -150,13 +155,13 @@

 static void
-do_unigram(FILE *f)
+do_unigram(FILE *f, const char *whitelist_filepath)
 {

 	char *word = NULL;
 	size_t wordsize = 0;
 	ssize_t bytesread;
-	spell_t *spell = spell_init("dict/unigram.txt");
+	spell_t *spell = spell_init("dict/unigram.txt", whitelist_filepath);
 	char *line = NULL;
 	size_t linesize = 0;
 	ssize_t bytes_read;
@@ -188,6 +193,9 @@
 			if (spell_is_known_word(spell, word, 1))
 				continue;

+			if (is_whitelisted_word(spell, word))
+				continue;
+
 			char **corrections = spell_get_suggestions(spell, word, 1);
 			size_t i = 0;
 			while(corrections && corrections[i] != NULL) {
@@ -204,9 +212,10 @@
 {
 	long ngram = 1;
 	FILE *input = stdin;
+	char *whitelist_filepath = NULL;
 	int ch;

-	while ((ch = getopt(argc, argv, "f:n:")) != -1) {
+	while ((ch = getopt(argc, argv, "f:n:w:")) != -1) {
 		switch (ch) {
 		case 'f':
 			input = fopen(optarg, "r");
@@ -216,14 +225,17 @@
 		case 'n':
 			ngram = strtol(optarg, NULL, 10);
 			break;
+		case 'w':
+			whitelist_filepath = optarg;
+			break;
 		default:
 			break;
 		}
 	}

 	if (ngram == 1)
-		do_unigram(input);
+		do_unigram(input, whitelist_filepath);
 	if (ngram == 2)
-		do_bigram(input);
+		do_bigram(input, whitelist_filepath);
 	return 0;
 }


New tests for UA_Guid

New tests for UA_Guid

--- tests/check_builtin.c
+++ tests/check_builtin.c
@@ -1549,7 +1549,39 @@
 	UA_ApplicationDescription_deleteMembers(&copiedValue);
 }
 END_TEST
-
+START_TEST(UA_Guid_copyShallWorkOnInputExample) {
+	//given
+	const UA_Guid src = {3, 45, 1222, {8, 7, 6, 5, 4, 3, 2, 1}};
+
+	UA_Guid dst;
+	UA_Int32 ret;
+
+	//when
+	ret = UA_Guid_copy(&src, &dst);
+
+	//then
+	ck_assert_int_eq(ret, UA_SUCCESS);
+	ck_assert_int_eq(src.data1, dst.data1);
+	ck_assert_int_eq(src.data3, dst.data3);
+	ck_assert_int_eq(src.data4[4], dst.data4[4]);
+	//finally
+}
+END_TEST
+START_TEST(UA_Guid_copyWithNullArgumentShallReturn) {
+	//given
+	UA_Guid *src = UA_NULL;
+	UA_Guid *dst = UA_NULL;
+	UA_Int32 ret;
+
+	//when
+	ret = UA_Guid_copy(src, dst);
+
+	//then
+	ck_assert_int_eq(ret, UA_ERROR);
+
+	//finally
+}
+END_TEST
 START_TEST(UA_Variant_copyShallWorkOnSingleValueExample) {
 	//given
 	UA_String testString = (UA_String){5, (UA_Byte*)"OPCUA"};
@@ -1804,6 +1836,9 @@

 	tcase_add_test(tc_copy, UA_DiagnosticInfo_copyShallWorkOnExample);
 	tcase_add_test(tc_copy, UA_ApplicationDescription_copyShallWorkOnExample);
+
+	tcase_add_test(tc_copy, UA_Guid_copyWithNullArgumentShallReturn);
+	tcase_add_test(tc_copy, UA_Guid_copyShallWorkOnInputExample);
 	suite_add_tcase(s, tc_copy);
 	return s;
 }


add z, switch

add z, switch

--- Arduino/libraries/Printer/Printer.h
+++ Arduino/libraries/Printer/Printer.h
@@ -17,6 +17,10 @@
     void    moveSouth();
     void    moveEast();
     void    moveWest();
+    void    on();
+    void    off();
+    void    moveUp();
+    void    moveDown();
 private:
     Motor   m_x;
     Motor   m_y1;


ArmPkg: Expand AArch64 address width to 48 bits

The VA address space has a maximum address width of 48 bits in
AArch64 state; 48 bits address width limit will provide better
compatibility than 40 bits for future CPU.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
Reviewed-by: Olivier Martin <Olivier.Martin@arm.com>

git-svn-id: 3158a46dfd52e07d1fda3e32e1ab2e353a00b20f@17526 6f19259b-4bc3-4df7-8a09-765794883524

--- ArmPkg/Include/Chipset/AArch64Mmu.h
+++ ArmPkg/Include/Chipset/AArch64Mmu.h
@@ -51,8 +51,8 @@
 #define TT_ALIGNMENT_BLOCK_ENTRY                BIT12
 #define TT_ALIGNMENT_DESCRIPTION_TABLE          BIT12

-#define TT_ADDRESS_MASK_BLOCK_ENTRY             (0xFFFFFFFULL << 12)
-#define TT_ADDRESS_MASK_DESCRIPTION_TABLE       (0xFFFFFFFULL << 12)
+#define TT_ADDRESS_MASK_BLOCK_ENTRY             (0xFFFFFFFFFULL << 12)
+#define TT_ADDRESS_MASK_DESCRIPTION_TABLE       (0xFFFFFFFFFULL << 12)

 #define TT_TYPE_MASK                            0x3
 #define TT_TYPE_TABLE_ENTRY                     0x3


Added ut2k4 colored name parsing

Added ut2k4 colored name parsing

git-svn-id: 799001c4292c71bc513a6d33c97ab5ebe661e4c7@45 bac25679-d237-0410-bec6-f8029acc7ebe


free time event when delete eventloop

free time event when delete eventloop

--- src/ae.c
+++ src/ae.c
@@ -135,6 +135,13 @@
     aeApiFree(eventLoop);
     zfree(eventLoop->events);
     zfree(eventLoop->fired);
+    /* Free time event. */
+    aeTimeEvent *next_te, *te = eventLoop->timeEventHead;
+    while (te) {
+        next_te = te->next;
+        zfree(te);
+        te = next_te;
+    }
     zfree(eventLoop);
 }


Fix AF decode leak

Fix AF decode leak

--- src/af.c
+++ src/af.c
@@ -59,7 +59,7 @@
 void sd_af_delete(sd_af_file *af) {
     for(int i = 0; i < 70; i++) {
         if(af->moves[i]) {
-            free(af->moves[i]);
+            sd_move_delete(af->moves[i]);
         }
     }
     free(af);


bk.c    	fixed path parsing bug. Thanks to Bill Moore

bk: 38d7b9e21dzyXN-WMIzr0xShihonpw

--- src/bk.c
+++ src/bk.c
@@ -583,9 +583,9 @@
 		strcat(buf, av[0]);
 		goto gotit;
 	}
-
-	for (t = s = p; t = strchr(s, ':'); s = t + 1) {
-		*t = 0;
+
+	t = strdup(p);
+	for (s = strtok(t, ":"); s != NULL; s = strtok(NULL, ":")) {
 		sprintf(buf, "%s/%s", s, av[0]);
 		if (executable(buf)) {
 		verbose((stderr, "USING PATH %s\n", buf));
@@ -598,11 +598,10 @@
 			} else {
 				add2path = 0;
 			}
-			*t = ':';
+			free(t);
 			goto gotit;
-
-		}
-		*t = ':';
-	}
+		}
+	}
+	free(t);
 	return;
 }


cc.c: Perform the throttle check per uid rather than per IP

I forgot there was a reliable way to differentiate between users in c-c
connection structures.

--- src/cc.c
+++ src/cc.c
@@ -171,8 +171,8 @@
 #define THROTTLE_BURST 10

 struct throttle_get {
-  char ip[40];  // no port
   char tth[24];
+  guint64 uid;
   guint64 offset;
   time_t throttle;
 };
@@ -183,14 +183,14 @@
 static guint throttle_hash(gconstpointer key) {
   const struct throttle_get *t = key;
   guint *tth = (guint *)t->tth;
-  return *tth + g_str_hash(t->ip) + (gint)t->offset;
+  return *tth + (gint)t->offset + (gint)t->uid;
 }

 static gboolean throttle_equal(gconstpointer a, gconstpointer b) {
   const struct throttle_get *x = a;
   const struct throttle_get *y = b;
-  return strcmp(x->ip, y->ip) == 0 && memcmp(x->tth, y->tth, 24) == 0 && x->offset == y->offset;
+  return x->uid == y->uid && memcmp(x->tth, y->tth, 24) == 0 && x->offset == y->offset;
 }

@@ -202,10 +202,8 @@
 static gboolean throttle_check(struct cc *cc, char *tth, guint64 offset) {
   // construct a key
   struct throttle_get key;
-  strncpy(key.ip, net_remoteaddr(cc->net), 40);
-  if(strchr(key.ip, ':'))
-    *(strchr(key.ip, ':')) = 0;
   memcpy(key.tth, tth, 24);
+  key.uid = cc->uid;
   key.offset = offset;
   time(&key.throttle);


test-contacts: add fd.o#27686 ref to its test

--- tests/dbus/contacts.c
+++ tests/dbus/contacts.c
@@ -1988,7 +1988,7 @@
   guint i;
   TpContactFeature features[] = { TP_CONTACT_FEATURE_CAPABILITIES };

-  g_message (G_STRFUNC);
+  g_test_bug ("27686");

   for (i = 0; i < 3; i++)
     handles[i] = tp_handle_ensure (service_repo, ids[i], NULL, NULL);


Make dbid range check for SWAPDB command consistent with SELECT, MOVE, and COPY. (#8555)

DB ID used to be parsed as a long for SWAPDB command, now
make it into an int to be consistent with other commands that parses
the DB ID argument like SELECT, MOVE, COPY. See #8085

The implication is that the error message when the provided db index
is greater than 4M changes slightly.

--- src/db.c
+++ src/db.c
@@ -1315,7 +1315,7 @@
  *
  * Returns C_ERR if at least one of the DB ids are out of range, otherwise
  * C_OK is returned. */
-int dbSwapDatabases(long id1, long id2) {
+int dbSwapDatabases(int id1, int id2) {
     if (id1 < 0 || id1 >= server.dbnum ||
         id2 < 0 || id2 >= server.dbnum) return C_ERR;
     if (id1 == id2) return C_OK;
@@ -1356,7 +1356,7 @@

 /* SWAPDB db1 db2 */
 void swapdbCommand(client *c) {
-    long id1, id2;
+    int id1, id2;

     /* Not allowed in cluster mode: we have just DB 0 there. */
     if (server.cluster_enabled) {
@@ -1365,11 +1365,11 @@
     }

     /* Get the two DBs indexes. */
-    if (getLongFromObjectOrReply(c, c->argv[1], &id1,
+    if (getIntFromObjectOrReply(c, c->argv[1], &id1,
         "invalid first DB index") != C_OK)
         return;

-    if (getLongFromObjectOrReply(c, c->argv[2], &id2,
+    if (getIntFromObjectOrReply(c, c->argv[2], &id2,
         "invalid second DB index") != C_OK)
         return;


fd.o #19688: add a regression test

fd.o #19688: add a regression test

--- tests/dbus/contacts.c
+++ tests/dbus/contacts.c
@@ -776,6 +776,31 @@
   guint i;
   GError *e /* no initialization needed */;

+  g_message ("%s: all bad (fd.o #19688)", G_STRFUNC);
+
+  tp_connection_get_contacts_by_id (client_conn,
+      1, ids + 2,
+      0, NULL,
+      by_id_cb,
+      &result, finish, NULL);
+
+  g_main_loop_run (result.loop);
+
+  MYASSERT (result.contacts->len == 0, ": %u", result.contacts->len);
+  MYASSERT (g_hash_table_size (result.bad_ids) == 1, ": %u",
+      g_hash_table_size (result.bad_ids));
+  MYASSERT_NO_ERROR (result.error);
+
+  e = g_hash_table_lookup (result.bad_ids, "Not valid");
+  MYASSERT (e != NULL, "");
+
+  g_ptr_array_free (result.contacts, TRUE);
+  result.contacts = NULL;
+  g_strfreev (result.good_ids);
+  result.good_ids = NULL;
+  g_hash_table_destroy (result.bad_ids);
+  result.bad_ids = NULL;
+
   g_message ("%s: all good", G_STRFUNC);

   tp_connection_get_contacts_by_id (client_conn,


now that turned out to be a massive improvement... quite unexpectedly so...

--- src/gc.c
+++ src/gc.c
@@ -81,15 +81,18 @@

 void gc_tag (sexpr sx)
 {
-    unsigned int i, k;
-
-    for (i = 0, k = (gc_call_size / sizeof (sexpr)); i < k; i++)
-    {
-        if (gc_calls[i] == sx)
-        {
-            gc_calls[i] = (sexpr)0;
+    sexpr *c = gc_calls;
+    sexpr *k = gc_calls + gc_calls_i;
+
+    while (c < k)
+    {
+        if ((*c) == sx)
+        {
+            (*c) = (sexpr)0;
             sx_tag_sub (sx);
         }
+
+        c++;
     }
 }


gi: add gi.isinfo() for checking whether argument is of gi.info type.

--- src/gi.c
+++ src/gi.c
@@ -560,6 +560,20 @@
   return namespace_new (L, namespace);
 }

+/* Lua API: boolean = core.gi.isinfo(info) */
+static int
+gi_isinfo (lua_State *L)
+{
+  if (lua_getmetatable (L, 1))
+    {
+      luaL_getmetatable (L, LGI_GI_INFO);
+      lua_pushboolean (L, lua_rawequal (L, -1, -2));
+    }
+  else
+    lua_pushboolean (L, 0);
+  return 1;
+}
+
 static int
 gi_index (lua_State *L)
 {
@@ -593,6 +607,12 @@
   { NULL, NULL }
 };

+static const luaL_Reg gi_api_reg[] = {
+  { "require", gi_require },
+  { "isinfo", gi_isinfo },
+  { NULL, NULL }
+};
+
 void
 lgi_gi_init (lua_State *L)
 {
@@ -608,8 +628,7 @@

   /* Register global API. */
   lua_newtable (L);
-  lua_pushcfunction (L, gi_require);
-  lua_setfield (L, -2, "require");
+  luaL_register (L, NULL, gi_api_reg);
   lua_newtable (L);
   lua_pushcfunction (L, gi_index);
   lua_setfield (L, -2, "__index");


* Fixed list printing

* Fixed list printing

--- src/io.c
+++ src/io.c
@@ -435,12 +435,29 @@
     printf("<#closure>");
     break;

-  case SLY_TYPE_PAIR:
+  case SLY_TYPE_PAIR: {
+    sly_object_t cdr;
+    sly_gcobject_t *p = obj->value.gc;
+
     printf("(");
-    sly_io_write(&(((sly_pair_t*)obj->value.gc)->car));
-    printf(" . ");
-    sly_io_write(&(((sly_pair_t*)obj->value.gc)->cdr));
+    for(;;) {
+
+      sly_io_write(&(SLY_PAIR(p)->car));
+
+      cdr = SLY_PAIR(p)->cdr;
+      if(cdr.type == SLY_TYPE_NIL) {
+        break;
+      } else if(cdr.type != SLY_TYPE_PAIR) {
+        printf (" . ");
+        sly_io_write(&cdr);
+        break;
+      } else {
+        printf(" ");
+        p = cdr.value.gc;
+      }
+    }
     printf(")");
+  }
     break;

   case SLY_TYPE_CONTI:


fix #525: Display result

fix #525: Display result


don't print directory entries unless they have a filehandle

--- src/ls.c
+++ src/ls.c
@@ -133,11 +133,10 @@
     }

     while (input_fh) {
+
         current = parse_fh(input_fh);
+
         if (current) {
-            current->client_sock->sin_family = AF_INET;
-            current->client_sock->sin_port = htons(NFS_PORT);
-
             /* check if we can use the same client connection as the previous target */
             /* get the server address out of the client */
             if (client) {
@@ -148,41 +147,55 @@
             }

             if (client == NULL) {
+                current->client_sock->sin_family = AF_INET;
+                current->client_sock->sin_port = htons(NFS_PORT);
                 /* connect to server */
                 client = create_rpc_client(current->client_sock, &hints, NFS_PROGRAM, version, timeout, src_ip);
                 client->cl_auth = authunix_create_default();
             }

-            entry = do_readdirplus(client, current);
-            while (entry) {
-                /* first check for hidden files */
-                if (all == 0) {
-                    if (entry->name[0] == '.') {
-                        entry = entry->nextentry;
-                        continue;
+            if (client) {
+                entry = do_readdirplus(client, current);
+
+                while (entry) {
+                    /* first check for hidden files */
+                    if (all == 0) {
+                        if (entry->name[0] == '.') {
+                            entry = entry->nextentry;
+                            continue;
+                        }
                     }
-                }
-                printf("%s:%s", current->host, current->path);
-                /* if the path doesn't already end in /, print one now */
-                if (current->path[strlen(current->path) - 1] != '/')
-                    printf("/");
-                /* the filename */
-                printf("%s", entry->name);
-                /* if it's a directory print a trailing slash */
-                /* TODO this seems to be 0 sometimes */
-                if (entry->name_attributes.post_op_attr_u.attributes.type == NF3DIR)
-                    printf("/");
-                printf(":");
-
-                /* print the filehandle in hex */
-                for (i = 0; i < entry->name_handle.post_op_fh3_u.handle.data.data_len; i++) {
-                    printf("%02hhx", entry->name_handle.post_op_fh3_u.handle.data.data_val[i]);
-                }
-                printf("\n");
-
-                entry = entry->nextentry;
-            }
-        }
+                    /* if there is no filehandle (/dev, /proc, etc) don't print */
+                    /* none of the other utilities can do anything without a filehandle */
+                    /* TODO unless -a ? */
+                    if (entry->name_handle.post_op_fh3_u.handle.data.data_len) {
+                        printf("%s:%s", current->host, current->path);
+                        /* if the path doesn't already end in /, print one now */
+                        if (current->path[strlen(current->path) - 1] != '/')
+                            printf("/");
+                        /* the filename */
+                        printf("%s", entry->name);
+                        /* if it's a directory print a trailing slash */
+                        /* TODO this seems to be 0 sometimes */
+                        if (entry->name_attributes.post_op_attr_u.attributes.type == NF3DIR)
+                            printf("/");
+                        printf(":");
+
+                        /* print the filehandle in hex */
+                        for (i = 0; i < entry->name_handle.post_op_fh3_u.handle.data.data_len; i++) {
+                            printf("%02hhx", entry->name_handle.post_op_fh3_u.handle.data.data_val[i]);
+                        }
+                        printf("\n");
+                    }
+
+                    entry = entry->nextentry;
+                }
+            }
+        }
+
+        /* cleanup */
+        free(current->client_sock);
+        free(current);

         /* get the next filehandle*/
         if (optind == argc) {


Add ASSERT_ARGS() to each function.

Add ASSERT_ARGS() to each function.

git-svn-id: 2406d6b42e5961eceaf0ba26f58518ac94ed3785@34847 d31e2699-5ff4-0310-a27c-f18f2fbe73fe

--- src/oo.c
+++ src/oo.c
@@ -94,6 +94,7 @@
 Parrot_oo_extract_methods_from_namespace(PARROT_INTERP, ARGIN(PMC *self), ARGIN(PMC *ns))
 {
    PMC *methods, *vtable_overrides;
+   ASSERT_ARGS(Parrot_oo_extract_methods_from_namespace);

     /* Pull in methods from the namespace, if any. */
    if (PMC_IS_NULL(ns))
@@ -157,6 +158,7 @@
 {
     Parrot_Class_attributes * const _class     = PARROT_CLASS(classobj);
     PMC          * const _namespace = _class->_namespace;
+   ASSERT_ARGS(Parrot_oo_get_namespace);

     if (PMC_IS_NULL(_namespace))
         return PMCNULL;
@@ -182,6 +184,7 @@
 Parrot_oo_get_class(PARROT_INTERP, ARGIN(PMC *key))
 {
     PMC *classobj = PMCNULL;
+    ASSERT_ARGS(Parrot_oo_get_class);

     if (PObj_is_class_TEST(key))
         classobj = key;
@@ -249,6 +252,7 @@
     PMC * const ns     = Parrot_get_namespace_keyed_str(interp, hll_ns, name);
     PMC * const _class = PMC_IS_NULL(ns)
                        ? PMCNULL : VTABLE_get_class(interp, ns);
+    ASSERT_ARGS(Parrot_oo_get_class_str);

     /* Look up a low-level class and create a proxy */
     if (PMC_IS_NULL(_class)) {
@@ -286,6 +290,7 @@
     PMC * const namearg  = pmc_new(interp, enum_class_String);
     PMC        *namehash = pmc_new(interp, enum_class_Hash);
     PMC        *classobj;
+    ASSERT_ARGS(Parrot_oo_newclass_from_str);

     VTABLE_set_string_native(interp, namearg, name);
     VTABLE_set_pmc_keyed_str(interp, namehash, CONST_STRING(interp, "name"), namearg);
@@ -314,6 +319,7 @@
         ARGIN(PMC *classobj), ARGIN(STRING *name))
 {
     Parrot_Class_attributes *class_info;
+    ASSERT_ARGS(Parrot_oo_find_vtable_override_for_class);
     PARROT_ASSERT(PObj_is_class_TEST(classobj));

     class_info = PARROT_CLASS(classobj);
@@ -339,6 +345,7 @@
         ARGIN(PMC *classobj), ARGIN(STRING *name))
 {
     Parrot_Class_attributes * const _class = PARROT_CLASS(classobj);
+    ASSERT_ARGS(Parrot_oo_find_vtable_override);

     if (VTABLE_exists_keyed_str(interp, _class->parent_overrides, name))
         return VTABLE_get_pmc_keyed_str(interp, _class->parent_overrides, name);
@@ -386,6 +393,7 @@
     /* some of the first "slots" don't have names. skip 'em. */
     INTVAL low               = PARROT_VTABLE_LOW;
     INTVAL high              = NUM_VTABLE_FUNCTIONS + PARROT_VTABLE_LOW;
+    ASSERT_ARGS(Parrot_get_vtable_index);

     while (low < high) {
         const INTVAL       mid    = (low + high) / 2;
@@ -427,6 +435,7 @@
 const char*
 Parrot_MMD_method_name(SHIM_INTERP, INTVAL idx)
 {
+    ASSERT_ARGS(Parrot_MMD_method_name);
     PARROT_ASSERT(idx >= 0);

     if (idx >= MMD_USER_FIRST)
@@ -455,6 +464,7 @@
 {
     const INTVAL type = pmc_type(interp, class_name);
     PMC         *pmc;
+    ASSERT_ARGS(Parrot_class_lookup);

     if (type <= 0)
         return PMCNULL;
@@ -483,6 +493,7 @@
 {
     const INTVAL type = pmc_type_p(interp, class_name);
     PMC         *pmc;
+    ASSERT_ARGS(Parrot_class_lookup_p);

     if (type <= 0)
         return PMCNULL;
@@ -510,6 +521,7 @@
 fail_if_type_exists(PARROT_INTERP, ARGIN(PMC *name))
 {
     PMC * const value = (PMC *)VTABLE_get_pointer_keyed(interp, interp->class_hash, name);
+    ASSERT_ARGS(fail_if_type_exists);

     if (PMC_IS_NULL(value))
         return 0;
@@ -556,6 +568,7 @@
 {
     INTVAL type;
     const INTVAL typeid_exists = fail_if_type_exists(interp, name);
+    ASSERT_ARGS(Parrot_oo_register_type);

     PMC *classobj = VTABLE_get_class(interp, namespace);
     if (!PMC_IS_NULL(classobj)) {
@@ -604,6 +617,7 @@
 Parrot_remove_parent(PARROT_INTERP, ARGIN(PMC *removed_class),
         ARGIN(PMC *existing_class))
 {
+    ASSERT_ARGS(Parrot_remove_parent);
     UNUSED(interp);
     UNUSED(removed_class);
     UNUSED(existing_class);
@@ -632,6 +646,7 @@
 {
     Caches * const mc = interp->caches;
     UINTVAL type, entry;
+    ASSERT_ARGS(mark_object_cache);

     if (!mc)
         return;
@@ -665,6 +680,7 @@
 init_object_cache(PARROT_INTERP)
 {
     Caches * const mc = interp->caches = mem_allocate_zeroed_typed(Caches);
+    ASSERT_ARGS(init_object_cache);
     mc->idx = NULL;
 }

@@ -684,6 +700,7 @@
 {
     UINTVAL i;
     Caches * const mc = interp->caches;
+    ASSERT_ARGS(destroy_object_cache);

     /* mc->idx[type][bits] = e; */
     for (i = 0; i < mc->mc_size; i++) {
@@ -711,6 +728,7 @@
 {
     Caches * const mc = interp->caches;
     INTVAL i;
+    ASSERT_ARGS(invalidate_type_caches);

     if (!mc)
         return;
@@ -747,6 +765,7 @@
 invalidate_all_caches(PARROT_INTERP)
 {
     UINTVAL i;
+    ASSERT_ARGS(invalidate_all_caches);
     for (i = 1; i < (UINTVAL)interp->n_vtable_max; ++i)
         invalidate_type_caches(interp, i);
 }
@@ -768,6 +787,7 @@
 Parrot_invalidate_method_cache(PARROT_INTERP, ARGIN_NULLOK(STRING *_class))
 {
     INTVAL type;
+    ASSERT_ARGS(Parrot_invalidate_method_cache);

     /* during interp creation and NCI registration the class_hash
      * isn't yet up */
@@ -816,6 +836,7 @@
 Parrot_find_method_direct(PARROT_INTERP, ARGIN(PMC *_class), ARGIN(STRING *method_name))
 {
     PMC * const found = find_method_direct_1(interp, _class, method_name);
+    ASSERT_ARGS(Parrot_find_method_direct);

     if (!PMC_IS_NULL(found))
         return found;
@@ -854,6 +875,7 @@

     Caches           *mc;
     Meth_cache_entry *e, *old;
+    ASSERT_ARGS(Parrot_find_method_with_cache);

     PARROT_ASSERT(method_name != 0);

@@ -935,6 +957,7 @@
     STRING *class_name;
     const char *result;
     Interp *tracer;
+    ASSERT_ARGS(debug_trace_find_meth);

     if (!Interp_trace_TEST(interp, PARROT_TRACE_FIND_METH_FLAG))
         return;
@@ -984,6 +1007,7 @@

     PMC * const  mro = _class->vtable->mro;
     const INTVAL n   = VTABLE_elements(interp, mro);
+    ASSERT_ARGS(find_method_direct_1);

     for (i = 0; i < n; ++i) {
         PMC *method, *ns;
@@ -1027,6 +1051,7 @@
     const int list_count = VTABLE_elements(interp, merge_list);
     int       cand_count = 0;
     int       i;
+    ASSERT_ARGS(C3_merge);

     /* Try and find something appropriate to add to the MRO - basically, the
      * first list head that is not in the tail of all the other lists. */
@@ -1123,6 +1148,7 @@
     PMC * const merge_list = pmc_new(interp, enum_class_ResizablePMCArray);
     PMC *immediate_parents;
     int i, parent_count;
+    ASSERT_ARGS(Parrot_ComputeMRO_C3);

     /* Now get immediate parents list. */
     Parrot_PCCINVOKE(interp, _class, CONST_STRING(interp, "parents"),
@@ -1203,6 +1229,7 @@

     /* Check we have not already composed the role; if so, just ignore it. */
     int roles_count = VTABLE_elements(interp, roles_list);
+    ASSERT_ARGS(Parrot_ComposeRole);

     for (i = 0; i < roles_count; i++)
         if (VTABLE_get_pmc_keyed_int(interp, roles_list, i) == role)


Only stopped tasks may be added to the runqueue.

--- src/os.c
+++ src/os.c
@@ -307,7 +307,7 @@
 	task->priority = priority;
 	task->task_func = task_func;
 	task->task_params = task_params;
-	task->state = RUNNABLE;
+	task->state = STOPPED;

 	task->name = name;
 	task->stack_base = (int *)stack_base;
@@ -330,6 +330,12 @@
 void os_add_task(task_t *new_task)
 {
 	CM_ATOMIC_CONTEXT();
+
+	if (new_task->state != STOPPED) {
+		return;
+	}
+
+	new_task->state = RUNNABLE;

 	if (all_tasks.first == NULL) {
 		all_tasks.first = new_task;


sc: Simplify malloc with memory alignment.

--- src/sc.c
+++ src/sc.c
@@ -313,12 +313,10 @@
   void               *ret;
   int                *malloc_count = sc_malloc_count (package);

-#if defined(__bgq__)
-  size_t              alignment = 32;
-  posix_memalign (&ret, alignment, size);
+#if defined(SC_MEMALIGN_BYTES)
+  posix_memalign (&ret, SC_MEMALIGN_BYTES, size);
 #else
-  posix_memalign (&ret, SC_MEMALIGN_BYTES, size);
-  //ret = malloc (size);
+  ret = malloc (size);
 #endif
   if (size > 0) {
     SC_CHECK_ABORTF (ret != NULL, "Allocation (malloc size %lli)",


Fix display of song lists with more than 999 items

Increased buffer size.

--- src/ui.c
+++ src/ui.c
@@ -665,7 +665,7 @@
 size_t BarUiListSongs (const BarSettings_t *settings,
 		const PianoSong_t *song, const char *filter) {
 	size_t i = 0;
-	char digits[4];
+	char digits[8];

 	while (song != NULL) {
 		if (filter == NULL ||


pass format string as a string literal

pass format string as a string literal

--- src/ui.c
+++ src/ui.c
@@ -108,7 +108,7 @@
     gtk_message_dialog_set_markup(dialog, title);

     if(message)
-        gtk_message_dialog_format_secondary_text(dialog, message);
+        gtk_message_dialog_format_secondary_text(dialog, "%s", message);

     return GTK_DIALOG(dialog);
 }


Fix comparison between pointer and zero character constant

--- src/ui.c
+++ src/ui.c
@@ -124,7 +124,7 @@
 		if (sbpos < 0)
 			sbpos = CONSOLE_SCROLLBACK - 1;
 		while (sbpos != console_scrollback_pos && sby < viewport->y) {
-			if (console_scrollback[sbpos] == '\0')
+			if (console_scrollback[sbpos][0] == '\0')
 				break;
 			len = strlen(console_scrollback[sbpos]);
 			offset = (len > max_display) ? (len - max_display) : 0;


Changed header title from module to view under the find dialog.

--- src/ui.h
+++ src/ui.h
@@ -141,7 +141,7 @@
 #define OVERALL_BANDWIDTH "bandwidth"
 #define OVERALL_LOG       "log_path"

-#define FIND_HEAD    "Find pattern in all modules"
+#define FIND_HEAD    "Find pattern in all views"
 #define FIND_DESC    "Regex allowed - ^g to cancel - TAB switch case"

 #define MAX_CHOICES       366


fix a small bug in OP_ARGARY.

fix a small bug in OP_ARGARY.


debug printer supports OP_LREF

debug printer supports OP_LREF

--- src/vm.c
+++ src/vm.c
@@ -160,6 +160,9 @@
       break;
     case OP_GSET:
       printf("OP_GSET\t%p\n", irep->code[i].u.gvar);
+      break;
+    case OP_LREF:
+      printf("OP_LREF\t%d\n", irep->code[i].u.i);
       break;
     case OP_JMP:
       printf("OP_JMP\t%d\n", irep->code[i].u.i);


refactor the last change

refactor the last change

--- src/vm.c
+++ src/vm.c
@@ -775,11 +775,10 @@
       ci->fp = pic->sp - c.u.i;
       ci->env = NULL;
       if (pic_proc_func_p(pic_proc_ptr(x))) {
-        pic_value *sp;

         /* invoke! */
-        sp = pic->sp;
-        sp[0] = proc->u.func.f(pic);
+        v = proc->u.func.f(pic);
+        pic->sp[0] = v;
         pic->sp += pic->ci->retc;

         pic_gc_arena_restore(pic, ai);
@@ -1046,5 +1045,10 @@
   ci->ip = (pic_code *)&iseq - 1;
   ci->fp = pic->sp;
   ci->retc = pic_length(pic, args);
-  return pic_obj_value(proc);
-}
+
+  if (ci->retc == 0) {
+    return pic_none_value();
+  } else {
+    return pic_car(pic, args);
+  }
+}


fix several constant visibility issues (#131)

Thank you.

--- src/vm.c
+++ src/vm.c
@@ -619,6 +619,35 @@
   mrbc_class *cls = NULL;
   mrbc_value *v;

+#define _GET_CLASS_CONST \
+    v = mrbc_get_class_const(cls, sym_id); \
+    if( v != NULL ) goto DONE;
+
+  if( vm->callinfo_tail ) {
+    // class environment
+    if( vm->target_class != vm->callinfo_tail->target_class ) {
+      // case 1: Normal class constant
+      cls = vm->target_class;
+      _GET_CLASS_CONST;
+
+      // case 2: Nested class constant
+      if( vm->callinfo_tail->target_class != mrbc_class_object ) {
+        cls = vm->callinfo_tail->target_class;
+        _GET_CLASS_CONST;
+        mrbc_callinfo *tmp_ci = vm->callinfo_tail;
+        while( tmp_ci->prev ) {
+          cls = tmp_ci->prev->target_class;
+          _GET_CLASS_CONST;
+          tmp_ci = tmp_ci->prev;
+        }
+      }
+
+      // case 3: Subclass constant
+      // in order to be same with mruby's behavior (rather than CRuby)
+      // We place it after `mrbc_get_const`
+    }
+  }
+
   if( vm->callinfo_tail ) cls = vm->callinfo_tail->own_class;
   while( cls != NULL ) {
     v = mrbc_get_class_const(cls, sym_id);
@@ -627,7 +656,24 @@
   }

   v = mrbc_get_const(sym_id);
-  if( v == NULL ) {		// raise?
+  if( v != NULL ) goto DONE;
+
+  // case 3: Subclass constant
+  if( vm->callinfo_tail ) {
+    // class environment
+    if( vm->target_class != vm->callinfo_tail->target_class ) {
+      // To find super class
+      cls = vm->target_class->super;
+      while( cls != NULL ) {
+        _GET_CLASS_CONST;
+        cls = cls->super;
+      }
+    }
+  }
+
+#undef _GET_CLASS_CONST
+
+  if( v == NULL ) { // raise?
     console_printf( "NameError: uninitialized constant %s\n", sym_name );
     return 0;
   }


emit int result in int-int division if possible

--- src/vm.c
+++ src/vm.c
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <limits.h>
+#include <math.h>

 #include "picrin.h"
 #include "picrin/pair.h"
@@ -552,14 +553,14 @@
       NEXT;
     }

-#define DEFINE_ARITH_OP(opcode, op)				\
+#define DEFINE_ARITH_OP(opcode, op, guard)			\
     CASE(opcode) {						\
       pic_value a, b;						\
       b = POP();						\
       a = POP();						\
       if (pic_int_p(a) && pic_int_p(b)) {			\
 	double f = (double)pic_int(a) op (double)pic_int(b);	\
-	if (INT_MIN <= f && f <= INT_MAX) {			\
+	if (INT_MIN <= f && f <= INT_MAX && (guard)) {		\
 	  PUSH(pic_int_value((int)f));				\
 	}							\
 	else {							\
@@ -582,33 +583,10 @@
       NEXT;							\
     }

-    DEFINE_ARITH_OP(OP_ADD, +);
-    DEFINE_ARITH_OP(OP_SUB, -);
-    DEFINE_ARITH_OP(OP_MUL, *);
-
-    /* special care for (int / int) division */
-    CASE(OP_DIV) {
-      pic_value a, b;
-      b = POP();
-      a = POP();
-      if (pic_int_p(a) && pic_int_p(b)) {
-	PUSH(pic_float_value((double)pic_int(a) / pic_int(b)));
-      }
-      else if (pic_float_p(a) && pic_float_p(b)) {
-	PUSH(pic_float_value(pic_float(a) / pic_float(b)));
-      }
-      else if (pic_int_p(a) && pic_float_p(b)) {
-	PUSH(pic_float_value(pic_int(a) / pic_float(b)));
-      }
-      else if (pic_float_p(a) && pic_int_p(b)) {
-	PUSH(pic_float_value(pic_float(a) / pic_int(b)));
-      }
-      else {
-	pic->errmsg = "/ got non-number operands";
-	goto L_RAISE;
-      }
-      NEXT;
-    }
+    DEFINE_ARITH_OP(OP_ADD, +, true);
+    DEFINE_ARITH_OP(OP_SUB, -, true);
+    DEFINE_ARITH_OP(OP_MUL, *, true);
+    DEFINE_ARITH_OP(OP_DIV, /, f == round(f));

     CASE(OP_MINUS) {
       pic_value n;


Add src/A2.c

Add src/A2.c

error: pathspec 'src/A2.c' did not match any file(s) known to git

--- src/A2.c
+++ src/A2.c
@@ -0,0 +1,42 @@
+/*  Author: 		Dan Wilder
+ *
+ *  School:		University of Missouri - St. Louis
+ *  Semester:		Fall 2015
+ *  Class: 		CS 3130 - Design and Analysis of Algorithms
+ *  Instructor:		Galina N. Piatnitskaia
+ *
+ *  Description:
+ *    [15 points] Write a program to compare efficiency of four sorting
+ *  algorithms from part (1). To do that, you will have to use some function
+ *  to measure the time of execution of a code fragment. Apply each sorting
+ *  method to 10 different arrays of random integers of each of the following
+ *  sizes: 500, 1000, 2500 and 5000. The output of the program is average
+ *  execution times for all sizes.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include "../include/sort_algorithms.h"
+#include "../include/array_utilities.h"
+
+#define MAX_VAL   9999
+#define NUM_SIZES 4
+const int SIZES[NUM_SIZES] = {500, 1000, 2500, 5000};
+
+int main() {
+
+  // Array holding arrays of different sizes
+  int *arr[NUM_SIZES];
+  int i;
+
+  // Allocate each array for each size
+  for (i = 0; i < NUM_SIZES; ++i)
+    arr[i] = (int *) malloc(SIZES[i] *sizeof(int));
+
+  // Free memory
+  for (i = 0; i < NUM_SIZES; ++i)
+    free(arr[i]);
+
+  return 0;
+}


Make emptyDb() change introduced in #4852 simpler to read.

--- src/db.c
+++ src/db.c
@@ -337,10 +337,15 @@
         return -1;
     }

-    int j = dbnum == -1 ? 0 : dbnum;
-    int dbmax = dbnum == -1 ? server.dbnum : dbnum+1;
-
-    for (; j < dbmax; j++) {
+    int startdb, enddb;
+    if (dbnum == -1) {
+        startdb = 0;
+        enddb = server.dbnum-1;
+    } else {
+        startdb = enddb = dbnum;
+    }
+
+    for (int j = startdb; j <= enddb; j++) {
         if (dbnum != -1 && dbnum != j) continue;
         removed += dictSize(server.db[j].dict);
         if (async) {


for (p)expireat use absolute time, without double recomputation

--- src/db.c
+++ src/db.c
@@ -527,7 +527,7 @@
         return;

     if (unit == UNIT_SECONDS) milliseconds *= 1000;
-    milliseconds -= offset;
+    milliseconds += offset;

     de = dictFind(c->db->dict,key->ptr);
     if (de == NULL) {
@@ -554,8 +554,7 @@
         addReply(c, shared.cone);
         return;
     } else {
-        long long when = mstime()+milliseconds;
-        setExpire(c->db,key,when);
+        setExpire(c->db,key,milliseconds);
         addReply(c,shared.cone);
         signalModifiedKey(c->db,key);
         server.dirty++;
@@ -564,19 +563,19 @@
 }

 void expireCommand(redisClient *c) {
+    expireGenericCommand(c,mstime(),UNIT_SECONDS);
+}
+
+void expireatCommand(redisClient *c) {
     expireGenericCommand(c,0,UNIT_SECONDS);
 }

-void expireatCommand(redisClient *c) {
-    expireGenericCommand(c,mstime(),UNIT_SECONDS);
-}
-
 void pexpireCommand(redisClient *c) {
+    expireGenericCommand(c,mstime(),UNIT_MILLISECONDS);
+}
+
+void pexpireatCommand(redisClient *c) {
     expireGenericCommand(c,0,UNIT_MILLISECONDS);
-}
-
-void pexpireatCommand(redisClient *c) {
-    expireGenericCommand(c,mstime(),UNIT_MILLISECONDS);
 }

 void ttlGenericCommand(redisClient *c, int output_ms) {


if we read a expired key, misses++

if we read a expired key, misses++

--- src/db.c
+++ src/db.c
@@ -102,7 +102,10 @@
         /* Key expired. If we are in the context of a master, expireIfNeeded()
          * returns 0 only when the key does not exist at all, so it's safe
          * to return NULL ASAP. */
-        if (server.masterhost == NULL) return NULL;
+        if (server.masterhost == NULL) {
+            server.stat_keyspace_misses++;
+            return NULL;
+        }

         /* However if we are in the context of a slave, expireIfNeeded() will
          * not really try to expire the key, it only returns information
@@ -121,6 +124,7 @@
             server.current_client->cmd &&
             server.current_client->cmd->flags & CMD_READONLY)
         {
+            server.stat_keyspace_misses++;
             return NULL;
         }
     }


reverses comparison for clarity

reverses comparison for clarity

--- src/df.c
+++ src/df.c
@@ -398,10 +398,10 @@
                 break;
             /* display bytes */
             case 'b':
-                if (prefix != NONE) {
+                if (prefix == NONE) {
+                    prefix = BYTE;
+                } else {
                     fatal("Can't specify multiple units!\n");
-                } else {
-                    prefix = BYTE;
                 }
                 break;
             /* loop count */
@@ -419,26 +419,26 @@
                 break;
             /* display gigabytes */
             case 'g':
-                if (prefix != NONE) {
+                if (prefix == NONE) {
+                    prefix = GIGA;
+                } else {
                     fatal("Can't specify multiple units!\n");
-                } else {
-                    prefix = GIGA;
                 }
                 break;
             /* Graphite output */
             case 'G':
-                if (prefix != NONE) {
+                if (prefix == NONE) {
+                    cfg.format = graphite;
+                } else {
                     fatal("Can't specify units and -G!\n");
-                } else {
-                    cfg.format = graphite;
                 }
                 break;
             /* display human readable (default, set below) */
             case 'h':
-                if (prefix != NONE) {
+                if (prefix == NONE) {
+                    prefix = HUMAN;
+                } else {
                     fatal("Can't specify multiple units!\n");
-                } else {
-                    prefix = HUMAN;
                 }
                 break;
             /* polling frequency */
@@ -452,10 +452,10 @@
                 break;
             /* display kilobytes */
             case 'k':
-                if (prefix != NONE) {
+                if (prefix == NONE) {
+                    prefix = KILO;
+                } else {
                     fatal("Can't specify multiple units!\n");
-                } else {
-                    prefix = KILO;
                 }
                 break;
             /* loop forever */
@@ -470,10 +470,10 @@
                 break;
             /* display megabytes */
             case 'm':
-                if (prefix != NONE) {
+                if (prefix == NONE) {
+                    prefix = MEGA;
+                } else {
                     fatal("Can't specify multiple units!\n");
-                } else {
-                    prefix = MEGA;
                 }
                 break;
             /* portmapper */
@@ -496,10 +496,10 @@
                 break;
             /* display terabytes */
             case 't':
-                if (prefix != NONE) {
+                if (prefix == NONE) {
+                    prefix = TERA;
+                } else {
                     fatal("Can't specify multiple units!\n");
-                } else {
-                    prefix = TERA;
                 }
                 break;
             /* use TCP */


dh: Use ssh_string_new() in make_bignum_string().

--- src/dh.c
+++ src/dh.c
@@ -346,8 +346,11 @@
   unsigned int len = bignum_num_bytes(num);
   unsigned int bits = bignum_num_bits(num);

-  /* Remember if the fist bit is set, it is considered as a
-   * negative number. So 0's must be appended */
+  if (len == 0) {
+      return NULL;
+  }
+
+  /* If the first bit is set we have a negative number */
   if (!(bits % 8) && bignum_is_bit_set(num, bits - 1)) {
     pad++;
   }
@@ -355,12 +358,13 @@
 #ifdef DEBUG_CRYPTO
   fprintf(stderr, "%d bits, %d bytes, %d padding\n", bits, len, pad);
 #endif /* DEBUG_CRYPTO */
-/* TODO: fix that crap !! */
-  ptr = malloc(sizeof(struct ssh_string_struct) + len + pad);
+
+  ptr = ssh_string_new(len + pad);
   if (ptr == NULL) {
     return NULL;
   }
-  ptr->size = htonl(len + pad);
+
+  /* We have a negative number so we need a leading zero */
   if (pad) {
     ptr->data[0] = 0;
   }


dl.c: Make sure to save user-related errors to dl.dat


max listeners

max listeners

--- src/ee.c
+++ src/ee.c
@@ -5,6 +5,10 @@
 #include <log.h>

 #define EE_NEW_LISTENER "new_listener"
+
+#ifndef EE_MAX_LISTENERS
+#define EE_MAX_LISTENERS 10
+#endif

 typedef void (*ee_cb)(void*);
 typedef void (*ee_new_listener_cb)(const char*);
@@ -85,6 +89,7 @@
   ee__event_t *event;
   list_node_t *handler_node;
   list_node_t *event_node;
+  int len;

   event = ee__find(self, name);
   if (event == NULL) {
@@ -101,6 +106,12 @@
     ee_emit(self, EE_NEW_LISTENER, &listener);
   }

+  len = event->handlers->len;
+  if (EE_MAX_LISTENERS && len > EE_MAX_LISTENERS) {
+    fprintf(stderr, "Event '%s' has %d listeners which exceeds %d max listeners!\n", name, len, EE_MAX_LISTENERS);
+    fprintf(stderr, "Increase this max default by setting EE_MAX_LISTENERS - set to zero for unlimited.\n");
+  }
+
   log_debug("Added event for '%s'. It has now %d handlers", event->name, event->handlers->len);
 }


fixup

fixup

--- src/fs.c
+++ src/fs.c
@@ -325,7 +325,6 @@
         }
       } else
         lua_pushnil(L);
-      uv_fs_req_cleanup(req);

       return 1;
     }
@@ -340,19 +339,6 @@
       return 2;
   }

-}
-
-static void luv_fs_cleanup_req(lua_State* L, uv_fs_t* req, luv_req_t* data) {
-#if LUV_UV_VERSION_GEQ(1, 28, 0)
-  if (req->fs_type == UV_FS_READDIR) {
-    luv_cleanup_req(L, data);
-  } else
-#endif
-  if(req->fs_type != UV_FS_SCANDIR) {
-    luv_cleanup_req(L, data);
-    req->data = NULL;
-    uv_fs_req_cleanup(req);
-  }
 }

 static void luv_fs_cb(uv_fs_t* req) {
@@ -371,8 +357,18 @@
     lua_insert(L, -nargs - 1);
     nargs++;
   }
-  luv_fulfill_req(L, data, nargs);
-  luv_fs_cleanup_req(L, req, data);
+  if (req->fs_type == UV_FS_SCANDIR) {
+    luv_fulfill_req(L, data, nargs);
+  }
+  else {
+    // cleanup the uv_fs_t before the callback is called to avoid
+    // a race condition when fs_close is called from within
+    // a fs_readdir callback, see https://github.com/luvit/luv/issues/384
+    uv_fs_req_cleanup(req);
+    req->data = NULL;
+    luv_fulfill_req(L, data, nargs);
+    luv_cleanup_req(L, data);
+  }
 }

 #define FS_CALL(func, req, ...) {                         \
@@ -401,7 +397,11 @@
   }                                                       \
   if (sync) {                                             \
     int nargs = push_fs_result(L, req);                   \
-    luv_fs_cleanup_req(L, req, data);                     \
+    if(req->fs_type != UV_FS_SCANDIR) {                   \
+      luv_cleanup_req(L, data);                           \
+      req->data = NULL;                                   \
+      uv_fs_req_cleanup(req);                             \
+    }                                                     \
     return nargs;                                         \
   }                                                       \
   lua_rawgeti(L, LUA_REGISTRYINDEX, data->req_ref);       \


fs: adapt to API changes in uv_fs_readdir

--- src/fs.c
+++ src/fs.c
@@ -57,8 +57,6 @@
 static void
 pyuv__process_fs_req(uv_fs_t* req) {
     PyGILState_STATE gstate = PyGILState_Ensure();
-    int res;
-    char *ptr;
     Loop *loop;
     FSRequest *fs_req;
     PyObject *result, *errorno, *r, *path, *item;
@@ -140,18 +138,17 @@
                 PyMem_Free(fs_req->buf.base);
                 break;
             case UV_FS_READDIR:
+                /* TODO: add (name, type) tuples instead? */
                 r = PyList_New(0);
                 if (!r) {
                     PyErr_Clear();
                     PYUV_SET_NONE(r);
                 } else {
-                    res = req->result;
-                    ptr = req->ptr;
-                    while (res--) {
-                        item = Py_BuildValue("s", ptr);
+                    uv_dirent_t ent;
+                    while (uv_fs_readdir_next(req, &ent) != UV_EOF) {
+                        item = Py_BuildValue("s", ent.name);
                         PyList_Append(r, item);
                         Py_DECREF(item);
-                        ptr += strlen(ptr) + 1;
                     }
                 }
                 break;


Revert "add_heap_page should not be invoked in gc_alloc, but should be in obj_alloc"

This reverts commit f11623f07554a470e5f9855459c9aefa3f48b48a.

--- src/gc.c
+++ src/gc.c
@@ -139,7 +139,8 @@
     if (p->s.size >= nunits)
       break;
     if (p == freep) {
-      return NULL;
+      if ((p = add_heap_page(pic)) == NULL)
+	return NULL;
     }
   }
   if (p->s.size == nunits) {
@@ -493,11 +494,8 @@
   if (obj == NULL) {
     pic_gc_run(pic);
     obj = (struct pic_object *)gc_alloc(pic, size);
-    if (obj == NULL) {
-      if (add_heap_page(pic) == NULL)
-	pic_abort(pic, "GC memory exhausted");
-      obj = (struct pic_object *)gc_alloc(pic, size);
-    }
+    if (obj == NULL)
+      pic_abort(pic, "GC memory exhausted");
   }
   obj->tt = tt;


Try harder to make installed tests pass

Try harder to make installed tests pass

--- tests/test-language.c
+++ tests/test-language.c
@@ -34,10 +34,18 @@
 	}
 	else
 	{
+		const gchar * const *current;
+		int i;
+
 		g_free (dir);

-		lang_dirs = g_new0 (gchar *, 2);
-		lang_dirs[0] = g_test_build_filename (G_TEST_DIST, "language-specs", NULL);
+		current = gtk_source_language_manager_get_search_path (fixture->manager);
+		lang_dirs = g_new0 (gchar *, g_strv_length ((gchar **)current) + 2);
+		for (i = 0; current[i] != NULL; i++)
+		{
+			lang_dirs[i] = g_strdup(current[i]);
+		}
+		lang_dirs[i] = g_test_build_filename (G_TEST_DIST, "language-specs", NULL);
 	}

 	gtk_source_language_manager_set_search_path (fixture->manager, lang_dirs);


Linux: fix compile

Linux: fix compile

--- src/if.c
+++ src/if.c
@@ -423,12 +423,14 @@
 		break;
 	default:
 		if (active) {
+			int i;
+
 			if (if_noconf)
 				active = IF_INACTIVE;
 			i = active ? LOG_WARNING : LOG_DEBUG;
 			logmessage(i, "%s: unsupported"
 			    " interface type 0x%.2x",
-			    ifp->name, ifp->hw_type);
+			    ifp->name, ifp->hwtype);
 		}
 		break;
 	}


order

order

--- src/li.h
+++ src/li.h
@@ -113,12 +113,17 @@

 typedef struct object object;

+void *allocate(void *ptr, size_t count, size_t size);
 object *create(int type);
+
+void cleanup(object *env);
+void destroy(object *obj);
+
 object *character(int c);
 object *compound(object *name, object *vars, object *body, object *env);
 object *environment(object *base);
+object *macro(object *vars, object *body, object *env);
 object *number(double n);
-object *macro(object *vars, object *body, object *env);
 object *pair(object *car, object *cdr);
 object *port(const char *filename, const char *mode);
 object *primitive(object *(*proc)(object *));
@@ -127,10 +132,10 @@
 object *syntax(object *(*proc)(object *, object *));
 object *vector(object *lst);

-void *allocate(void *ptr, size_t count, size_t size);
-void destroy(object *obj);
-void cleanup(object *env);
-
+
+object *environment_assign(object *var, object *val, object *env);
+object *environment_define(object *var, object *val, object *env);
+object *environment_lookup(object *exp, object *env);
 int is_equal(object *obj1, object *obj2);
 int is_eqv(object *obj1, object *obj2);
 int is_list(object *obj);
@@ -205,9 +210,6 @@
 /* eval */
 object *apply(object *proc, object *args);
 object *append_variable(object *var, object *val, object *env);
-object *environment_assign(object *var, object *val, object *env);
-object *environment_define(object *var, object *val, object *env);
-object *environment_lookup(object *exp, object *env);
 object *eval(object *exp, object *env);
 object *setup_environment(void);


[oo] Avoided a dual-lookup for vtable overrides in class cache.

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

--- src/oo.c
+++ src/oo.c
@@ -366,13 +366,14 @@
 {
     ASSERT_ARGS(Parrot_oo_find_vtable_override)
     Parrot_Class_attributes * const _class = PARROT_CLASS(classobj);
-
-    if (VTABLE_exists_keyed_str(interp, _class->parent_overrides, name))
-        return VTABLE_get_pmc_keyed_str(interp, _class->parent_overrides, name);
+    PMC                            *result =
+        VTABLE_get_pmc_keyed_str(interp, _class->parent_overrides, name);
+
+    if (!PMC_IS_NULL(result))
+        return result;
     else {
         /* Walk and search for the vtable method. */
         const INTVAL num_classes = VTABLE_elements(interp, _class->all_parents);
-        PMC         *result      = PMCNULL;
         INTVAL       i;

         for (i = 0; i < num_classes; i++) {


Fixed bad parameter name.

Fixed bad parameter name.

--- src/op.h
+++ src/op.h
@@ -332,7 +332,7 @@
 #define MAKE_FUNCTOR(x) expr_t::op_t::wrap_functor(bind(&x, this, _1))
 #define WRAP_FUNCTOR(x) expr_t::op_t::wrap_functor(x)

-string op_context(const expr_t::ptr_op_t op, const expr_t::ptr_op_t op);
+string op_context(const expr_t::ptr_op_t op, const expr_t::ptr_op_t goal);

 } // namespace ledger


fix mman.h ref

fix mman.h ref

--- src/os.c
+++ src/os.c
@@ -23,7 +23,12 @@
 #include <sys/mman.h>  // mmap
 #include <unistd.h>    // sysconf
 #if defined(__linux__)
+#include <features.h>
+#if defined(__GLIBC__)
 #include <linux/mman.h> // linux mmap flags
+#else
+#include <sys/mman.h>
+#endif
 #endif
 #if defined(__APPLE__)
 #include <mach/vm_statistics.h>


Added debug messages to iface callbacks so I can actually see who is wrong :)

--- src/pa.c
+++ src/pa.c
@@ -77,7 +77,7 @@

 	bool internal;         /* Whether the iface is internal */
 	bool do_dhcp;          /* Whether we should do dhcp on that
-	                          iface. Which means we are owner of that link. */
+				  iface. Which means we are owner of that link. */

 	struct list_head laps; /* laps on that iface */
 	struct list_head eaps; /* eaps on that iface */
@@ -1745,6 +1745,8 @@
 	if(!iface)
 		return;

+	L_DEBUG("pa_ifu_intiface %s=%s", ifname, enabled ? "enabled" : "disabled");
+
 	pa_iface_set_internal(pa, iface, enabled);
 }

@@ -1760,6 +1762,10 @@

 	if(!dp)
 		return;
+
+	L_DEBUG("pa_ifu_pd @%s %s %lld/%lld", ifname,
+			PREFIX_REPR(prefix),
+			(long long)valid_until, (long long)preferred_until);

 	pa_dp_update(pa, dp, ifname, excluded,
 		valid_until, preferred_until,
@@ -1874,4 +1880,3 @@
 	L_NOTICE("Pa structure destroyed");
 	free(pa);
 }
-