Beispiel #1
0
static void 
create_key_part(char *key, uint rownr)
{
	if (!unique_key)
		rownr &= 7;	/* Some identical keys */
	if (keyinfo[0].seg[0].type == HA_KEYTYPE_NUM) {
		sprintf(key, "%*d", keyinfo[0].seg[0].length, rownr);
	} else if (keyinfo[0].seg[0].type == HA_KEYTYPE_VARTEXT) {	/* Alpha record */
		/* Create a key that may be easily packed */
		bfill(key, keyinfo[0].seg[0].length, rownr < 10 ? 'A' : 'B');
		sprintf(key + keyinfo[0].seg[0].length - 2, "%-2d", rownr);
		if ((rownr & 7) == 0) {
			/* Change the key to force a unpack of the next key */
			bfill(key + 3, keyinfo[0].seg[0].length - 4, rownr < 10 ? 'a' : 'b');
		}
	} else {		/* Alpha record */
		if (keyinfo[0].seg[0].flag & HA_SPACE_PACK)
			sprintf(key, "%-*d", keyinfo[0].seg[0].length, rownr);
		else {
			/* Create a key that may be easily packed */
			bfill(key, keyinfo[0].seg[0].length, rownr < 10 ? 'A' : 'B');
			sprintf(key + keyinfo[0].seg[0].length - 2, "%-2d", rownr);
			if ((rownr & 7) == 0) {
				/*
				 * Change the key to force a unpack of the
				 * next key
				 */
				key[1] = (rownr < 10 ? 'a' : 'b');
			}
		}
	}
}
void writer(int num)
{
  uint i;
  uchar *buff;
  PAGECACHE_BLOCK_LINK *link;

  for (i= 0; i < number_of_write_tests; i++)
  {
    uchar c= (uchar) rand() % 256;

    if (i % report_divisor == 0)
      diag("Writer %d - %u", num, i);
    buff= pagecache_read(&pagecache, &file1, 0, 3, NULL,
                         PAGECACHE_PLAIN_PAGE,
                         PAGECACHE_LOCK_WRITE,
                         &link);

    check_page(buff, num);
    bfill(buff, TEST_PAGE_SIZE / 2, c);
    SLEEP;
    bfill(buff + TEST_PAGE_SIZE/2, TEST_PAGE_SIZE / 2, c);
    check_page(buff, num);
    pagecache_unlock_by_link(&pagecache, link,
                             PAGECACHE_LOCK_WRITE_UNLOCK,
                             PAGECACHE_UNPIN, 0, 0, 1, FALSE);
    SLEEP;
  }
}
Beispiel #3
0
  void ArrayVersion_misaligned(BenchmarkExt<int>& bench)
{
    bench.beginImplementation("Array<T,1> (misal.)");

    while (!bench.doneImplementationBenchmark())
    {
        int N = bench.getParameter();
        long iters = bench.getIterations();

        cout << bench.currentImplementation() << ": N = " << N << endl;


    Array<double,1> xfill(N+6);
    Array<double,1> x(xfill(Range(0,N+0-1)));
    initializeRandomDouble(x.dataFirst(), N);

    Array<double,1> afill(N+6);
    Array<double,1> a(afill(Range(1,N+1-1)));
    initializeRandomDouble(a.dataFirst(), N);

    Array<double,1> bfill(N+6);
    Array<double,1> b(bfill(Range(2,N+2-1)));
    initializeRandomDouble(b.dataFirst(), N);

    Array<double,1> cfill(N+6);
    Array<double,1> c(cfill(Range(3,N+3-1)));
    initializeRandomDouble(c.dataFirst(), N);

    Array<double,1> dfill(N+6);
    Array<double,1> d(dfill(Range(4,N+4-1)));
    initializeRandomDouble(d.dataFirst(), N);

    Array<double,1> yfill(N+6);
    Array<double,1> y(yfill(Range(5,N+5-1)));
    initializeRandomDouble(y.dataFirst(), N);


        bench.start();
        for (long i=0; i < iters; ++i)
        {
            x = a*b + c*d; y = b+d;
            sink();
        }
        bench.stop();

        bench.startOverhead();
        for (long i=0; i < iters; ++i) {
            sink();
	}

        bench.stopOverhead();
    }

    bench.endImplementation();
}
  void ArrayVersion_misaligned(BenchmarkExt<int>& bench, double u, double v, double w, double z)
{
    bench.beginImplementation("Array<T,1> (misal.)");

    while (!bench.doneImplementationBenchmark())
    {
        int N = bench.getParameter();
        long iters = bench.getIterations();

        cout << bench.currentImplementation() << ": N = " << N << endl;


    Array<double,1> afill(N+5);
    Array<double,1> a(afill(Range(0,N+0-1)));
    initializeRandomDouble(a.dataFirst(), N);

    Array<double,1> bfill(N+5);
    Array<double,1> b(bfill(Range(1,N+1-1)));
    initializeRandomDouble(b.dataFirst(), N);

    Array<double,1> cfill(N+5);
    Array<double,1> c(cfill(Range(2,N+2-1)));
    initializeRandomDouble(c.dataFirst(), N);

    Array<double,1> dfill(N+5);
    Array<double,1> d(dfill(Range(3,N+3-1)));
    initializeRandomDouble(d.dataFirst(), N);

    Array<double,1> xfill(N+5);
    Array<double,1> x(xfill(Range(4,N+4-1)));
    initializeRandomDouble(x.dataFirst(), N);


        bench.start();
        for (long i=0; i < iters; ++i)
        {
            x=(1.0-c*c)/((4*w)*sin(1.0+c*c-2*v*c))*a*b*u*exp(-z*d);
            sink();
        }
        bench.stop();

        bench.startOverhead();
        for (long i=0; i < iters; ++i) {
            sink();
	}

        bench.stopOverhead();
    }

    bench.endImplementation();
}
Beispiel #5
0
  void ArrayVersion_unaligned(BenchmarkExt<int>& bench)
{
    bench.beginImplementation("Array<T,1> (unal.)");

    while (!bench.doneImplementationBenchmark())
    {
        int N = bench.getParameter();
        long iters = bench.getIterations();

        cout << bench.currentImplementation() << ": N = " << N << endl;


    Array<double,1> xfill(N+1);
    Array<double,1> x(xfill(Range(1,N)));
    initializeRandomDouble(x.dataFirst(), N);

    Array<double,1> afill(N+1);
    Array<double,1> a(afill(Range(1,N)));
    initializeRandomDouble(a.dataFirst(), N);

    Array<double,1> bfill(N+1);
    Array<double,1> b(bfill(Range(1,N)));
    initializeRandomDouble(b.dataFirst(), N);

    Array<double,1> cfill(N+1);
    Array<double,1> c(cfill(Range(1,N)));
    initializeRandomDouble(c.dataFirst(), N);

    Array<double,1> dfill(N+1);
    Array<double,1> d(dfill(Range(1,N)));
    initializeRandomDouble(d.dataFirst(), N);


        bench.start();
        for (long i=0; i < iters; ++i)
        {
            x = (a+b)*(c+d);
            sink();
        }
        bench.stop();

        bench.startOverhead();
        for (long i=0; i < iters; ++i) {
            sink();
	}

        bench.stopOverhead();
    }

    bench.endImplementation();
}
void bfill(int x,int y,int bcolor,int ncolor)
{
    int current=getpixel(x,y);
    if(current!=ncolor&&current!=bcolor)
    {

        delay(2);

        putpixel(x,y,ncolor);
        bfill(x+1,y,bcolor,ncolor);
        bfill(x-1,y,bcolor,ncolor);
        bfill(x,y-1,bcolor,ncolor);
        bfill(x,y+1,bcolor,ncolor);
    }
}
Beispiel #7
0
static void uf_space_normal(N_RECINFO *rec, BIT_BUFF *bit_buff, uchar *to, uchar *end)
{
  if (get_bit(bit_buff))
    bfill((byte*) to,(end-to),' ');
  else
    decode_bytes(rec,bit_buff,to,end);
}
Beispiel #8
0
int my_aes_encrypt(const char* source, int source_length, char* dest,
                   const char* key, int key_length)
{
    KEYINSTANCE aes_key;
    uint8 block[AES_BLOCK_SIZE];	/* 128 bit block used for padding */
    int rc;			/* result codes */
    int num_blocks;		/* number of complete blocks */
    char pad_len;			/* pad size for the last block */
    int i;

    if ((rc= my_aes_create_key(&aes_key,AES_ENCRYPT,key,key_length)))
        return rc;

    num_blocks = source_length/AES_BLOCK_SIZE;

    for (i = num_blocks; i > 0; i--)   /* Encode complete blocks */
    {
        rijndaelEncrypt(aes_key.rk, aes_key.nr, (const uint8*) source,
                        (uint8*) dest);
        source+= AES_BLOCK_SIZE;
        dest+= AES_BLOCK_SIZE;
    }

    /* Encode the rest. We always have incomplete block */
    pad_len = AES_BLOCK_SIZE - (source_length - AES_BLOCK_SIZE*num_blocks);
    memcpy(block, source, 16 - pad_len);
    bfill(block + AES_BLOCK_SIZE - pad_len, pad_len, pad_len);
    rijndaelEncrypt(aes_key.rk, aes_key.nr, block, (uint8*) dest);
    return AES_BLOCK_SIZE*(num_blocks + 1);
}
Beispiel #9
0
static void 
update_record(char *record)
{
	char           *pos = record + 1;
	if (recinfo[1].type == FIELD_BLOB) {
		char           *column, *ptr;
		int		length;
		length = uint4korr(pos);	/* Long blob */
		memcpy_fixed(&column, pos + 4, sizeof(char *));
		memcpy(blob_key, column, length);	/* Move old key */
		ptr = blob_key;
		memcpy_fixed(pos + 4, &ptr, sizeof(char *));	/* Store pointer to new
								 * key */
		if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
			casedn(blob_key, length);
		pos += recinfo[1].length;
	} else if (recinfo[1].type == FIELD_VARCHAR) {
		uint		length = uint2korr(pos);
		casedn(pos + 2, length);
		pos += recinfo[1].length;
	} else {
		if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
			casedn(pos, keyinfo[0].seg[0].length);
		pos += recinfo[1].length;
	}

	if (recinfo[2].type == FIELD_BLOB) {
		char           *column;
		int		length;
		length = uint4korr(pos);
		memcpy_fixed(&column, pos + 4, sizeof(char *));
		memcpy(blob_record, column, length);
		bfill(blob_record + length, 20, '.');	/* Make it larger */
		length += 20;
		int4store(pos, length);
		column = blob_record;
		memcpy_fixed(pos + 4, &column, sizeof(char *));
	} else if (recinfo[2].type == FIELD_VARCHAR) {
		/* Second field is longer than 10 characters */
		uint		length = uint2korr(pos);
		bfill(pos + 2 + length, recinfo[2].length - length - 2, '.');
		length = recinfo[2].length - 2;
		int2store(pos, length);
	} else {
		bfill(pos + recinfo[2].length - 10, 10, '.');
	}
}
Beispiel #10
0
void _myfree(void *ptr, const char *filename, uint lineno, myf myflags)
{
  struct st_irem *irem;
  DBUG_ENTER("_myfree");
  DBUG_PRINT("enter",("ptr: %p", ptr));

  if (!sf_malloc_quick)
    (void) _sanity (filename, lineno);

  if ((!ptr && (myflags & MY_ALLOW_ZERO_PTR)) ||
      check_ptr("Freeing",(uchar*) ptr,filename,lineno))
    DBUG_VOID_RETURN;

  /* Calculate the address of the remember structure */
  irem= (struct st_irem *) ((char*) ptr- ALIGN_SIZE(sizeof(struct st_irem))-
			    sf_malloc_prehunc);

  /*
    Check to make sure that we have a real remember structure.
    Note: this test could fail for four reasons:
    (1) The memory was already free'ed
    (2) The memory was never new'ed
    (3) There was an underrun
    (4) A stray pointer hit this location
  */

  if (*((uint32*) ((char*) ptr- sizeof(uint32))) != MAGICKEY)
  {
    fprintf(stderr, "Error: Freeing unallocated data at line %d, '%s'\n",
	    lineno, filename);
    DBUG_PRINT("safe",("Unallocated data at line %d, '%s'",lineno,filename));
    (void) fflush(stderr);
    DBUG_VOID_RETURN;
  }

  /* Remove this structure from the linked list */
  pthread_mutex_lock(&THR_LOCK_malloc);
  if (irem->prev)
    irem->prev->next= irem->next;
   else
    sf_malloc_root= irem->next;

  if (irem->next)
    irem->next->prev= irem->prev;
  /* Handle the statistics */
  sf_malloc_cur_memory-= irem->datasize;
  sf_malloc_count--;
  pthread_mutex_unlock(&THR_LOCK_malloc);

#ifndef HAVE_purify
  /* Mark this data as free'ed */
  if (!sf_malloc_quick)
    bfill(ptr, irem->datasize, (pchar) FREE_VAL);
#endif
  *((uint32*) ((char*) ptr- sizeof(uint32)))= ~MAGICKEY;
  /* Actually free the memory */
  free((char*) irem);
  DBUG_VOID_RETURN;
}
Beispiel #11
0
void _myfree (gptr pPtr, const char *sFile, uint uLine, myf myflags)
{
  struct remember *pRec;
  DBUG_ENTER("_myfree");
  DBUG_PRINT("enter",("ptr: %lx",pPtr));

  if (!sf_malloc_quick)
    (void) _sanity (sFile, uLine);

  if ((!pPtr && (myflags & MY_ALLOW_ZERO_PTR)) ||
      check_ptr("Freeing",(byte*) pPtr,sFile,uLine))
    DBUG_VOID_RETURN;

  /* Calculate the address of the remember structure */
  pRec = (struct remember *) ((byte*) pPtr-sizeof(struct irem)-
			      sf_malloc_prehunc);

  /* Check to make sure that we have a real remember structure	*/
  /* Note: this test could fail for four reasons:		*/
  /*	(1) The memory was already free'ed			*/
  /*	(2) The memory was never new'ed				*/
  /*	(3) There was an underrun				*/
  /*	(4) A stray pointer hit this location			*/

  if (*((long*) ((char*) &pRec -> lSpecialValue+sf_malloc_prehunc))
      != MAGICKEY)
  {
    fprintf (stderr, "Freeing unallocated data at line %d, '%s'\n",
	     uLine, sFile);
    DBUG_PRINT("safe",("Unallocated data at line %d, '%s'",uLine,sFile));
    (void) fflush(stderr);
    DBUG_VOID_RETURN;
  }

  /* Remove this structure from the linked list */
  pthread_mutex_lock(&THR_LOCK_malloc);
  if (pRec -> pPrev) {
    pRec -> pPrev -> pNext = pRec -> pNext;
  } else {
    pRememberRoot = pRec -> pNext;
  }
  if (pRec -> pNext) {
    pRec -> pNext -> pPrev = pRec -> pPrev;
  }
  /* Handle the statistics */
  lCurMemory -= pRec -> uDataSize;
  cNewCount--;
  pthread_mutex_unlock(&THR_LOCK_malloc);

#ifndef HAVE_purify
  /* Mark this data as free'ed */
  bfill(&pRec->aData[sf_malloc_prehunc],pRec->uDataSize,(pchar) FREE_VAL);
#endif
  *((long*) ((char*) &pRec -> lSpecialValue+sf_malloc_prehunc)) = ~MAGICKEY;

  /* Actually free the memory */
  free ((my_string ) pRec);
  DBUG_VOID_RETURN;
}
Beispiel #12
0
static void uf_space_prespace(N_RECINFO *rec, BIT_BUFF *bit_buff, uchar *to, uchar *end)
{
  uint spaces;
  if (get_bit(bit_buff))
    bfill((byte*) to,(end-to),' ');
  else
  {
    if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end)
    {
      bit_buff->error=1;
      return;
    }
    bfill((byte*) to,spaces,' ');
    if (to+spaces != end)
      decode_bytes(rec,bit_buff,to+spaces,end);
  }
}
static void make_record(uchar *record, uint n1, uint n2, uint n3,
			const char *mark, uint count)
{
  bfill(record,reclength,' ');
  sprintf((char*) record,"%6d:%4d:%8d:%3.3s: %4d",
	  n1,n2,n3,mark,count);
  record[37]='A';				/* Store A in null key */
  record[38]=1;					/* set as null */
}
Beispiel #14
0
void * memset
    (
    void * m,                   /* block of memory */
    int    c,                   /* character to store */
    size_t size                 /* size of memory */
    )
    {
    bfill ((char *) m, (int) size, c);
    return (m);
    }
