/* The xDisconnect and xDestroy methods are also the same */ /* ** The two input rule lists are both sorted in order of increasing ** cost. Merge them together into a single list, sorted by cost, and ** return a pointer to the head of that list. */ static fuzzer_rule fuzzerMergeRules(fuzzer_rule pA, fuzzer_rule pB) { fuzzer_rule head = new fuzzer_rule(); fuzzer_rule pTail; pTail = head; while (pA != null && pB != null) { if (pA.rCost <= pB.rCost) { pTail.pNext = pA; pTail = pA; pA = pA.pNext; } else { pTail.pNext = pB; pTail = pB; pB = pB.pNext; } } if (pA == null) { pTail.pNext = pB; } else { pTail.pNext = pA; } return(head.pNext); }
/* Note that for this virtual table, the xCreate and xConnect ** methods are identical. */ static int fuzzerDisconnect(ref object pVtab) { fuzzer_vtab p = (fuzzer_vtab)pVtab; Debug.Assert(p.nCursor == 0); do { while (p.pRule != null) { fuzzer_rule pRule = p.pRule; p.pRule = pRule.pNext; pRule = null;//sqlite3_free(pRule); } p.pRule = p.pNewRule; p.pNewRule = null; } while (p.pRule != null); pVtab = null;//sqlite3_free(p); return(SQLITE_OK); }
/* ** Compute the current output term for a fuzzer_stem. */ static int fuzzerRender( fuzzer_stem pStem, /* The stem to be rendered */ ref string pzBuf, /* Write results into this buffer. realloc if needed */ ref int pnBuf /* Size of the buffer */ ) { fuzzer_rule pRule = pStem.pRule; int n; string z; n = pStem.nBasis + pRule.nTo - pRule.nFrom; if ((pnBuf) < n + 1) { //(*pzBuf) = sqlite3_realloc((*pzBuf), n+100); //if( (*pzBuf)==0 ) return SQLITE_NOMEM; (pnBuf) = n + 100; } n = pStem.n; //z = pzBuf; if (n < 0) { z = pStem.zBasis.Substring(0, pStem.nBasis + 1);//memcpy(z, pStem.zBasis, pStem.nBasis+1); } else { z = pStem.zBasis.Substring(0, n);//memcpy( z, pStem.zBasis, n ); if (pRule.nTo != 0) { z += pRule.zTo.Substring(0, pRule.nTo);//memcpy(&z[n], pRule.zTo, pRule.nTo); } z += pStem.zBasis.Substring(n + pRule.nFrom, pStem.nBasis - n - pRule.nFrom); //memcpy(&z[n+pRule.nTo], &pStem.zBasis[n+pRule.nFrom], pStem.nBasis-n-pRule.nFrom+1); } pzBuf = z; return(SQLITE_OK); }
/* ** Open a new fuzzer cursor. */ static int fuzzerOpen(sqlite3_vtab pVTab, out sqlite3_vtab_cursor ppCursor) { fuzzer_vtab p = (fuzzer_vtab)pVTab; fuzzer_cursor pCur; pCur = new fuzzer_cursor();//= sqlite3_malloc( sizeof(pCur) ); ///if( pCur==0 ) return SQLITE_NOMEM; //memset(pCur, 0, sizeof(pCur)); pCur.pVtab = p; ppCursor = pCur; if (p.nCursor == 0 && p.pNewRule != null) { uint i; fuzzer_rule pX; fuzzer_rule[] a = new fuzzer_rule[15]; //for(i=0; i<sizeof(a)/sizeof(a[0]); i++) a[i] = 0; while ((pX = p.pNewRule) != null) { p.pNewRule = pX.pNext; pX.pNext = null; for (i = 0; a[i] != null && i < a.Length; i++)//<sizeof(a)/sizeof(a[0])-1; i++) { pX = fuzzerMergeRules(a[i], pX); a[i] = null; } a[i] = fuzzerMergeRules(a[i], pX); } for (pX = a[0], i = 1; i < a.Length; i++)//sizeof(a)/sizeof(a[0]); i++) { pX = fuzzerMergeRules(a[i], pX); } p.pRule = fuzzerMergeRules(p.pRule, pX); } p.nCursor++; return(SQLITE_OK); }
/* ** Open a new fuzzer cursor. */ static int fuzzerOpen( sqlite3_vtab pVTab, out sqlite3_vtab_cursor ppCursor ) { fuzzer_vtab p = (fuzzer_vtab)pVTab; fuzzer_cursor pCur; pCur = new fuzzer_cursor();//= sqlite3_malloc( sizeof(pCur) ); ///if( pCur==0 ) return SQLITE_NOMEM; //memset(pCur, 0, sizeof(pCur)); pCur.pVtab = p; ppCursor = pCur; if ( p.nCursor == 0 && p.pNewRule != null ) { uint i; fuzzer_rule pX; fuzzer_rule[] a = new fuzzer_rule[15]; //for(i=0; i<sizeof(a)/sizeof(a[0]); i++) a[i] = 0; while ( ( pX = p.pNewRule ) != null ) { p.pNewRule = pX.pNext; pX.pNext = null; for ( i = 0; a[i] != null && i < a.Length; i++ )//<sizeof(a)/sizeof(a[0])-1; i++) { pX = fuzzerMergeRules( a[i], pX ); a[i] = null; } a[i] = fuzzerMergeRules( a[i], pX ); } for ( pX = a[0], i = 1; i < a.Length; i++ )//sizeof(a)/sizeof(a[0]); i++) { pX = fuzzerMergeRules( a[i], pX ); } p.pRule = fuzzerMergeRules( p.pRule, pX ); } p.nCursor++; return SQLITE_OK; }
/* The xDisconnect and xDestroy methods are also the same */ /* ** The two input rule lists are both sorted in order of increasing ** cost. Merge them together into a single list, sorted by cost, and ** return a pointer to the head of that list. */ static fuzzer_rule fuzzerMergeRules( fuzzer_rule pA, fuzzer_rule pB ) { fuzzer_rule head = new fuzzer_rule(); fuzzer_rule pTail; pTail = head; while ( pA != null && pB != null ) { if ( pA.rCost <= pB.rCost ) { pTail.pNext = pA; pTail = pA; pA = pA.pNext; } else { pTail.pNext = pB; pTail = pB; pB = pB.pNext; } } if ( pA == null ) { pTail.pNext = pB; } else { pTail.pNext = pA; } return head.pNext; }