void main()
{
    clrscr();
    int gdriver=DETECT,gmode;
    initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
    setcolor(RED);
    rectangle(100,100,150,150);
    bfill(125,125,RED,GREEN);
    getch();
}
Beispiel #16
0
static void backblank( SAREA area, void *dummy )
/**********************************************/
{
    register    ORD                     row;

    dummy=dummy;
    for( row = area.row; row < area.row + area.height; ++row ) {
        bfill( &UIData->screen, row, area.col, UIData->attrs[ATTR_NORMAL], ' ', area.width );
    }
}
Beispiel #17
0
static char *process_int_arg(char *to, char *end, size_t length,
                             longlong par, char arg_type, uint print_type)
{
  size_t res_length, to_length;
  char *store_start= to, *store_end;
  char buff[32];

  if ((to_length= (size_t) (end-to)) < 16 || length)
    store_start= buff;

  if (arg_type == 'd' || arg_type == 'i')
    store_end= longlong10_to_str(par, store_start, -10);
  else if (arg_type == 'u')
    store_end= longlong10_to_str(par, store_start, 10);
  else if (arg_type == 'p')
  {
    store_start[0]= '0';
    store_start[1]= 'x';
    store_end= ll2str(par, store_start + 2, 16, 0);
  }
  else if (arg_type == 'o')
  {
    store_end= ll2str(par, store_start, 8, 0);
  }
  else
  {
    DBUG_ASSERT(arg_type == 'X' || arg_type =='x');
    store_end= ll2str(par, store_start, 16, (arg_type == 'X'));
  }

  if ((res_length= (size_t) (store_end - store_start)) > to_length)
    return to;                           /* num doesn't fit in output */
  /* If %#d syntax was used, we have to pre-zero/pre-space the string */
  if (store_start == buff)
  {
    length= min(length, to_length);
    if (res_length < length)
    {
      size_t diff= (length- res_length);
      bfill(to, diff, (print_type & PREZERO_ARG) ? '0' : ' ');
      if (arg_type == 'p' && print_type & PREZERO_ARG)
      {
        if (diff > 1)
          to[1]= 'x';
        else
          store_start[0]= 'x';
        store_start[1]= '0';
      }
      to+= diff;
    }
    bmove(to, store_start, res_length);
  }
  to+= res_length;
  return to;
}
Beispiel #18
0
	EVB
*get_evb()
{
	REG EVB		*e;

	if (e = eul)
	{
	  eul = eul->e_nextp;
	  bfill(sizeof(EVB), 0, e);
	}
	return(e);
}
Beispiel #19
0
static void uf_endspace(N_RECINFO *rec, BIT_BUFF *bit_buff, uchar *to,
			uchar *end)
{
  uint spaces;
  if ((spaces=get_bits(bit_buff,rec->space_length_bits))+to > end)
  {
    bit_buff->error=1;
    return;
  }
  if (to+spaces != end)
    decode_bytes(rec,bit_buff,to,end-spaces);
  bfill((byte*) end-spaces,spaces,' ');
}
Beispiel #20
0
void intern drawbox( BUFFER *bptr, SAREA area, const char *box, ATTR attr, bool fill )
/************************************************************************************/
{
    uisize      row;

    bpixel( bptr, area.row, area.col, attr, BOX_CHAR( box, TOP_LEFT ) );
    if( area.width > 2 )
        bfill( bptr, area.row, area.col + 1, attr, BOX_CHAR( box, TOP_LINE ), area.width - 2 );
    bpixel( bptr, area.row, area.col + area.width - 1, attr, BOX_CHAR( box, TOP_RIGHT ) );
    for( row = area.row + 1; row < area.row + area.height - 1; ++row ) {
        bpixel( bptr, row, area.col, attr, BOX_CHAR( box, LEFT_LINE ) );
        if( fill && area.width > 2 ) {
            bfill( bptr, row, area.col + 1, attr, ' ', area.width - 2 );
        }
        bpixel( bptr, row, area.col + area.width - 1, attr, BOX_CHAR( box, RIGHT_LINE ) );
    }
    bpixel( bptr, row, area.col, attr, BOX_CHAR( box, BOTTOM_LEFT ) );
    if( area.width > 2 )
        bfill( bptr, row, area.col + 1, attr, BOX_CHAR( box, BOTTOM_LINE ), area.width - 2 );
    bpixel( bptr, row, area.col + area.width - 1, attr, BOX_CHAR( box, BOTTOM_RIGHT ) );
    physupdate( &area );
}
Beispiel #21
0
void intern drawbox( BUFFER     *bptr,
                     SAREA      area,
                     char       *box,
                     ATTR       attr,
                     int        fill )
/************************************/
{
    register    ORD                     row;

    bpixel( bptr, area.row, area.col, attr, box[ 0 ] );
    bfill( bptr, area.row, area.col + 1, attr, box[ 4 ], area.width - 2 );
    bpixel( bptr, area.row, area.col + area.width - 1, attr, box[ 1 ] );
    for( row = area.row + 1 ; row < area.row + area.height - 1 ; ++row ) {
        bpixel( bptr, row, area.col, attr, box[ 7 ] );
        if( fill ) {
            bfill( bptr, row, area.col + 1, attr, ' ', area.width - 2 );
        }
        bpixel( bptr, row, area.col + area.width - 1, attr, box[ 5 ] );
    }
    bpixel( bptr, row, area.col, attr, box[ 3 ] );
    bfill( bptr, row, area.col + 1, attr, box[ 6 ], area.width - 2 );
    bpixel( bptr, row, area.col + area.width - 1, attr, box[ 2 ] );
    physupdate( &area );
}
Beispiel #22
0
void MultiJac::eval(doublereal* x0, doublereal* resid0, doublereal rdt)
{
    m_nevals++;
    clock_t t0 = clock();
    bfill(0.0);
    size_t n, m, ipt=0, j, nv, mv, iloc;
    doublereal rdx, dx, xsave;

    for (j = 0; j < m_points; j++) {
        nv = m_resid->nVars(j);
        for (n = 0; n < nv; n++) {
            // perturb x(n); preserve sign(x(n))
            xsave = x0[ipt];
            if (xsave >= 0) {
                dx = xsave*m_rtol + m_atol;
            } else {
                dx = xsave*m_rtol - m_atol;
            }
            x0[ipt] = xsave + dx;
            dx = x0[ipt] - xsave;
            rdx = 1.0/dx;

            // calculate perturbed residual
            m_resid->eval(j, x0, m_r1.data(), rdt, 0);

            // compute nth column of Jacobian
            for (size_t i = j - 1; i != j+2; i++) {
                if (i != npos && i < m_points) {
                    mv = m_resid->nVars(i);
                    iloc = m_resid->loc(i);
                    for (m = 0; m < mv; m++) {
                        value(m+iloc,ipt) = (m_r1[m+iloc] - resid0[m+iloc])*rdx;
                    }
                }
            }
            x0[ipt] = xsave;
            ipt++;
        }
    }

    for (n = 0; n < m_size; n++) {
        m_ssdiag[n] = value(n,n);
    }

    m_elapsed += double(clock() - t0)/CLOCKS_PER_SEC;
    m_age = 0;
}
Beispiel #23
0
static void mfill( BUFFER *bptr, ORD row, ORD col, ATTR attr,
                   char ch, int len, int height )
/***********************************************************/
{
    SAREA       area;

    area.row = row;
    area.col = col;
    area.width = len;
    area.height = height;
    while( height != 0 ) {
        bfill( bptr, row, col, attr, ch, len );
        ++row;
        --height;
    }
    physupdate( &area );
}
Beispiel #24
0
size_t my_strnxfrm_simple(CHARSET_INFO * cs, 
                          uchar *dest, size_t len,
                          const uchar *src, size_t srclen)
{
  const uchar *map= cs->sort_order;
  size_t dstlen= len;
  set_if_smaller(len, srclen);
  if (dest != src)
  {
    const uchar *end;
    for ( end=src+len; src < end ;  )
      *dest++= map[*src++];
  }
  else
  {
    const uchar *end;
    for ( end=dest+len; dest < end ; dest++)
      *dest= (char) map[(uchar) *dest];
  }
  if (dstlen > len)
    bfill(dest, dstlen - len, ' ');
  return dstlen;
}
Beispiel #25
0
char *strmake(register char *dst, register const char *src, size_t length)
{
  while (length--)
  {
    if (! (*dst++ = *src++))
    {
#ifdef EXTRA_DEBUG
      /*
        'length' is the maximum length of the string; the buffer needs
        to be one character larger to accommodate the terminating
        '\0'.  This is easy to get wrong, so we make sure we write to
        the entire length of the buffer to identify incorrect
        buffer-sizes.  We only initialism the "unused" part of the
        buffer here, a) for efficiency, and b) because dst==src is
        allowed, so initializing the entire buffer would overwrite the
        source-string. Also, we write a character rather than '\0' as
        this makes spotting these problems in the results easier.

        If we are using purify/valgrind, we only set one character at
        end to be able to detect also wrong accesses after the end of
        dst.
      */
      if (length)
      {
#ifdef HAVE_valgrind
        dst[length-1]= 'Z';
#else
        bfill(dst, length-1, (int) 'Z');
#endif /* HAVE_valgrind */
      }
#endif /* EXTRA_DEBUG */
      return dst-1;
    }
  }
  *dst=0;
  return dst;
}
Beispiel #26
0
void memPartInit 
    (
    FAST PART_ID partId,        /* partition to initialize */
    char *pPool,                /* pointer to memory block */
    unsigned poolSize           /* block size in bytes */
    )
    {
    /* initialize partition descriptor */

    bfill ((char *) partId, sizeof (*partId), 0);

    partId->options	  = memPartOptionsDefault;
    partId->minBlockWords = sizeof (FREE_BLOCK) >> 1;

    /* initialize partition semaphore with a virtual function so semaphore
     * type is selectable.  By default memPartLibInit() will utilize binary
     * semaphores while memInit() will utilize mutual exclusion semaphores
     * with the options stored in _mutexOptionsMemLib.
     */

    (* memPartSemInitRtn) (partId);

    dllInit (&partId->freeList);			/* init. free list */

#ifdef WV_INSTRUMENTATION
    if (wvObjIsEnabled)
    {
    /* windview - connect object class event logging routine */
    objCoreInit (&partId->objCore, memPartInstClassId); 
    }
    else
#endif
    objCoreInit (&partId->objCore, memPartClassId);	/* initialize core */

    (void) memPartAddToPool (partId, pPool, poolSize);
    }
Beispiel #27
0
static void update_record(uchar *record)
{
  uchar *pos=record+1;
  if (recinfo[1].type == FIELD_BLOB)
  {
    uchar *column,*ptr;
    int length;
    length=uint4korr(pos);			/* Long blob */
    memcpy_fixed(&column,pos+4,sizeof(char*));
    memcpy(blob_key,column,length);		/* Move old key */
    ptr=blob_key;
    memcpy_fixed(pos+4,&ptr,sizeof(char*));	/* Store pointer to new key */
    if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
      default_charset_info->cset->casedn(default_charset_info,
                                         (char*) blob_key, length,
                                         (char*) blob_key, length);
    pos+=recinfo[1].length;
  }
  else if (recinfo[1].type == FIELD_VARCHAR)
  {
    uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
    uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos);
    default_charset_info->cset->casedn(default_charset_info,
                                       (char*) pos + pack_length, length,
                                       (char*) pos + pack_length, length);
    pos+=recinfo[1].length;
  }
  else
  {
    if (keyinfo[0].seg[0].type != HA_KEYTYPE_NUM)
      default_charset_info->cset->casedn(default_charset_info,
                                         (char*) pos, keyinfo[0].seg[0].length,
                                         (char*) pos, keyinfo[0].seg[0].length);
    pos+=recinfo[1].length;
  }

  if (recinfo[2].type == FIELD_BLOB)
  {
    uchar *column;
    int length;
    length=uint4korr(pos);
    memcpy_fixed(&column,pos+4,sizeof(char*));
    memcpy(blob_record,column,length);
    bfill(blob_record+length,20,'.');	/* Make it larger */
    length+=20;
    int4store(pos,length);
    column= blob_record;
    memcpy_fixed(pos+4,&column,sizeof(char*));
  }
  else if (recinfo[2].type == FIELD_VARCHAR)
  {
    /* Second field is longer than 10 characters */
    uint pack_length= HA_VARCHAR_PACKLENGTH(recinfo[1].length-1);
    uint length= pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos);
    bfill(pos+pack_length+length,recinfo[2].length-length-pack_length,'.');
    length=recinfo[2].length-pack_length;
    if (pack_length == 1)
      *(uchar*) pos= (uchar) length;
    else
      int2store(pos,length);
  }
  else
  {
    bfill(pos+recinfo[2].length-10,10,'.');
  }
}
Beispiel #28
0
/*
  Change size of file.

  SYNOPSIS
    my_chsize()
      fd		File descriptor
      new_length	New file size
      filler		If we don't have truncate, fill up all bytes after
			new_length with this character
      MyFlags		Flags

  DESCRIPTION
    my_chsize() truncates file if shorter else fill with the filler character.
    The function also changes the file pointer. Usually it points to the end
    of the file after execution.

  RETURN VALUE
    0	Ok
    1	Error
*/
int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags)
{
  my_off_t oldsize;
  uchar buff[IO_SIZE];
  DBUG_ENTER("my_chsize");
  DBUG_PRINT("my",("fd: %d  length: %lu  MyFlags: %d",fd,(ulong) newlength,
		   MyFlags));

  if ((oldsize= my_seek(fd, 0L, MY_SEEK_END, MYF(MY_WME+MY_FAE))) == newlength)
    DBUG_RETURN(0);

  DBUG_PRINT("info",("old_size: %ld", (ulong) oldsize));

  if (oldsize > newlength)
  {
#ifdef _WIN32
    if (my_win_chsize(fd, newlength))
    {
      my_errno= errno;
      goto err;
    }
    DBUG_RETURN(0);
#elif defined(HAVE_FTRUNCATE)
    if (ftruncate(fd, (off_t) newlength))
    {
      my_errno= errno;
      goto err;
    }
    DBUG_RETURN(0);
#elif defined(HAVE_CHSIZE)
    if (chsize(fd, (off_t) newlength))
    {
      my_errno=errno;
      goto err;
    }
    DBUG_RETURN(0);
#else
    /*
      Fill space between requested length and true length with 'filler'
      We should never come here on any modern machine
    */
    if (my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE))
        == MY_FILEPOS_ERROR)
    {
      goto err;
    }
    swap_variables(my_off_t, newlength, oldsize);
#endif
  }

  /* Full file with 'filler' until it's as big as requested */
  bfill(buff, IO_SIZE, filler);
  while (newlength-oldsize > IO_SIZE)
  {
    if (my_write(fd, buff, IO_SIZE, MYF(MY_NABP)))
      goto err;
    oldsize+= IO_SIZE;
  }
  if (my_write(fd,buff,(size_t) (newlength-oldsize), MYF(MY_NABP)))
    goto err;
  DBUG_RETURN(0);

err:
  DBUG_PRINT("error", ("errno: %d", errno));
  if (MyFlags & MY_WME)
    my_error(EE_CANT_CHSIZE, MYF(ME_BELL+ME_WAITTANG), my_errno);
  DBUG_RETURN(1);
} /* my_chsize */
Beispiel #29
0
void canvas()
{	
	int button,mousex,mousey;	//local mouse variables
	if(cur_panel==0&&canvas_flag!=1)
	{
	top_panel_buttons(tool_but_num,0,5);
	hover_text(cur_tool);
	button_click((2+cur_tool*20),2,(18+cur_tool*20),18);
	canvas_flag=1;
	}
	else if(cur_panel==1&&canvas_flag!=2)
	{
	hover_text(cur_tool);
	top_panel_buttons(buttons_data[cur_tool-1],0,5);
	button_click((2+cur_style*20),2,(18+cur_style*20),18);
	canvas_flag=2;
	}
	hover_text(cur_tool);
	getmousepos(&button,&mousex,&mousey);
	for(;mousey>20;getmousepos(&button,&mousex,&mousey))
	{
		if(button==1)
		{
			restrictmouseptr(0,27,xmax,ymax);
			switch(cur_tool)
			{
				case 4: user_text(mousex,mousey);
						break;
				case 5: pencil();
						break;
				case 6: brush(2);
						break;
				case 7: bfill(mousex,mousey);
						break;
				case 8: brush(1);
						break;
				case 9: user_pickcolor();
						break;
				case 10: user_line();
						break;
				case 11: drawRectangle();
						break;
				case 12: drawEllipse();
						break;
				case 13: drawSpray();
						break;
				case 14: drawSpiral();
						break;
				case 15:user_clip();
						break;
				case 16:user_poly();
						break;
				case 17:drawCircle(cur_style);
						break;

			}

		}
		else
		{
			restrictmouseptr(0,0,xmax,ymax);
			
		}
	}
}
Beispiel #30
0
gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags)
{
    struct remember *pTmp;
    DBUG_ENTER("_mymalloc");
    DBUG_PRINT("enter",("Size: %u",uSize));


    if (!sf_malloc_quick)
      (void) _sanity (sFile, uLine);

    if(uSize + lCurMemory > safemalloc_mem_limit)
      pTmp = 0;
    else
       /* Allocate the physical memory */
       pTmp = (struct remember *) malloc (
		sizeof (struct irem)			/* remember data  */
		+ sf_malloc_prehunc
		+ uSize					/* size requested */
		+ 4					/* overrun mark   */
		+ sf_malloc_endhunc
		);

    /* Check if there isn't anymore memory avaiable */
    if (pTmp == NULL)
    {
      if (MyFlags & MY_FAE)
	error_handler_hook=fatal_error_handler_hook;
      if (MyFlags & (MY_FAE+MY_WME))
      {
	char buff[SC_MAXWIDTH];
	my_errno=errno;
	sprintf(buff,"Out of memory at line %d, '%s'", uLine, sFile);
	my_message(EE_OUTOFMEMORY,buff,MYF(ME_BELL+ME_WAITTANG));
	sprintf(buff,"needed %d byte (%ldk), memory in use: %ld bytes (%ldk)",
		uSize, (uSize + 1023L) / 1024L,
		lMaxMemory, (lMaxMemory + 1023L) / 1024L);
	my_message(EE_OUTOFMEMORY,buff,MYF(ME_BELL+ME_WAITTANG));
      }
      DBUG_PRINT("error",("Out of memory, in use: %ld at line %d, '%s'",
			  lMaxMemory,uLine, sFile));
      if (MyFlags & MY_FAE)
	exit(1);
      DBUG_RETURN ((gptr) NULL);
    }

    /* Fill up the structure */
    *((long*) ((char*) &pTmp -> lSpecialValue+sf_malloc_prehunc)) = MAGICKEY;
    pTmp -> aData[uSize + sf_malloc_prehunc+0] = MAGICEND0;
    pTmp -> aData[uSize + sf_malloc_prehunc+1] = MAGICEND1;
    pTmp -> aData[uSize + sf_malloc_prehunc+2] = MAGICEND2;
    pTmp -> aData[uSize + sf_malloc_prehunc+3] = MAGICEND3;
    pTmp -> sFileName = (my_string) sFile;
    pTmp -> uLineNum = uLine;
    pTmp -> uDataSize = uSize;
    pTmp -> pPrev = NULL;

    /* Add this remember structure to the linked list */
    pthread_mutex_lock(&THR_LOCK_malloc);
    if ((pTmp->pNext=pRememberRoot))
    {
      pRememberRoot -> pPrev = pTmp;
    }
    pRememberRoot = pTmp;

    /* Keep the statistics */
    lCurMemory += uSize;
    if (lCurMemory > lMaxMemory) {
	lMaxMemory = lCurMemory;
    }
    cNewCount++;
    pthread_mutex_unlock(&THR_LOCK_malloc);

    /* Set the memory to the aribtrary wierd value */
#ifdef HAVE_purify
    if (MyFlags & MY_ZEROFILL)
#endif
      bfill(&pTmp -> aData[sf_malloc_prehunc],uSize,
	    (char) (MyFlags & MY_ZEROFILL ? 0 : ALLOC_VAL));
    /* Return a pointer to the real data */
    DBUG_PRINT("exit",("ptr: %lx",&(pTmp -> aData[sf_malloc_prehunc])));
    if (sf_min_adress > &(pTmp -> aData[sf_malloc_prehunc]))
      sf_min_adress = &(pTmp -> aData[sf_malloc_prehunc]);
    if (sf_max_adress < &(pTmp -> aData[sf_malloc_prehunc]))
      sf_max_adress = &(pTmp -> aData[sf_malloc_prehunc]);
    DBUG_RETURN ((gptr) &(pTmp -> aData[sf_malloc_prehunc]));
}