示例#1
0
文件: st_arp.c 项目: swifteen/nvr_sdk
static void __ipcs_table_updating(
    struct nc_ipcs_table *tbl,
    int *arp_fds,
    int arp_wireless_fd
)
{
    fd_set readfds;
    int maxfd = -1;
    struct timeval timeo;
#define RCV_BUF_SIZE    1400
    char buf[RCV_BUF_SIZE];
    struct sockaddr_ll saddr;
    socklen_t saddr_len;
    int i;
    int ret = -1;

    timeo.tv_sec = NC_ARP_TIMEOUT_INTERVAL;
    timeo.tv_usec = 0;

    while (1)
    {
        FD_ZERO(&readfds);
        maxfd = 0;

        for (i = 0; i < tbl->wire_cnt; ++i)
        {
            st_fds_set(&readfds, arp_fds[i], &maxfd);
        }

        if (tbl->wireless_enable)
        {
            st_fds_set(&readfds, arp_wireless_fd, &maxfd);
        }

        st_fds_set(&readfds, tbl->dhcp_fd, &maxfd);

        ret = select(maxfd + 1, &readfds, NULL, NULL, &timeo);
        if (ret < 0)
        {
            if (errno == EINTR)
            {
                continue;
            }
            st_err("select error:%d\n", errno);
            perror("select ");
            break;
        }

        if (ret == 0)
        {
            timeo.tv_sec = NC_ARP_TIMEOUT_INTERVAL;
            timeo.tv_usec = 0;
            ipcs_table_updating_by_time(tbl);
            ipcs_table_refresh_wire(tbl, arp_fds);
            ipcs_table_refresh_wireless(tbl, arp_wireless_fd);
            continue;
        }

        /*for wire*/
        for (i = 0; i < tbl->wire_cnt; ++i)
        {
            if (FD_ISSET(arp_fds[i], &readfds))
            {
                st_dbg("\n");
                saddr_len = sizeof(saddr);
                memset(&saddr, 0, sizeof(saddr));
                ret = recvfrom(
                          arp_fds[i],
                          buf,
                          RCV_BUF_SIZE,
                          0,
                          (struct sockaddr *)&saddr,
                          &saddr_len
                      );
                if (ret < 0)
                {
                    st_err("recvfrom error:%d!\n", errno);
                    perror("recvfrom");
                    continue;
                }

                ipcs_table_updating_wire_by_arp(tbl, i, buf, ret, &saddr);
            }
        }

        /*for wireless*/
        if (tbl->wireless_enable)
        {
            if (FD_ISSET(arp_wireless_fd, &readfds))
            {
                st_dbg("\n");
                while (1)
                {
                    saddr_len = sizeof(saddr);
                    memset(&saddr, 0, sizeof(saddr));
                    ret = recvfrom(
                              arp_wireless_fd,
                              buf,
                              RCV_BUF_SIZE,
                              MSG_DONTWAIT,
                              (struct sockaddr *)&saddr,
                              &saddr_len
                          );
                    if (ret < 0)
                    {
                        st_dbg("errno = %d\n",errno);
                        if ((errno != EAGAIN) && (errno != EWOULDBLOCK))
                        {
                            st_err("recvfrom error:%d!\n", errno);
                            perror("recvfrom");
                        }
                        break;
                    }

                    ipcs_table_updating_wireless_by_arp(tbl, buf, ret, &saddr);
                }
            }
        }

        if (FD_ISSET(tbl->dhcp_fd, &readfds))
        {
            struct nc_new_info *ipc = NULL;

            while (1)
            {
                ret = recv(tbl->dhcp_fd, buf, RCV_BUF_SIZE, MSG_DONTWAIT);
                if (ret < 0)
                {
                    if ((errno != EAGAIN) && (errno != EWOULDBLOCK))
                    {
                        st_err("recv error:%d!\n", errno);
                        perror("recv");
                    }
                    break;
                }

                if (ret == 0)
                {
                    st_err("fd error, something wrong ...!\n");
                    break;
                }

                ipc = (struct nc_new_info*)buf;
                if (ipc->port_id == (unsigned short)-1)
                {
                    st_dbg("dhcp update:%d,%02x:%02x:%02x:%02x:%02x:%02x\n",
                           ipc->client_ip,(ipc->hwaddr)[0],(ipc->hwaddr)[1],
                           (ipc->hwaddr)[2],(ipc->hwaddr)[3],(ipc->hwaddr)[4],
                           (ipc->hwaddr)[5]);
                    ipcs_table_updating_wireless(tbl, ipc->client_ip, ipc->hwaddr);
                }
                else
                {
                    if ((((short)ipc->port_id) < 0) || (ipc->port_id >= tbl->wire_cnt))
                    {
                        st_err("port_id:%d from dhcp is wrong! range:[0-%d)\n", ipc->port_id, tbl->wire_cnt);
                        abort();
                    }
                    ipcs_table_updating_wire(tbl, ipc->port_id, ipc->client_ip, ipc->hwaddr);
                }
            }
        }
    }
}
示例#2
0
int main ()
{
  v2sf a, b, c, d;
  int i, j;

  /* cabs.eq.ps */
  a = (v2sf) {11, 22};
  b = (v2sf) {-33, -44};
  c = (v2sf) {55, 66};
  d = (v2sf) {-77, -88};
  i = 0;
  j = 0;
  if (__builtin_mips_any_cabs_eq_4s(a, b, c, d) != i)
     abort ();
  if (__builtin_mips_all_cabs_eq_4s(a, b, c, d) != j)
     abort ();

  /* cabs.eq.ps */
  a = (v2sf) {11, 22};
  b = (v2sf) {-11, -44};
  c = (v2sf) {55, 66};
  d = (v2sf) {-77, -88};
  i = 1;
  j = 0;
  if (__builtin_mips_any_cabs_eq_4s(a, b, c, d) != i)
     abort ();
  if (__builtin_mips_all_cabs_eq_4s(a, b, c, d) != j)
     abort ();

  /* cabs.eq.ps */
  a = (v2sf) {11, 22};
  b = (v2sf) {-33, -22};
  c = (v2sf) {55, 66};
  d = (v2sf) {-77, -88};
  i = 1;
  j = 0;
  if (__builtin_mips_any_cabs_eq_4s(a, b, c, d) != i)
     abort ();
  if (__builtin_mips_all_cabs_eq_4s(a, b, c, d) != j)
     abort ();

  /* cabs.eq.ps */
  a = (v2sf) {11, 22};
  b = (v2sf) {-33, -44};
  c = (v2sf) {55, 66};
  d = (v2sf) {-55, -88};
  i = 1;
  j = 0;
  if (__builtin_mips_any_cabs_eq_4s(a, b, c, d) != i)
     abort ();
  if (__builtin_mips_all_cabs_eq_4s(a, b, c, d) != j)
     abort ();

  /* cabs.eq.ps */
  a = (v2sf) {11, 22};
  b = (v2sf) {-33, -44};
  c = (v2sf) {55, 66};
  d = (v2sf) {-77, -66};
  i = 1;
  j = 0;
  if (__builtin_mips_any_cabs_eq_4s(a, b, c, d) != i)
     abort ();
  if (__builtin_mips_all_cabs_eq_4s(a, b, c, d) != j)
     abort ();

  /* cabs.eq.ps */
  a = (v2sf) {11, 22};
  b = (v2sf) {-11, -22};
  c = (v2sf) {55, 66};
  d = (v2sf) {-55, -66};
  i = 1;
  j = 1;
  if (__builtin_mips_any_cabs_eq_4s(a, b, c, d) != i)
     abort ();
  if (__builtin_mips_all_cabs_eq_4s(a, b, c, d) != j)
     abort ();

  /* Test all comparisons */
  a = (v2sf) {11, 33};
  b = (v2sf) {-33, -11};
  c = (v2sf) {55, 66};
  d = (v2sf) {-55, -88};

  i = test0 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test1 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test2 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test3 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test4 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test5 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test6 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test7 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test8 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test9 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test10 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test11 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test12 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test13 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test14 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test15 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test16 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test17 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test18 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test19 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test20 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test21 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test22 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test23 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test24 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test25 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test26 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test27 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test28 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test29 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test30 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test31 (a, b, c, d);
  if (i != 0)
    abort ();

  /* Reversed arguments */
  i = test0 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test1 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test2 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test3 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test4 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test5 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test6 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test7 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test8 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test9 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test10 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test11 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test12 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test13 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test14 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test15 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test16 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test17 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test18 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test19 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test20 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test21 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test22 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test23 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test24 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test25 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test26 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test27 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test28 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test29 (b, a, d, c);
  if (i != 0)
    abort ();
  i = test30 (b, a, d, c);
  if (i != 1)
    abort ();
  i = test31 (b, a, d, c);
  if (i != 0)
    abort ();

#ifndef __FAST_MATH__
  /* Test all comparisons */
  a = (v2sf) {qnan, qnan};
  b = (v2sf) {-33, -11};
  c = (v2sf) {qnan, qnan};
  d = (v2sf) {-55, -88};

  i = test0 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test1 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test2 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test3 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test4 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test5 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test6 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test7 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test8 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test9 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test10 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test11 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test12 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test13 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test14 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test15 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test16 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test17 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test18 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test19 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test20 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test21 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test22 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test23 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test24 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test25 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test26 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test27 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test28 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test29 (a, b, c, d);
  if (i != 0)
    abort ();
  i = test30 (a, b, c, d);
  if (i != 1)
    abort ();
  i = test31 (a, b, c, d);
  if (i != 1)
    abort ();
#endif

  printf ("Test Passes\n");
  exit (0);
}
示例#3
0
文件: zmalloc.c 项目: plding/redis
static void zmalloc_oom(size_t size) {
    fprintf(stderr, "zmalloc: Out of memory trying to allocate %zu bytes\n",
        size);
    fflush(stderr);
    abort();
}
示例#4
0
static int
ffs_balloc_ufs1(struct inode *ip, off_t offset, int bufsize, struct buf **bpp)
{
	daddr_t lbn, lastlbn;
	int size;
	int32_t nb;
	struct buf *bp, *nbp;
	struct fs *fs = ip->i_fs;
	struct indir indirs[NIADDR + 2];
	daddr_t newb, pref;
	int32_t *bap;
	int osize, nsize, num, i, error;
	int32_t *allocblk, allociblk[NIADDR + 1];
	int32_t *allocib;
	const int needswap = UFS_FSNEEDSWAP(fs);

	lbn = lblkno(fs, offset);
	size = blkoff(fs, offset) + bufsize;
	if (bpp != NULL) {
		*bpp = NULL;
	}

	assert(size <= fs->fs_bsize);
	if (lbn < 0)
		return (EFBIG);

	/*
	 * If the next write will extend the file into a new block,
	 * and the file is currently composed of a fragment
	 * this fragment has to be extended to be a full block.
	 */

	lastlbn = lblkno(fs, ip->i_ffs1_size);
	if (lastlbn < NDADDR && lastlbn < lbn) {
		nb = lastlbn;
		osize = blksize(fs, ip, nb);
		if (osize < fs->fs_bsize && osize > 0) {
			warnx("need to ffs_realloccg; not supported!");
			abort();
		}
	}

	/*
	 * The first NDADDR blocks are direct blocks
	 */

	if (lbn < NDADDR) {
		nb = ufs_rw32(ip->i_ffs1_db[lbn], needswap);
		if (nb != 0 && ip->i_ffs1_size >= lblktosize(fs, lbn + 1)) {

			/*
			 * The block is an already-allocated direct block
			 * and the file already extends past this block,
			 * thus this must be a whole block.
			 * Just read the block (if requested).
			 */

			if (bpp != NULL) {
				error = bread(ip->i_fd, ip->i_fs, lbn,
				    fs->fs_bsize, bpp);
				if (error) {
					brelse(*bpp);
					return (error);
				}
			}
			return (0);
		}
		if (nb != 0) {

			/*
			 * Consider need to reallocate a fragment.
			 */

			osize = fragroundup(fs, blkoff(fs, ip->i_ffs1_size));
			nsize = fragroundup(fs, size);
			if (nsize <= osize) {

				/*
				 * The existing block is already
				 * at least as big as we want.
				 * Just read the block (if requested).
				 */

				if (bpp != NULL) {
					error = bread(ip->i_fd, ip->i_fs, lbn,
					    osize, bpp);
					if (error) {
						brelse(*bpp);
						return (error);
					}
				}
				return 0;
			} else {
				warnx("need to ffs_realloccg; not supported!");
				abort();
			}
		} else {

			/*
			 * the block was not previously allocated,
			 * allocate a new block or fragment.
			 */

			if (ip->i_ffs1_size < lblktosize(fs, lbn + 1))
				nsize = fragroundup(fs, size);
			else
				nsize = fs->fs_bsize;
			error = ffs_alloc(ip, lbn,
			    ffs_blkpref_ufs1(ip, lbn, (int)lbn,
				&ip->i_ffs1_db[0]),
				nsize, &newb);
			if (error)
				return (error);
			if (bpp != NULL) {
				bp = getblk(ip->i_fd, ip->i_fs, lbn, nsize);
				bp->b_blkno = fsbtodb(fs, newb);
				clrbuf(bp);
				*bpp = bp;
			}
		}
		ip->i_ffs1_db[lbn] = ufs_rw32((int32_t)newb, needswap);
		return (0);
	}

	/*
	 * Determine the number of levels of indirection.
	 */

	pref = 0;
	if ((error = ufs_getlbns(ip, lbn, indirs, &num)) != 0)
		return (error);

	if (num < 1) {
		warnx("ffs_balloc: ufs_getlbns returned indirect block");
		abort();
	}

	/*
	 * Fetch the first indirect block allocating if necessary.
	 */

	--num;
	nb = ufs_rw32(ip->i_ffs1_ib[indirs[0].in_off], needswap);
	allocib = NULL;
	allocblk = allociblk;
	if (nb == 0) {
		pref = ffs_blkpref_ufs1(ip, lbn, 0, (int32_t *)0);
		error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, &newb);
		if (error)
			return error;
		nb = newb;
		*allocblk++ = nb;
		bp = getblk(ip->i_fd, ip->i_fs, indirs[1].in_lbn, fs->fs_bsize);
		bp->b_blkno = fsbtodb(fs, nb);
		clrbuf(bp);
		/*
		 * Write synchronously so that indirect blocks
		 * never point at garbage.
		 */
		if ((error = bwrite(bp)) != 0)
			return error;
		allocib = &ip->i_ffs1_ib[indirs[0].in_off];
		*allocib = ufs_rw32((int32_t)nb, needswap);
	}

	/*
	 * Fetch through the indirect blocks, allocating as necessary.
	 */

	for (i = 1;;) {
		error = bread(ip->i_fd, ip->i_fs, indirs[i].in_lbn, 
		    fs->fs_bsize, &bp);
		if (error) {
			brelse(bp);
			return error;
		}
		bap = (int32_t *)bp->b_data;
		nb = ufs_rw32(bap[indirs[i].in_off], needswap);
		if (i == num)
			break;
		i++;
		if (nb != 0) {
			brelse(bp);
			continue;
		}
		if (pref == 0)
			pref = ffs_blkpref_ufs1(ip, lbn, 0, (int32_t *)0);
		error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, &newb);
		if (error) {
			brelse(bp);
			return error;
		}
		nb = newb;
		*allocblk++ = nb;
		nbp = getblk(ip->i_fd, ip->i_fs, indirs[i].in_lbn,
		    fs->fs_bsize);
		nbp->b_blkno = fsbtodb(fs, nb);
		clrbuf(nbp);
		/*
		 * Write synchronously so that indirect blocks
		 * never point at garbage.
		 */

		if ((error = bwrite(nbp)) != 0) {
			brelse(bp);
			return error;
		}
		bap[indirs[i - 1].in_off] = ufs_rw32(nb, needswap);

		bwrite(bp);
	}

	/*
	 * Get the data block, allocating if necessary.
	 */

	if (nb == 0) {
		pref = ffs_blkpref_ufs1(ip, lbn, indirs[num].in_off, &bap[0]);
		error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, &newb);
		if (error) {
			brelse(bp);
			return error;
		}
		nb = newb;
		*allocblk++ = nb;
		if (bpp != NULL) {
			nbp = getblk(ip->i_fd, ip->i_fs, lbn, fs->fs_bsize);
			nbp->b_blkno = fsbtodb(fs, nb);
			clrbuf(nbp);
			*bpp = nbp;
		}
		bap[indirs[num].in_off] = ufs_rw32(nb, needswap);

		/*
		 * If required, write synchronously, otherwise use
		 * delayed write.
		 */
		bwrite(bp);
		return (0);
	}
	brelse(bp);
	if (bpp != NULL) {
		error = bread(ip->i_fd, ip->i_fs, lbn, (int)fs->fs_bsize, &nbp);
		if (error) {
			brelse(nbp);
			return error;
		}
		*bpp = nbp;
	}
	return (0);
}
示例#5
0
文件: t-add.c 项目: clear731/lattice
int
main(void)
{
    int i;
    FLINT_TEST_INIT(state);
    

    flint_printf("add....");
    fflush(stdout);

    /* x = y + z */
    for (i = 0; i < 10000; i++)
    {
        fmpq_t x, y, z;
        mpq_t X, Y, Z;

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);
        mpq_init(X);
        mpq_init(Y);
        mpq_init(Z);

        fmpq_randtest(x, state, 200);
        fmpq_randtest(y, state, 200);
        fmpq_randtest(z, state, 200);

        fmpq_get_mpq(X, x);
        fmpq_get_mpq(Y, y);
        fmpq_get_mpq(Z, z);

        fmpq_add(x, y, z);

        if (!fmpq_is_canonical(x))
        {
            flint_printf("FAIL: result not canonical!\n");
            abort();
        }

        mpq_add(X, Y, Z);
        fmpq_get_mpq(Y, x);

        if (!mpq_equal(X, Y))
        {
            flint_printf("FAIL: fmpq_add(x,y,z) != mpq_add(X,Y,Z)\n");
            flint_printf("x = ");
            fmpq_print(x);
            flint_printf("\ny = ");
            fmpq_print(y);
            flint_printf("\nz = ");
            fmpq_print(z);
            flint_printf("\n");
            abort();
        }

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);

        mpq_clear(X);
        mpq_clear(Y);
        mpq_clear(Z);
    }

    /* x = x + y */
    for (i = 0; i < 10000; i++)
    {
        fmpq_t x, y;
        mpq_t X, Y;

        fmpq_init(x);
        fmpq_init(y);
        mpq_init(X);
        mpq_init(Y);

        fmpq_randtest(x, state, 200);
        fmpq_randtest(y, state, 200);

        fmpq_get_mpq(X, x);
        fmpq_get_mpq(Y, y);

        fmpq_add(x, x, y);

        if (!fmpq_is_canonical(x))
        {
            flint_printf("FAIL: result not canonical!\n");
            abort();
        }

        mpq_add(X, X, Y);
        fmpq_get_mpq(Y, x);

        if (!mpq_equal(X, Y))
        {
            flint_printf("FAIL: fmpq_add(x,x,y) != mpq_add(X,X,Y)\n");
            flint_printf("x = ");
            fmpq_print(x);
            flint_printf("\ny = ");
            fmpq_print(y);
            flint_printf("\n");
            abort();
        }

        fmpq_clear(x);
        fmpq_clear(y);

        mpq_clear(X);
        mpq_clear(Y);
    }

    /* x = y + x */
    for (i = 0; i < 10000; i++)
    {
        fmpq_t x, y;
        mpq_t X, Y;

        fmpq_init(x);
        fmpq_init(y);
        mpq_init(X);
        mpq_init(Y);

        fmpq_randtest(x, state, 200);
        fmpq_randtest(y, state, 200);

        fmpq_get_mpq(X, x);
        fmpq_get_mpq(Y, y);

        fmpq_add(x, y, x);

        if (!fmpq_is_canonical(x))
        {
            flint_printf("FAIL: result not canonical!\n");
            abort();
        }

        mpq_add(X, Y, X);
        fmpq_get_mpq(Y, x);

        if (!mpq_equal(X, Y))
        {
            flint_printf("FAIL: fmpq_add(x,y,x) != mpq_add(X,Y,X)\n");
            flint_printf("x = ");
            fmpq_print(x);
            flint_printf("\ny = ");
            fmpq_print(y);
            flint_printf("\n");
            abort();
        }

        fmpq_clear(x);
        fmpq_clear(y);

        mpq_clear(X);
        mpq_clear(Y);
    }

    

    FLINT_TEST_CLEANUP(state);
    flint_printf("PASS\n");
    return 0;
}
示例#6
0
文件: t_lookup.c 项目: Danfx/opensips
/* Determine current transaction
 *
 *                   Found      Not Found     Error (e.g. parsing)
 *  Return Value     1          0             -1
 *  T                ptr        0             T_UNDEFINED
 */
int t_check( struct sip_msg* p_msg , int *param_branch )
{
	int local_branch;

	/* is T still up-to-date ? */
	LM_DBG("start=%p\n", T);
	if ( T==T_UNDEFINED )
	{
		/* transaction lookup */
		if ( p_msg->first_line.type==SIP_REQUEST ) {
			/* force parsing all the needed headers*/
			if (parse_headers(p_msg, HDR_EOH_F, 0 )==-1) {
				LM_ERR("parsing error\n");
				return -1;
			}
			/* in case, we act as UAS for INVITE and reply with 200,
			 * we will need to run dialog-matching for subsequent
			 * ACK, for which we need From-tag; We also need from-tag
			 * in case people want to have proxied e2e ACKs accounted
			 */
			if (p_msg->REQ_METHOD==METHOD_INVITE
							&& parse_from_header(p_msg)<0) {
				LM_ERR("from parsing failed\n");
				return -1;
			}
			t_lookup_request( p_msg , 0 /* unlock before returning */ );
		} else {
			/* we need Via for branch and Cseq method to distinguish
			   replies with the same branch/cseqNr (CANCEL)
			*/
			if ( parse_headers(p_msg, HDR_VIA1_F|HDR_CSEQ_F, 0 )==-1
			|| !p_msg->via1 || !p_msg->cseq ) {
				LM_ERR("reply cannot be parsed\n");
				return -1;
			}

			/* if that is an INVITE, we will also need to-tag
			   for later ACK matching */
			if ( get_cseq(p_msg)->method_id==METHOD_INVITE ) {
					if (parse_headers(p_msg, HDR_TO_F, 0)==-1 || !p_msg->to)  {
						LM_ERR("INVITE reply cannot be parsed\n");
						return -1;
					}
			}

			t_reply_matching( p_msg ,
				param_branch!=0?param_branch:&local_branch );

		}
#ifdef EXTRA_DEBUG
		if ( T && T!=T_UNDEFINED && T->damocles) {
			LM_ERR("transaction %p scheduled for deletion "
				"and called from t_check\n", T);
			abort();
		}
#endif
		LM_DBG("end=%p\n",T);
	} else {
		if (T)
			LM_DBG("transaction already found!\n");
		else
			LM_DBG("transaction previously sought and not found\n");
	}

	return T ? (T==T_UNDEFINED ? -1 : 1 ) : 0;
}
示例#7
0
int
op_begemot(struct snmp_context *ctx, struct snmp_value *value,
    u_int sub, u_int iidx __unused, enum snmp_op op)
{

	switch (op) {

	  case SNMP_OP_GET:
		switch (value->var.subs[sub - 1]) {

		  case LEAF_begemotHrStorageUpdate:
			value->v.uint32 = storage_tbl_refresh;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrFSUpdate:
			value->v.uint32 = fs_tbl_refresh;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrDiskStorageUpdate:
			value->v.uint32 = disk_storage_tbl_refresh;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrNetworkUpdate:
			value->v.uint32 = network_tbl_refresh;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrSWInstalledUpdate:
			value->v.uint32 = swins_tbl_refresh;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrSWRunUpdate:
			value->v.uint32 = swrun_tbl_refresh;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrPkgDir:
			return (string_get(value, pkg_dir, -1));
		}
		abort();

	  case SNMP_OP_GETNEXT:
		abort();

	  case SNMP_OP_SET:
		switch (value->var.subs[sub - 1]) {

		  case LEAF_begemotHrStorageUpdate:
			ctx->scratch->int1 = storage_tbl_refresh;
			storage_tbl_refresh = value->v.uint32;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrFSUpdate:
			ctx->scratch->int1 = fs_tbl_refresh;
			fs_tbl_refresh = value->v.uint32;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrDiskStorageUpdate:
			ctx->scratch->int1 = disk_storage_tbl_refresh;
			disk_storage_tbl_refresh = value->v.uint32;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrNetworkUpdate:
			ctx->scratch->int1 = network_tbl_refresh;
			network_tbl_refresh = value->v.uint32;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrSWInstalledUpdate:
			ctx->scratch->int1 = swins_tbl_refresh;
			swins_tbl_refresh = value->v.uint32;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrSWRunUpdate:
			ctx->scratch->int1 = swrun_tbl_refresh;
			swrun_tbl_refresh = value->v.uint32;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrPkgDir:
			return (string_save(value, ctx, -1, &pkg_dir));
		}
		abort();

	  case SNMP_OP_COMMIT:
		switch (value->var.subs[sub - 1]) {

		  case LEAF_begemotHrStorageUpdate:
		  case LEAF_begemotHrFSUpdate:
		  case LEAF_begemotHrDiskStorageUpdate:
		  case LEAF_begemotHrNetworkUpdate:
		  case LEAF_begemotHrSWInstalledUpdate:
		  case LEAF_begemotHrSWRunUpdate:
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrPkgDir:
			string_commit(ctx);
			return (SNMP_ERR_NOERROR);
		}
		abort();

	  case SNMP_OP_ROLLBACK:
		switch (value->var.subs[sub - 1]) {

		  case LEAF_begemotHrStorageUpdate:
			storage_tbl_refresh = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrFSUpdate:
			fs_tbl_refresh = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrDiskStorageUpdate:
			disk_storage_tbl_refresh = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrNetworkUpdate:
			network_tbl_refresh = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrSWInstalledUpdate:
			swins_tbl_refresh = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrSWRunUpdate:
			swrun_tbl_refresh = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotHrPkgDir:
			string_rollback(ctx, &pkg_dir);
			return (SNMP_ERR_NOERROR);
		}
		abort();
	}

	abort();
}
示例#8
0
int main() {
  if (f() == 10)
    /*__builtin_*/abort();
  return 0;
}
示例#9
0
int
main(void)
{
    int i;
    FLINT_TEST_INIT(state);
    

    flint_printf("solve_dixon....");
    fflush(stdout);

    /* Solve nonsingular systems */
    for (i = 0; i < 100 * flint_test_multiplier(); i++)
    {
        fmpq_mat_t A, B, X, AX;
        fmpq_t d;
        int success;
        slong n, m, bits;

        n = n_randint(state, 10);
        m = n_randint(state, 10);
        bits = 1 + n_randint(state, 100);

        fmpq_mat_init(A, n, n);
        fmpq_mat_init(B, n, m);
        fmpq_mat_init(X, n, m);
        fmpq_mat_init(AX, n, m);

        fmpq_init(d);
        /* XXX: replace with a randtest function */
        do {
            fmpq_mat_randtest(A, state, bits);
            fmpq_mat_det(d, A);
        } while (fmpq_is_zero(d));
        fmpq_clear(d);

        fmpq_mat_randtest(B, state, bits);

        success = fmpq_mat_solve_dixon(X, A, B);
        fmpq_mat_mul(AX, A, X);

        if (!fmpq_mat_equal(AX, B) || !success)
        {
            flint_printf("FAIL!\n");
            flint_printf("success: %d\n", success);
            flint_printf("A:\n");
            fmpq_mat_print(A);
            flint_printf("B:\n");
            fmpq_mat_print(B);
            flint_printf("X:\n");
            fmpq_mat_print(X);
            flint_printf("AX:\n");
            fmpq_mat_print(AX);
            abort();
        }

        fmpq_mat_clear(A);
        fmpq_mat_clear(B);
        fmpq_mat_clear(X);
        fmpq_mat_clear(AX);
    }

    /* Check singular systems */
    for (i = 0; i < 100 * flint_test_multiplier(); i++)
    {
        fmpq_mat_t A, B, X;
        fmpz_mat_t M;
        fmpz_t den;
        slong n, m, bits;
        int success;

        n = 1 + n_randint(state, 10);
        m = 1 + n_randint(state, 10);
        bits = 1 + n_randint(state, 100);

        fmpz_init(den);
        fmpz_mat_init(M, n, n);
        fmpz_mat_randrank(M, state, n_randint(state, n), bits);
        if (i % 2)
            fmpz_mat_randops(M, state, n_randint(state, 2*m*n + 1));
        fmpz_randtest_not_zero(den, state, bits);
        fmpq_mat_init(A, n, n);
        fmpq_mat_set_fmpz_mat_div_fmpz(A, M, den);

        fmpq_mat_init(B, n, m);
        fmpq_mat_randtest(B, state, bits);
        fmpq_mat_init(X, n, m);

        success = fmpq_mat_solve_dixon(X, A, B);

        if (success != 0)
        {
            flint_printf("FAIL!\n");
            flint_printf("Expected success = 0\n");
            fmpq_mat_print(A);
            flint_printf("\n");
            abort();
        }

        fmpq_mat_clear(A);
        fmpq_mat_clear(B);
        fmpq_mat_clear(X);
        fmpz_mat_clear(M);
        fmpz_clear(den);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
// wahbm compressed in place
//{{{ uint32_t wah_compressed_in_place_or(uint32_t *r_wah,
uint32_t wah_compressed_in_place_or(uint32_t *r_wah,
                                    uint32_t r_wah_size,
                                    uint32_t *wah,
                                    uint32_t wah_size)
{
    uint32_t wah_i, wah_v, wah_fill_size, wah_fill_value,
             r_wah_i, r_wah_v, r_wah_fill_size, r_wah_fill_value,
             end, num_words;

    r_wah_i = 0;


    for (wah_i = 0; wah_i < wah_size; ++wah_i)
    {
        wah_v = wah[wah_i];
        r_wah_v = r_wah[r_wah_i];

        if (wah_v == 0x80000000)
            abort();
        if (r_wah_v == 0x80000000)
            abort();

        if (wah_v >= 0x80000000) { // wah_v is a fill

            wah_fill_value = (wah_v >> 30) & 1;
            wah_fill_size = (wah_v & 0x3fffffff);

            while (wah_fill_size > 0) {

                if (r_wah_v >= 0x80000000) { // r_wah is a fill

                    /*
                    fprintf(stderr, "%u:%s\t%u:%s\n",
                            wah_i,int_to_binary(wah_v),
                            r_wah_i,int_to_binary(r_wah_v));
                    */

                    r_wah_fill_value = (r_wah_v >> 30) & 1;
                    r_wah_fill_size = (r_wah_v & 0x3fffffff);

                    // make a new fill based on the smaller one
                    num_words = MIN(wah_fill_size, r_wah_fill_size);

                    if (num_words > 1) {
                        r_wah[r_wah_i] = (1 << 31) +
                                         ((r_wah_fill_value |
                                           wah_fill_value) << 30) +
                                         num_words;
                    } else {
                        if ((r_wah_fill_value | wah_fill_value) == 1)
                            r_wah[r_wah_i] = 0x7fffffff;
                        else
                            r_wah[r_wah_i] = 0;
                    }

                    r_wah_fill_size -= num_words;
                    wah_fill_size -= num_words;

                    // save any values left on the end of r_wah run
                    if (r_wah_fill_size > 0) {
                        if (r_wah_fill_size == 1) {
                            // we no longer have a fill, write a literal
                            if (r_wah_fill_value == 1) { //all ones
                                r_wah[r_wah_i + num_words] = 0x7fffffff;
                                //fprintf(stderr,"2\n");
                            } else {  // all zeros
                                r_wah[r_wah_i + num_words] = 0;
                                //fprintf(stderr,"3\n");
                            }
                        } else {
                            // we still have a fill, write it
                            r_wah[r_wah_i + num_words] =
                                (1 << 31) +
                                (r_wah_fill_value << 30) +
                                r_wah_fill_size;
                            //fprintf(stderr,"4\n");
                        }
                    }

                    r_wah_i += num_words;
                } else { // r_wah is a literal
                    if (wah_fill_value == 1)
                        r_wah[r_wah_i] = 0x7fffffff;
                    r_wah_i += 1;
                    wah_fill_size -= 1;
                }

                if (r_wah_i < r_wah_size)
                    r_wah_v = r_wah[r_wah_i];

                if (r_wah_v == 0x80000000)
                    abort();
            }
示例#11
0
int
main(int argc, char* argv[])
{
  const char *pacfile = NULL, *host = NULL, *url = NULL, *urlsfile = NULL,
             *client_ip = NULL, *dns_servers = NULL, *dns_domains = NULL;
  int dns_resolver_variant = DNS_GETADDRINFO;

  int enable_microsoft_extensions = 1;

  if (argv[1] && (STREQ(argv[1], "--help") || STREQ(argv[1], "--helpshort"))) {
    usage(argv[0]);
  }

  signed char c;
  while ((c = getopt(argc, argv, "eEvp:u:h:f:c:s:d:r:")) != -1)
    switch (c)
    {
      case 'v':
        printf("%s\n", pacparser_version());
        return 0;
      case 'p':
        pacfile = optarg;
        break;
      case 'u':
        url = optarg;
        break;
      case 'h':
        host = optarg;
        break;
      case 'f':
        urlsfile = optarg;
        break;
      case 'c':
        client_ip = optarg;
        break;
      case 's':
        dns_servers = optarg;
        break;
      case 'd':
        dns_domains = optarg;
        break;
      case 'r':
        if (!strcmp(optarg, "none"))
        {
            dns_resolver_variant = DNS_NONE;
        }
        else if (!strcmp(optarg, "getaddrinfo"))
        {
            dns_resolver_variant = DNS_GETADDRINFO;
        }
        else if (!strcmp(optarg, "c-ares"))
        {
            dns_resolver_variant = DNS_C_ARES;
        }
        else
        {
            usage(argv[0]);
            abort();
        }
        break;
     case 'e':
        enable_microsoft_extensions = 1;
        break;
     case 'E':
        enable_microsoft_extensions = 0;
        break;
      case '?':
        usage(argv[0]);
        /* fallthrough */
      default:
        abort();
    }

  if (!pacfile) {
    fprintf(stderr, __FILE__": You didn't specify the PAC file\n");
    usage(argv[0]);
  }
  if (!url && !urlsfile) {
    fprintf(stderr, __FILE__": You didn't specify a URL or URL-FILE\n");
    usage(argv[0]);
  }
  if (url && urlsfile) {
    fprintf(stderr, __FILE__": You can't specify both URL and URL-FILE\n");
    usage(argv[0]);
  }

  std::unique_ptr<PacParser> parser = PacParser::create(
    dns_servers, dns_domains, enable_microsoft_extensions);

  if (!parser->set_dns_resolver_variant(dns_resolver_variant))
    usage(argv[0]);

  // Read pacfile from stdin.
  if (STREQ("-", pacfile)) {
    char *script;
    size_t script_size = 1;  // for the null terminator
    char buffer[LINEMAX];

    script = (char*)calloc(1, sizeof(char));
    if (script == NULL) {
      perror(__FILE__": Failed to allocate the memory for the script");
      return 1;
    }

    while (fgets(buffer, sizeof(buffer), stdin)) {
      if (strlen(buffer) == 0)
        break;
      char *old = script;
      script_size += strlen(buffer);
      if (script_size > PACMAX) {
        fprintf(stderr, __FILE__": Input file is too big. "
                "Maximum allowed size in bytes is: %d\n", PACMAX);
        free(script);
        return 1;
      }
      script = (char*)realloc(script, script_size);
      if (script == NULL) {
        perror(__FILE__": Failed to allocate the memory for the script");
        free(old);
        return 1;
      }
      strncat(script, buffer, strlen(buffer));
    }

    if (ferror(stdin)) {
      free(script);
      perror(__FILE__": Error reading from stdin");
      return 1;
    }

    if (!parser->parse_pac_string(script)) {
      fprintf(stderr, __FILE__": Could not parse the pac script '%s'\n",
              script);
      free(script);
      return 1;
    }
    free(script);
  }
  else {
    if (!parser->parse_pac_file(pacfile)) {
      fprintf(stderr, __FILE__": Could not parse the pac file: %s\n",
              pacfile);
      return 1;
    }
  }

  if (client_ip)
    parser->setmyip(client_ip);

  char *h;
  std::string proxy;
  int rc = 0;

  if (url) {
    if (host) {
      parser->find_proxy(url, host, proxy);
    } else {
      // If the host was not explicitly given, get it from the URL.
      // If that fails, return with error (the get_host_from_url()
      // function will print a proper error message in that case).
      if ((h = get_host_from_url(url)) == NULL) {
        return 1;
      }
      parser->find_proxy(url, h, proxy);
      free(h);
    }
    if (!proxy.length()) {
      fprintf(stderr, __FILE__": Problem in finding proxy for %s\n", url);
      return 1;
    }
    printf("%s\n", proxy.c_str());
  }

  else if (urlsfile) {
    char line[LINEMAX];
    FILE *fp;
    if ((fp = fopen(urlsfile, "r")) == NULL) {
      fprintf(stderr, __FILE__": Could not open urlsfile '%s'\n", urlsfile);
      return 1;
    }
    while (fgets(line, sizeof(line), fp)) {
      char *url = line;
      // Remove spaces from the beginning.
      while (*url == ' ' || *url == '\t')
        url++;
      // Skip comment lines.
      if (*url == '#') {
        printf("%s", url);
        continue;
      }
      char *urlend = url;
      while (*urlend != '\r' && *urlend != '\n' && *urlend != '\0' &&
             *urlend != ' ' && *urlend != '\t')
        urlend++;  // keep moving till you hit space or end of string
      *urlend = '\0';
      if ((h = get_host_from_url(url)) == NULL) {
        rc = 1;  // will exit with error
        continue;
      }
      parser->find_proxy(url, h, proxy);
      free(h);
      if (!proxy.length()) {
        fprintf(stderr, __FILE__": Problem in finding proxy for %s\n", url);
        rc = 1; // will exit with error
        continue;
      }
      printf("%s : %s\n", url, proxy.c_str());
    }
    fclose(fp);
  }

  return rc;
}
示例#12
0
文件: memcp.c 项目: brodock/AntiSpam
void options_parse(int argc, char *argv[])
{
  int option_index= 0;
  int option_rv;

  memcached_programs_help_st help_options[]=
  {
    {0},
  };

  static struct option long_options[]=
    {
      {"version", no_argument, NULL, OPT_VERSION},
      {"help", no_argument, NULL, OPT_HELP},
      {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
      {"debug", no_argument, &opt_verbose, OPT_DEBUG},
      {"servers", required_argument, NULL, OPT_SERVERS},
      {"flag", required_argument, NULL, OPT_FLAG},
      {"expire", required_argument, NULL, OPT_EXPIRE},
      {"set",  no_argument, NULL, OPT_SET},
      {"add",  no_argument, NULL, OPT_ADD},
      {"replace",  no_argument, NULL, OPT_REPLACE},
      {"hash", required_argument, NULL, OPT_HASH},
      {"binary", no_argument, NULL, OPT_BINARY},
      {0, 0, 0, 0},
    };

  while (1) 
  {
    option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);

    if (option_rv == -1) break;

    switch (option_rv)
    {
    case 0:
      break;
    case OPT_BINARY:
      opt_binary = 1;
      break;
    case OPT_VERBOSE: /* --verbose or -v */
      opt_verbose = OPT_VERBOSE;
      break;
    case OPT_DEBUG: /* --debug or -d */
      opt_verbose = OPT_DEBUG;
      break;
    case OPT_VERSION: /* --version or -V */
      version_command(PROGRAM_NAME);
      break;
    case OPT_HELP: /* --help or -h */
      help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION, long_options, help_options);
      break;
    case OPT_SERVERS: /* --servers or -s */
      opt_servers= strdup(optarg);
      break;
    case OPT_FLAG: /* --flag */
      opt_flags= (uint32_t)strtol(optarg, (char **)NULL, 16);
      break;
    case OPT_EXPIRE: /* --expire */
      opt_expires= (time_t)strtoll(optarg, (char **)NULL, 10);
      break;
    case OPT_SET:
      opt_method= OPT_SET;
      break;
    case OPT_REPLACE:
      opt_method= OPT_REPLACE;
      break;
    case OPT_ADD:
      opt_method= OPT_ADD;
    case OPT_HASH:
      opt_hash= strdup(optarg);
      break;
    case '?':
      /* getopt_long already printed an error message. */
      exit(1);
    default:
      abort();
    }
  }
}
示例#13
0
文件: vm.cpp 项目: deiv/rubinius-pkg
 void VM::print_backtrace() {
   abort();
 }
示例#14
0
void HIDDEN
xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
{
	xbps_array_t mdeps;

	mdeps = xbps_dictionary_get(xhp->transd, "missing_deps");

	for (unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
		xbps_array_t pkgrdeps;
		xbps_object_t obj;
		const char *pkgver, *tract;
		char *pkgname;

		obj = xbps_array_get(pkgs, i);
		/*
		 * if pkg in transaction is not installed,
		 * pass to next one.
		 */
		xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
		xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);

		pkgname = xbps_pkg_name(pkgver);
		assert(pkgname);
		if (xbps_pkg_is_installed(xhp, pkgname) == 0) {
			free(pkgname);
			continue;
		}
		/*
		 * If pkg is installed but does not have revdeps,
		 * pass to next one.
		 */
		pkgrdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
		if (!xbps_array_count(pkgrdeps)) {
			free(pkgname);
			continue;
		}
		free(pkgname);
		/*
		 * Time to validate revdeps for current pkg.
		 */
		for (unsigned int x = 0; x < xbps_array_count(pkgrdeps); x++) {
			xbps_array_t rundeps;
			xbps_dictionary_t revpkgd;
			const char *curpkgver, *revpkgver, *curdep, *curtract;
			char *curpkgname, *curdepname;
			bool found = false;

			xbps_array_get_cstring_nocopy(pkgrdeps, x, &curpkgver);
			pkgname = xbps_pkg_name(curpkgver);
			assert(pkgname);
			if ((revpkgd = xbps_find_pkg_in_array(pkgs, pkgname, NULL))) {
				xbps_dictionary_get_cstring_nocopy(revpkgd, "transaction", &curtract);
				if (strcmp(curtract, "remove") == 0)
					revpkgd = NULL;
			}
			if (revpkgd == NULL)
				revpkgd = xbps_pkgdb_get_pkg(xhp, curpkgver);

			xbps_dictionary_get_cstring_nocopy(revpkgd, "pkgver", &revpkgver);
			/*
			 * If target pkg is being removed, all its revdeps
			 * will be broken unless those revdeps are also in
			 * the transaction.
			 */
			if (strcmp(tract, "remove") == 0) {
				if (xbps_dictionary_get(obj, "replaced")) {
					free(pkgname);
					continue;
				}
				if (xbps_find_pkg_in_array(pkgs, pkgname, "remove")) {
					free(pkgname);
					continue;
				}
				free(pkgname);
				broken_pkg(mdeps, curpkgver, pkgver, tract);
				continue;
			}
			/*
			 * First try to match any supported virtual package.
			 */
			if (check_virtual_pkgs(mdeps, obj, revpkgd)) {
				free(pkgname);
				continue;
			}
			/*
			 * Try to match real dependencies.
			 */
			rundeps = xbps_dictionary_get(revpkgd, "run_depends");
			/*
			 * Find out what dependency is it.
			 */
			curpkgname = xbps_pkg_name(pkgver);
			assert(curpkgname);

			for (unsigned int j = 0; j < xbps_array_count(rundeps); j++) {
				xbps_array_get_cstring_nocopy(rundeps, j, &curdep);
				if (((curdepname = xbps_pkg_name(curdep)) == NULL) &&
				    ((curdepname = xbps_pkgpattern_name(curdep)) == NULL))
					abort();

				if (strcmp(curdepname, curpkgname) == 0) {
					free(curdepname);
					found = true;
					break;
				}
				free(curdepname);
			}
			free(curpkgname);

			if (!found) {
				free(pkgname);
				continue;
			}
			if (xbps_match_pkgdep_in_array(rundeps, pkgver)) {
				free(pkgname);
				continue;
			}
			/*
			 * Installed package conflicts with package
			 * in transaction being updated, check
			 * if a new version of this conflicting package
			 * is in the transaction.
			 */
			if (xbps_find_pkg_in_array(pkgs, pkgname, "update")) {
				free(pkgname);
				continue;
			}
			free(pkgname);
			broken_pkg(mdeps, curpkgver, pkgver, tract);
		}

	}
}
示例#15
0
int process_cmd_line(int argc, char *argv[]) {
    int c;

    while (1) {
        /* getopt_long stores the option index here. */
        int option_index = 0;

        c = getopt_long(argc, argv, "", long_options, &option_index);

        /* Detect the end of the options. */
        if (c == -1) break;
        switch (c) {
            case 0: {
                /* If this option set a flag, do nothing else now. */
                if (long_options[option_index].flag != 0) break;
                printf ("option %s", long_options[option_index].name);
                if (optarg)
                    printf (" with arg %s", optarg);
                printf ("\n");
            }
            break;

            case 'd': {
                int i;

                if (device_flag > 0) {
                    printf("Error: multiply --device option\n");
                    exit(-1);
                }
                access.device_name = optarg;
                for (i = 0; optarg[i] != '\0'; i++)
                    access.device_name[i] = toupper(access.device_name[i]);

                device_flag++;
            }
            break;

            case 'i': {
                if (instance_flag > 0) {
                    printf("Error: multiply --instance option\n");
                    exit(-1);
                }
                instance = strtol(optarg, NULL, 10);
                instance_flag++;
            }
            break;

            case 't': {
                if (delay_flag > 0) {
                    printf("Error: multiply --delay option\n");
                    exit(-1);
                }
                delay = strtol(optarg, NULL, 10);
                delay_flag++;
            }
            break;

            case '?':
                /* getopt_long already printed an error message. */
                return -1;
                break;

            default:
                abort();
        }
    }

    return 0;
}
示例#16
0
void st_abort(const std::string& reason, const std::string& details)
{
  fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
  st_shutdown();
  abort();
}
示例#17
0
static struct throbber *
make_throbber (struct state *st, Drawable d, int w, int h, unsigned long pixel)
{
  XGCValues gcv;
  unsigned long flags;
  struct throbber *t = (struct throbber *) malloc (sizeof (*t));
  t->x = w / 2;
  t->y = h / 2;
  t->max_size = (w > h ? w : h);
  //t->speed = get_integer_resource (st->dpy, "speed", "Speed");
  t->speed = speed;
  t->fuse = 1 + (random() % 4);
  //t->thickness = get_integer_resource (st->dpy, "thickness", "Thickness");
  t->thickness = thickness;

  if (t->speed < 0) t->speed = -t->speed;
  t->speed += (((random() % t->speed) / 2) - (t->speed / 2));
  if (t->speed > 0) t->speed = -t->speed;

  flags = GCForeground;
# ifndef HAVE_COCOA
  if (st->transparent_p)
    {
      gcv.foreground = ~0L;
      gcv.plane_mask = st->base_pixel | st->plane_masks[random() % st->nplanes];
      flags |= GCPlaneMask;
    }
  else
# endif /* !HAVE_COCOA */
    {
      gcv.foreground = pixel;
    }

  gcv.line_width = t->thickness;
  gcv.cap_style = CapProjecting;
  gcv.join_style = JoinMiter;

  flags |= (GCLineWidth | GCCapStyle | GCJoinStyle);
  t->gc = XCreateGC (st->dpy, d, flags, &gcv);

# ifdef HAVE_COCOA
  if (st->transparent_p)
    {
      /* give a non-opaque alpha to the color */
      unsigned long pixel = gcv.foreground;
      unsigned long amask = BlackPixelOfScreen (st->xgwa.screen);
      unsigned long a = (0xCCCCCCCC & amask);
      pixel = (pixel & (~amask)) | a;

      jwxyz_XSetAlphaAllowed (st->dpy, t->gc, True);
      XSetForeground (st->dpy, t->gc, pixel);
    }
# endif /* HAVE_COCOA */

  switch (random() % 11) {
  case 0: case 1: case 2: case 3: t->draw = draw_star; break;
  case 4: case 5: case 6: case 7: t->draw = draw_circle; break;
  case 8: t->draw = draw_hlines; break;
  case 9: t->draw = draw_vlines; break;
  case 10: t->draw = draw_corners; break;
  default: abort(); break;
  }

  if (t->draw == draw_circle) 
    t->max_size *= 1.5;

  if (random() % 4)
    t->size = t->max_size;
  else
    t->size = t->thickness, t->speed = -t->speed;

  return t;
}
// PLFrameWalker API
const char *Apigee_plframe_get_regname (Apigee_plframe_regnum_t regnum) {
    switch (regnum) {
        case Apigee_PLFRAME_PPC_SRR0:
            return "srr0";
        case Apigee_PLFRAME_PPC_SRR1:
            return "srr1";
            
        case Apigee_PLFRAME_PPC_DAR:
            return "dar";
        case Apigee_PLFRAME_PPC_DSISR:
            return "dsisr";

        case Apigee_PLFRAME_PPC_R0:
            return "r0";
        case Apigee_PLFRAME_PPC_R1:
            return "r1";
        case Apigee_PLFRAME_PPC_R2:
            return "r2";
        case Apigee_PLFRAME_PPC_R3:
            return "r3";
        case Apigee_PLFRAME_PPC_R4:
            return "r4";
        case Apigee_PLFRAME_PPC_R5:
            return "r5";
        case Apigee_PLFRAME_PPC_R6:
            return "r6";
        case Apigee_PLFRAME_PPC_R7:
            return "r7";
        case Apigee_PLFRAME_PPC_R8:
            return "r8";
        case Apigee_PLFRAME_PPC_R9:
            return "r9";
        case Apigee_PLFRAME_PPC_R10:
            return "r10";
        case Apigee_PLFRAME_PPC_R11:
            return "r11";
        case Apigee_PLFRAME_PPC_R12:
            return "r12";
        case Apigee_PLFRAME_PPC_R13:
            return "r13";
        case Apigee_PLFRAME_PPC_R14:
            return "r14";
        case Apigee_PLFRAME_PPC_R15:
            return "r15";
        case Apigee_PLFRAME_PPC_R16:
            return "r16";
        case Apigee_PLFRAME_PPC_R17:
            return "r17";
        case Apigee_PLFRAME_PPC_R18:
            return "r18";
        case Apigee_PLFRAME_PPC_R19:
            return "r19";
        case Apigee_PLFRAME_PPC_R20:
            return "r20";
        case Apigee_PLFRAME_PPC_R21:
            return "r21";
        case Apigee_PLFRAME_PPC_R22:
            return "r22";
        case Apigee_PLFRAME_PPC_R23:
            return "r23";
        case Apigee_PLFRAME_PPC_R24:
            return "r24";
        case Apigee_PLFRAME_PPC_R25:
            return "r25";
        case Apigee_PLFRAME_PPC_R26:
            return "r26";
        case Apigee_PLFRAME_PPC_R27:
            return "r27";
        case Apigee_PLFRAME_PPC_R28:
            return "r28";
        case Apigee_PLFRAME_PPC_R29:
            return "r29";
        case Apigee_PLFRAME_PPC_R30:
            return "r30";
        case Apigee_PLFRAME_PPC_R31:
            return "r31";
            
        case Apigee_PLFRAME_PPC_CR:
            return "cr";
            
        case Apigee_PLFRAME_PPC_XER:
            return "xer";
            
        case Apigee_PLFRAME_PPC_LR:
            return "lr";
            
        case Apigee_PLFRAME_PPC_CTR:
            return "ctr";
            
        case Apigee_PLFRAME_PPC_VRSAVE:
            return "vrsave";

        default:
            // Unsupported register
            break;
    }
    
    /* Unsupported register is an implementation error (checked in unit tests) */
    Apigee_PLCF_DEBUG("Missing register name for register id: %d", regnum);
    abort();
}
示例#19
0
int
main(void)
{
    int i, result;
    ulong cflags = UWORD(0);

    FLINT_TEST_INIT(state);

    flint_printf("scalar_div_fmpz....");
    fflush(stdout);

    /* Check aliasing of a and b */
    for (i = 0; i < 1000 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t a, b;
        fmpz_t n;

        fmpz_init(n);
        fmpz_randtest_not_zero(n, state, 200);

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_randtest(a, state, n_randint(state, 100), 200);

        fmpq_poly_scalar_div_fmpz(b, a, n);
        fmpq_poly_scalar_div_fmpz(a, a, n);

        cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
        result = (fmpq_poly_equal(a, b) && !cflags);
        if (!result)
        {
            flint_printf("FAIL (aliasing):\n");
            fmpq_poly_debug(a), flint_printf("\n\n");
            fmpq_poly_debug(b), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            fmpz_print(n);
            abort();
        }

        fmpz_clear(n);
        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
    }

    /* Compare with fmpq_poly_scalar_mul_si */
    for (i = 0; i < 1000 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t a, b, c;
        fmpz_t n1;
        slong n;

        n = z_randtest_not_zero(state);
        fmpz_init(n1);
        fmpz_set_si(n1, n);

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(c);
        fmpq_poly_randtest(a, state, n_randint(state, 100), 200);

        fmpq_poly_scalar_div_fmpz(b, a, n1);
        fmpq_poly_scalar_div_si(c, a, n);

        cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
        result = (fmpq_poly_equal(b, c) && !cflags);
        if (!result)
        {
            flint_printf("FAIL (comparison with _si):\n");
            fmpq_poly_debug(a), flint_printf("\n\n");
            fmpz_print(n1), flint_printf("\n\n");
            fmpq_poly_debug(b), flint_printf("\n\n");
            fmpq_poly_debug(c), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            abort();
        }

        fmpz_clear(n1);
        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(c);
    }

    /* Check that (a / n1) / n2 == a / (n1 * n2) */
    for (i = 0; i < 1000 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t a, lhs, rhs;
        fmpz_t n1, n2, n;

        fmpz_init(n1);
        fmpz_init(n2);
        fmpz_init(n);

        fmpz_randtest_not_zero(n1, state, 100);
        fmpz_randtest_not_zero(n2, state, 100);
        fmpz_mul(n, n1, n2);

        fmpq_poly_init(a);
        fmpq_poly_init(lhs);
        fmpq_poly_init(rhs);
        fmpq_poly_randtest(a, state, n_randint(state, 100), 200);

        fmpq_poly_scalar_div_fmpz(lhs, a, n1);
        fmpq_poly_scalar_div_fmpz(lhs, lhs, n2);
        fmpq_poly_scalar_div_fmpz(rhs, a, n);

        cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
        result = (fmpq_poly_equal(lhs, rhs) && !cflags);
        if (!result)
        {
            flint_printf("FAIL (a / n1 / n2):\n");
            fmpq_poly_debug(a), flint_printf("\n\n");
            fmpz_print(n1), flint_printf("\n\n");
            fmpz_print(n2), flint_printf("\n\n");
            fmpz_print(n), flint_printf("\n\n");
            fmpq_poly_debug(lhs), flint_printf("\n\n");
            fmpq_poly_debug(rhs), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            abort();
        }

        fmpz_clear(n1);
        fmpz_clear(n2);
        fmpz_clear(n);
        fmpq_poly_clear(a);
        fmpq_poly_clear(lhs);
        fmpq_poly_clear(rhs);
    }

    /* Check that (a + b) / n == a/n + b/n */
    for (i = 0; i < 1000 * flint_test_multiplier(); i++)
    {
        fmpq_poly_t a, b, lhs, rhs;
        fmpz_t n;

        fmpz_init(n);

        fmpz_randtest_not_zero(n, state, 100);

        fmpq_poly_init(a);
        fmpq_poly_init(b);
        fmpq_poly_init(lhs);
        fmpq_poly_init(rhs);
        fmpq_poly_randtest(a, state, n_randint(state, 100), 200);
        fmpq_poly_randtest(b, state, n_randint(state, 100), 200);

        fmpq_poly_scalar_div_fmpz(lhs, a, n);
        fmpq_poly_scalar_div_fmpz(rhs, b, n);
        fmpq_poly_add(rhs, lhs, rhs);
        fmpq_poly_add(lhs, a, b);
        fmpq_poly_scalar_div_fmpz(lhs, lhs, n);

        cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
        cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
        result = (fmpq_poly_equal(lhs, rhs) && !cflags);
        if (!result)
        {
            flint_printf("FAIL ((a + b) / n):\n");
            fmpq_poly_debug(a), flint_printf("\n\n");
            fmpq_poly_debug(b), flint_printf("\n\n");
            fmpz_print(n), flint_printf("\n\n");
            fmpq_poly_debug(lhs), flint_printf("\n\n");
            fmpq_poly_debug(rhs), flint_printf("\n\n");
            flint_printf("cflags = %wu\n\n", cflags);
            abort();
        }

        fmpz_clear(n);
        fmpq_poly_clear(a);
        fmpq_poly_clear(b);
        fmpq_poly_clear(lhs);
        fmpq_poly_clear(rhs);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
示例#20
0
GUIEngine::GUIEngine(	irr::IrrlichtDevice* dev,
						gui::IGUIElement* parent,
						IMenuManager *menumgr,
						scene::ISceneManager* smgr,
						MainMenuData* data,
						bool& kill) :
	m_device(dev),
	m_parent(parent),
	m_menumanager(menumgr),
	m_smgr(smgr),
	m_data(data),
	m_texture_source(NULL),
	m_sound_manager(NULL),
	m_formspecgui(0),
	m_buttonhandler(0),
	m_menu(0),
	m_kill(kill),
	m_startgame(false),
	m_script(0),
	m_scriptdir(""),
	m_irr_toplefttext(0),
	m_clouds_enabled(true),
	m_cloud()
{
	//initialize texture pointers
	for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
		m_textures[i].texture = NULL;
	}
	// is deleted by guiformspec!
	m_buttonhandler = new TextDestGuiEngine(this);

	//create texture source
	m_texture_source = new MenuTextureSource(m_device->getVideoDriver());

	//create soundmanager
	MenuMusicFetcher soundfetcher;
#if USE_SOUND
	m_sound_manager = createOpenALSoundManager(&soundfetcher);
#endif
	if(!m_sound_manager)
		m_sound_manager = &dummySoundManager;

	//create topleft header
	std::wstring t = utf8_to_wide(std::string(PROJECT_NAME_C " ") +
			g_version_hash);

	core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(t), g_fontengine->getTextHeight());
	rect += v2s32(4, 0);

	m_irr_toplefttext =
		m_device->getGUIEnvironment()->addStaticText(t.c_str(),
		rect,false,true,0,-1);

	//create formspecsource
	m_formspecgui = new FormspecFormSource("");

	/* Create menu */
	m_menu = new GUIFormSpecMenu(m_device,
			m_parent,
			-1,
			m_menumanager,
			NULL /* &client */,
			NULL /* gamedef */,
			m_texture_source,
			m_formspecgui,
			m_buttonhandler,
			NULL,
			false);

	m_menu->allowClose(false);
	m_menu->lockSize(true,v2u32(800,600));

	// Initialize scripting

	infostream << "GUIEngine: Initializing Lua" << std::endl;

	m_script = new MainMenuScripting(this);

	try {
		if (m_data->errormessage != "") {
			m_script->setMainMenuErrorMessage(m_data->errormessage);
			m_data->errormessage = "";
		}

		if (!loadMainMenuScript()) {
			errorstream << "No future without mainmenu" << std::endl;
			abort();
		}

		run();
	}
	catch(LuaError &e) {
		errorstream << "MAINMENU ERROR: " << e.what() << std::endl;
		m_data->errormessage = e.what();
	}

	m_menu->quitMenu();
	m_menu->drop();
	m_menu = NULL;
}
示例#21
0
static void
make_gasket (logo_configuration *dc, int wire)
{
  int i;
  int points_size;
  int npoints = 0;
  int nctrls = 0;
  int res = 360/8;
  GLfloat d2r = M_PI / 180;

  GLfloat thick2 = (dc->gasket_thickness / dc->gasket_size) / 2;

  GLfloat *pointsx0, *pointsy0, *pointsx1, *pointsy1, *normals;

  GLfloat r0  = 0.780;  /* 395 */
  GLfloat r1a = 0.855;                /* top of wall below upper left hole */
  GLfloat r1b = 0.890;                /* center of upper left hole */
  GLfloat r1c = 0.922;                /* bottom of wall above hole */
  GLfloat r1  = 0.928;  /* 471 */
  GLfloat r2  = 0.966;  /* 490 */
  GLfloat r3  = 0.984;  /* 499 */
  GLfloat r4  = 1.000;  /* 507 */
  GLfloat r5  = 1.090;  /* 553 */

  GLfloat ctrl_r[100], ctrl_th[100];

  glPushMatrix();

# define POINT(r,th) \
    ctrl_r [nctrls] = r, \
    ctrl_th[nctrls] = (th * d2r), \
    nctrls++

  POINT (0.829, 0);      /* top indentation, right half */
  POINT (0.831, 0.85);
  POINT (0.835, 1.81);
  POINT (0.841, 2.65);
  POINT (0.851, 3.30);
  POINT (0.862, 3.81);
  POINT (0.872, 3.95);

  POINT (r4,    4.0);   /* moving clockwise... */
  POINT (r4,   48.2);
  POINT (r1,   48.2);
  POINT (r1,   54.2);
  POINT (r2,   55.8);
  POINT (r2,   73.2);
  POINT (r1,   74.8);
  POINT (r1,  101.2);
  POINT (r3,  103.4);
  POINT (r3,  132.0);
  POINT (r1,  133.4);

  POINT (r1,  180.7);
  POINT (r2,  183.6);
  POINT (r2,  209.8);
  POINT (r1,  211.0);
  POINT (r1,  221.8);
  POINT (r5,  221.8);
  POINT (r5,  223.2);
  POINT (r4,  223.2);

  POINT (r4,  316.8);      /* upper left indentation */
  POINT (0.990, 326.87);
  POINT (0.880, 327.21);
  POINT (0.872, 327.45);
  POINT (0.869, 327.80);
  POINT (0.867, 328.10);

  POINT (0.867, 328.85);
  POINT (0.869, 329.15);
  POINT (0.872, 329.50);
  POINT (0.880, 329.74);
  POINT (0.990, 330.08);

  POINT (r4,  339.0);
  if (! wire)
    {
      POINT (r1a, 339.0);      /* cut-out disc */
      POINT (r1a, 343.0);
    }
  POINT (r4,  343.0);
  POINT (r4,  356.0);

  POINT (0.872, 356.05);   /* top indentation, left half */
  POINT (0.862, 356.19);
  POINT (0.851, 356.70);
  POINT (0.841, 357.35);
  POINT (0.835, 358.19);
  POINT (0.831, 359.15);
  POINT (0.829, 360);
# undef POINT

  points_size = res + (nctrls * 2);
  pointsx0 = (GLfloat *) malloc (points_size * sizeof(GLfloat));
  pointsy0 = (GLfloat *) malloc (points_size * sizeof(GLfloat));
  pointsx1 = (GLfloat *) malloc (points_size * sizeof(GLfloat));
  pointsy1 = (GLfloat *) malloc (points_size * sizeof(GLfloat));
  normals  = (GLfloat *) malloc (points_size * sizeof(GLfloat) * 2);

  npoints = 0;
  for (i = 1; i < nctrls; i++)
    {
      GLfloat from_r  = ctrl_r [i-1];
      GLfloat from_th = ctrl_th[i-1];
      GLfloat to_r    = ctrl_r [i];
      GLfloat to_th   = ctrl_th[i];

      GLfloat step = 2*M_PI / res;
      int nsteps = 1 + ((to_th - from_th) / step);
      int j;

      for (j = 0; j < nsteps + (i == nctrls-1); j++)
        {
          GLfloat r  = from_r  + (j * (to_r  - from_r)  / nsteps);
          GLfloat th = from_th + (j * (to_th - from_th) / nsteps);

          GLfloat cth = cos(th) * dc->gasket_size;
          GLfloat sth = sin(th) * dc->gasket_size;

          pointsx0[npoints] = r0 * cth;  /* inner ring */
          pointsy0[npoints] = r0 * sth;
          pointsx1[npoints] = r  * cth;  /* outer ring */
          pointsy1[npoints] = r  * sth;
          npoints++;

          if (npoints >= points_size) abort();
        }
    }

  /* normals for the outer ring */
  for (i = 1; i < npoints; i++)
    {
      XYZ a, b, c, n;
      a.x = pointsx1[i-1];
      a.y = pointsy1[i-1];
      a.z = 0;
      b.x = pointsx1[i];
      b.y = pointsy1[i];
      b.z = 0;
      c = b;
      c.z = 1;
      n = calc_normal (a, b, c);
      normals[(i-1)*2  ] = n.x;
      normals[(i-1)*2+1] = n.y;
    }

  glRotatef(-90, 0, 1, 0);
  glRotatef(180, 0, 0, 1);

  if (wire)
    {
      GLfloat z;
      for (z = -thick2; z <= thick2; z += thick2*2)
        {
# if 1
          /* inside edge */
          glBegin (GL_LINE_LOOP);
          for (i = 0; i < npoints; i++)
            glVertex3f (pointsx0[i], pointsy0[i], z);
          glEnd();

          /* outside edge */
          glBegin (GL_LINE_LOOP);
          for (i = 0; i < npoints; i++)
            glVertex3f (pointsx1[i], pointsy1[i], z);
          glEnd();
# else
          for (i = 1; i < npoints; i++)
            {
              glBegin (GL_LINE_STRIP);
              glVertex3f (pointsx0[i-1], pointsy0[i-1], z);
              glVertex3f (pointsx0[i  ], pointsy0[i  ], z);
              glVertex3f (pointsx1[i  ], pointsy1[i  ], z);
              glVertex3f (pointsx1[i-1], pointsy1[i-1], z);
              glEnd();
            }
# endif
        }
#if 1
      glBegin (GL_LINES);
      for (i = 0; i < npoints; i++)
        {
          /* inside rim */
          glVertex3f (pointsx0[i], pointsy0[i], -thick2);
          glVertex3f (pointsx0[i], pointsy0[i],  thick2);
          /* outside rim */
          glVertex3f (pointsx1[i], pointsy1[i], -thick2);
          glVertex3f (pointsx1[i], pointsy1[i],  thick2);
        }
      glEnd();
#endif
    }
  else
    {
      /* top */
      glFrontFace(GL_CW);
      glNormal3f(0, 0, -1);
      glBegin (GL_QUAD_STRIP);
      for (i = 0; i < npoints; i++)
        {
          glVertex3f (pointsx0[i], pointsy0[i], -thick2);
          glVertex3f (pointsx1[i], pointsy1[i], -thick2);
        }
      glEnd();

      /* bottom */
      glFrontFace(GL_CCW);
      glNormal3f(0, 0, 1);
      glBegin (GL_QUAD_STRIP);
      for (i = 0; i < npoints; i++)
        {
          glVertex3f (pointsx0[i], pointsy0[i], thick2);
          glVertex3f (pointsx1[i], pointsy1[i], thick2);
        }
      glEnd();

      /* inside edge */
      glFrontFace(GL_CW);
      glBegin (GL_QUAD_STRIP);
      for (i = 0; i < npoints; i++)
        {
          glNormal3f (-pointsx0[i], -pointsy0[i],  0);
          glVertex3f ( pointsx0[i],  pointsy0[i],  thick2);
          glVertex3f ( pointsx0[i],  pointsy0[i], -thick2);
        }
      glEnd();

      /* outside edge */
      glFrontFace(GL_CCW);
      glBegin (GL_QUADS);
      {
        for (i = 0; i < npoints-1; i++)
          {
            int ia = (i == 0 ? npoints-2 : i-1);
            int iz = (i == npoints-2 ? 0 : i+1);
            GLfloat  x = pointsx1[i];
            GLfloat  y = pointsy1[i];
            GLfloat xz = pointsx1[iz];
            GLfloat yz = pointsy1[iz];

            GLfloat nxa = normals[ia*2];   /* normal of [i-1 - i] face */
            GLfloat nya = normals[ia*2+1];
            GLfloat nx  = normals[i*2];    /* normal of [i - i+1] face */
            GLfloat ny  = normals[i*2+1];
            GLfloat nxz = normals[iz*2];    /* normal of [i+1 - i+2] face */
            GLfloat nyz = normals[iz*2+1];

            GLfloat anglea = vector_angle (nx, ny, 0, nxa, nya, 0);
            GLfloat anglez = vector_angle (nx, ny, 0, nxz, nyz, 0);
            GLfloat pointy = 0.005;

            if (anglea > pointy)
              {
                glNormal3f (nx, ny, 0);
                glVertex3f (x,  y,   thick2);
                glVertex3f (x,  y,  -thick2);
              }
            else
              {
                glNormal3f ((nxa + nx) / 2, (nya + ny) / 2, 0);
                glVertex3f (x,  y,   thick2);
                glVertex3f (x,  y,  -thick2);
              }

            if (anglez > pointy)
              {
                glNormal3f (nx, ny, 0);
                glVertex3f (xz, yz, -thick2);
                glVertex3f (xz, yz,  thick2);
              }
            else
              {
                glNormal3f ((nx + nxz) / 2, (ny + nyz) / 2, 0);
                glVertex3f (xz, yz, -thick2);
                glVertex3f (xz, yz,  thick2);
              }
          }
      }
      glEnd();
    }

  /* Fill in the upper left hole...
   */
  {
    GLfloat th;
    npoints = 0;

    th = 339.0 * d2r;
    pointsx0[npoints] = r1c * cos(th) * dc->gasket_size;
    pointsy0[npoints] = r1c * sin(th) * dc->gasket_size;
    npoints++;
    pointsx0[npoints] = r4 * cos(th) * dc->gasket_size;
    pointsy0[npoints] = r4 * sin(th) * dc->gasket_size;
    npoints++;

    th = 343.0 * d2r;
    pointsx0[npoints] = r1c * cos(th) * dc->gasket_size;
    pointsy0[npoints] = r1c * sin(th) * dc->gasket_size;
    npoints++;
    pointsx0[npoints] = r4 * cos(th) * dc->gasket_size;
    pointsy0[npoints] = r4 * sin(th) * dc->gasket_size;
    npoints++;

    if (! wire)
      {
        /* front wall */
        glNormal3f (0, 0, -1);
        glFrontFace(GL_CW);
        glBegin (wire ? GL_LINE_LOOP : GL_QUADS);
        glVertex3f (pointsx0[0], pointsy0[0], -thick2);
        glVertex3f (pointsx0[1], pointsy0[1], -thick2);
        glVertex3f (pointsx0[3], pointsy0[3], -thick2);
        glVertex3f (pointsx0[2], pointsy0[2], -thick2);
        glEnd();

        /* back wall */
        glNormal3f (0, 0, 1);
        glFrontFace(GL_CCW);
        glBegin (wire ? GL_LINE_LOOP : GL_QUADS);
        glVertex3f (pointsx0[0], pointsy0[0],  thick2);
        glVertex3f (pointsx0[1], pointsy0[1],  thick2);
        glVertex3f (pointsx0[3], pointsy0[3],  thick2);
        glVertex3f (pointsx0[2], pointsy0[2],  thick2);
        glEnd();
      }

    /* top wall */
    glFrontFace(GL_CW);
    glBegin (wire ? GL_LINE_LOOP : GL_QUADS);
    glNormal3f (pointsx0[1], pointsy0[1], 0);
    glVertex3f (pointsx0[1], pointsy0[1],  thick2);
    glNormal3f (pointsx0[3], pointsy0[3], 0);
    glVertex3f (pointsx0[3], pointsy0[3],  thick2);
    glVertex3f (pointsx0[3], pointsy0[3], -thick2);
    glNormal3f (pointsx0[1], pointsy0[1], 0);
    glVertex3f (pointsx0[1], pointsy0[1], -thick2);
    glEnd();


    /* Now make a donut.
     */
    {
      int nsteps = 12;
      GLfloat r0 = 0.026;
      GLfloat r1 = 0.060;
      GLfloat th, cth, sth;

      glPushMatrix ();

      th = ((339.0 + 343.0) / 2) * d2r;
      
      glTranslatef (r1b * cos(th) * dc->gasket_size,
                    r1b * sin(th) * dc->gasket_size,
                    0);

      npoints = 0;
      for (i = 0; i < nsteps; i++)
        {
          th = 2 * M_PI * i / nsteps;
          cth = cos (th) * dc->gasket_size;
          sth = sin (th) * dc->gasket_size;
          pointsx0[npoints] = r0 * cth;
          pointsy0[npoints] = r0 * sth;
          pointsx1[npoints] = r1 * cth;
          pointsy1[npoints] = r1 * sth;
          npoints++;
        }

      pointsx0[npoints] = pointsx0[0];
      pointsy0[npoints] = pointsy0[0];
      pointsx1[npoints] = pointsx1[0];
      pointsy1[npoints] = pointsy1[0];
      npoints++;

      if (wire)
        {
          glBegin (GL_LINE_LOOP);
          for (i = 0; i < npoints; i++)
            glVertex3f (pointsx0[i], pointsy0[i], -thick2);
          glEnd();
          glBegin (GL_LINE_LOOP);
          for (i = 0; i < npoints; i++)
            glVertex3f (pointsx0[i], pointsy0[i],  thick2);
          glEnd();
# if 0
          glBegin (GL_LINE_LOOP);
          for (i = 0; i < npoints; i++)
            glVertex3f (pointsx1[i], pointsy1[i], -thick2);
          glEnd();
          glBegin (GL_LINE_LOOP);
          for (i = 0; i < npoints; i++)
            glVertex3f (pointsx1[i], pointsy1[i],  thick2);
          glEnd();
# endif
        }
      else
        {
          /* top */
          glFrontFace(GL_CW);
          glNormal3f(0, 0, -1);
          glBegin (GL_QUAD_STRIP);
          for (i = 0; i < npoints; i++)
            {
              glVertex3f (pointsx0[i], pointsy0[i], -thick2);
              glVertex3f (pointsx1[i], pointsy1[i], -thick2);
            }
          glEnd();

          /* bottom */
          glFrontFace(GL_CCW);
          glNormal3f(0, 0, 1);
          glBegin (GL_QUAD_STRIP);
          for (i = 0; i < npoints; i++)
            {
              glVertex3f (pointsx0[i], pointsy0[i],  thick2);
              glVertex3f (pointsx1[i], pointsy1[i],  thick2);
            }
          glEnd();
        }

      /* inside edge */
      glFrontFace(GL_CW);
      glBegin (wire ? GL_LINES : GL_QUAD_STRIP);
      for (i = 0; i < npoints; i++)
        {
          glNormal3f (-pointsx0[i], -pointsy0[i],  0);
          glVertex3f ( pointsx0[i],  pointsy0[i],  thick2);
          glVertex3f ( pointsx0[i],  pointsy0[i], -thick2);
        }
      glEnd();

      glPopMatrix();
    }
  }


  /* Attach the bottom-right dingus...
   */
  {
    GLfloat w = 0.04;
    GLfloat h = 0.17;
    GLfloat th;

    glRotatef (50, 0, 0, 1);
    glScalef (dc->gasket_size, dc->gasket_size, 1);
    glTranslatef (0, (r0+r1)/2, 0);

    /* buried box */
    if (! wire)
      {
        glFrontFace(GL_CCW);
        glBegin (wire ? GL_LINE_STRIP : GL_QUADS);
        glNormal3f (0, 0, -1);
        glVertex3f (-w/2, -h/2, -thick2); glVertex3f (-w/2,  h/2, -thick2);
        glVertex3f ( w/2,  h/2, -thick2); glVertex3f ( w/2, -h/2, -thick2);
        glNormal3f (1, 0, 0);
        glVertex3f ( w/2, -h/2, -thick2); glVertex3f ( w/2,  h/2, -thick2);
        glVertex3f ( w/2,  h/2,  thick2); glVertex3f ( w/2, -h/2,  thick2);
        glNormal3f (0, 0, 1);
        glVertex3f ( w/2, -h/2,  thick2); glVertex3f ( w/2,  h/2,  thick2);
        glVertex3f (-w/2,  h/2,  thick2); glVertex3f (-w/2, -h/2,  thick2);
        glNormal3f (-1, 0, 0);
        glVertex3f (-w/2, -h/2,  thick2); glVertex3f (-w/2,  h/2,  thick2);
        glVertex3f (-w/2,  h/2, -thick2); glVertex3f (-w/2, -h/2, -thick2);
        glEnd();
      }

    npoints = 0;
    for (th = 0; th < M_PI; th += (M_PI / 6))
      {
        pointsx0[npoints] = w/2 * cos(th);
        pointsy0[npoints] = w/2 * sin(th);
        npoints++;
      }

    /* front inside curve */
    glNormal3f (0, 0, -1);
    glFrontFace(GL_CW);
    glBegin (wire ? GL_LINE_STRIP : GL_TRIANGLE_FAN);
    if (! wire) glVertex3f (0, h/2, -thick2);
    for (i = 0; i < npoints; i++)
      glVertex3f (pointsx0[i], h/2 + pointsy0[i], -thick2);
    glEnd();

    /* front outside curve */
    glFrontFace(GL_CCW);
    glBegin (wire ? GL_LINE_STRIP : GL_TRIANGLE_FAN);
    if (! wire) glVertex3f (0, -h/2, -thick2);
    for (i = 0; i < npoints; i++)
      glVertex3f (pointsx0[i], -h/2 - pointsy0[i], -thick2);
    glEnd();

    /* back inside curve */
    glNormal3f (0, 0, 1);
    glFrontFace(GL_CCW);
    glBegin (wire ? GL_LINE_STRIP : GL_TRIANGLE_FAN);
    if (! wire) glVertex3f (0, h/2, thick2);
    for (i = 0; i < npoints; i++)
      glVertex3f (pointsx0[i], h/2 + pointsy0[i], thick2);
    glEnd();

    /* back outside curve */
    glFrontFace(GL_CW);
    glBegin (wire ? GL_LINE_STRIP : GL_TRIANGLE_FAN);
    if (! wire) glVertex3f (0, -h/2, thick2);
    for (i = 0; i < npoints; i++)
      glVertex3f (pointsx0[i], -h/2 - pointsy0[i], thick2);
    glEnd();

    /* inside curve */
    glFrontFace(GL_CCW);
    glBegin (wire ? GL_LINES : GL_QUAD_STRIP);
    for (i = 0; i < npoints; i++)
      {
        glNormal3f (pointsx0[i], pointsy0[i], 0);
        glVertex3f (pointsx0[i], h/2 + pointsy0[i],  thick2);
        glVertex3f (pointsx0[i], h/2 + pointsy0[i], -thick2);
      }
    glEnd();

    /* outside curve */
    glFrontFace(GL_CW);
    glBegin (wire ? GL_LINES : GL_QUAD_STRIP);
    for (i = 0; i < npoints; i++)
      {
        glNormal3f (pointsx0[i], -pointsy0[i], 0);
        glVertex3f (pointsx0[i], -h/2 - pointsy0[i],  thick2);
        glVertex3f (pointsx0[i], -h/2 - pointsy0[i], -thick2);
      }
    glEnd();
  }

  free (pointsx0);
  free (pointsy0);
  free (pointsx1);
  free (pointsy1);
  free (normals);

  glPopMatrix();
}
示例#22
0
int main(int argc, char* argv[]) {
    int opt;
    auto pss_sort = [](const Vma& a, const Vma& b) {
        uint64_t pss_a = show_wss ? a.wss.pss : a.usage.pss;
        uint64_t pss_b = show_wss ? b.wss.pss : b.usage.pss;
        return pss_a > pss_b;
    };

    auto uss_sort = [](const Vma& a, const Vma& b) {
        uint64_t uss_a = show_wss ? a.wss.uss : a.usage.uss;
        uint64_t uss_b = show_wss ? b.wss.uss : b.usage.uss;
        return uss_a > uss_b;
    };

    std::function<bool(const Vma& a, const Vma& b)> sort_func = nullptr;
    while ((opt = getopt(argc, argv, "himpuWw")) != -1) {
        switch (opt) {
            case 'h':
                hide_zeroes = true;
                break;
            case 'i':
                // TODO: libmeminfo doesn't support the flag to chose
                // between idle page tracking vs clear_refs. So for now,
                // this flag is unused and the library defaults to using
                // /proc/<pid>/clear_refs for finding the working set.
                use_pageidle = true;
                break;
            case 'm':
                // this is the default
                break;
            case 'p':
                sort_func = pss_sort;
                break;
            case 'u':
                sort_func = uss_sort;
                break;
            case 'W':
                reset_wss = true;
                break;
            case 'w':
                show_wss = true;
                break;
            case '?':
                usage(argv[0]);
                return 0;
            default:
                abort();
        }
    }

    if (optind != (argc - 1)) {
        fprintf(stderr, "Need exactly one pid at the end\n");
        usage(argv[0]);
        exit(EXIT_FAILURE);
    }

    pid_t pid = atoi(argv[optind]);
    if (pid == 0) {
        std::cerr << "Invalid process id" << std::endl;
        exit(EXIT_FAILURE);
    }

    if (reset_wss) {
        if (!ProcMemInfo::ResetWorkingSet(pid)) {
            std::cerr << "Failed to reset working set of pid : " << pid << std::endl;
            exit(EXIT_FAILURE);
        }
        return 0;
    }

    ProcMemInfo proc(pid, show_wss);
    const MemUsage& proc_stats = show_wss ? proc.Wss() : proc.Usage();
    std::vector<Vma> maps(proc.Maps());
    if (sort_func != nullptr) {
        std::sort(maps.begin(), maps.end(), sort_func);
    }

    return show(proc_stats, maps);
}
示例#23
0
文件: isxdigit.c 项目: pekd/sulong
int main() {
  if (!isxdigit('a')) {
    abort();
  }
  if (!isxdigit('d')) {
    abort();
  }
  if (!isxdigit('f')) {
    abort();
  }
  if (isxdigit('z')) {
    abort();
  }
  if (!isxdigit('A')) {
    abort();
  }
  if (!isxdigit('D')) {
    abort();
  }
  if (!isxdigit('F')) {
    abort();
  }
  if (isxdigit('Z')) {
    abort();
  }
  if (isxdigit(' ')) {
    abort();
  }
  if (!isxdigit('0')) {
    abort();
  }
  if (!isxdigit('5')) {
    abort();
  }
  if (!isxdigit('9')) {
    abort();
  }
  if (isxdigit('!')) {
    abort();
  }
  if (isxdigit('@')) {
    abort();
  }
  if (isxdigit('[')) {
    abort();
  }
}
示例#24
0
/** \note  There should be no possibility of program-level errors in the
    application of the combinator functions, which simply rearrange nodes. */
static Object *
apply_combinator( Combinator *c, Array *spine, unsigned int nargs, Manager *m )
{
    if ( DEBUG__SAFE && ( !c || !spine || !m ) )
        abort();

/* TODO: how about a lookup table instead of a switch statement? */
    switch ( *c )
    {
        case B_combinator:

            return apply_B( spine, nargs, m );

        case C_combinator:

            return apply_C( spine, nargs, m );

        case I_combinator:

            return apply_I( spine, nargs );

        case K_combinator:

            return apply_K( spine, nargs );

        case L_combinator:

            return apply_L( spine, nargs, m );

        case O_combinator:

            return apply_O( spine, nargs, m );

        case R_combinator:

            return apply_R( spine, nargs, m );

        case S_combinator:

            return apply_S( spine, nargs, m );

        case T_combinator:

            return apply_T( spine, nargs );

        case U_combinator:

            return apply_U( spine, nargs, m );

        case V_combinator:

            return apply_V( spine, nargs, m );

        case W_combinator:

            return apply_W( spine, nargs, m );

        case w_combinator:

            return apply_w( spine, nargs );

        case Y_combinator:

            return apply_Y( spine, nargs, m );

        default:

            abort();
    }
}
示例#25
0
static int parse_params(int argc, char *argv[])
{
    int c;
    while ((c = getopt(argc, argv, "BUCo:w:d:v:V:p:")) != -1) {
        switch (c) {
            case 'U':
                do_unpack = 0;
                break;
            case 'B':
                do_build = 0;
                break;
            case 'C':
                do_gencontrol = 0;
                break;
            case 'o':
                out_dir = optarg;
                break;
            case 'w':
                if ((work_dir = realpath(optarg, NULL)) == NULL) {
                    fprintf(stderr, "realpath(%s) failed: %s\n", optarg,
                            strerror(errno));
                    return -1;
                }
                break;
            case 'd':
                if ((dist_dir = realpath(optarg, NULL)) == NULL) {
                    fprintf(stderr, "realpath(%s) failed: %s\n", optarg,
                            strerror(errno));
                    return -1;
                }
                break;
            case 'p':
                if ((pkg_dir = realpath(optarg, NULL)) == NULL) {
                    fprintf(stderr, "realpath(%s) failed: %s\n", optarg,
                            strerror(errno));
                    return -1;
                }
                break;
            case 'v':
                ver_mode = VERSION_OVERRIDE;
                ver_param = optarg;
                break;
            case 'V':
                ver_mode = VERSION_APPEND;
                ver_param = optarg;
                break;
            case '?':
                fprintf(stderr, "Unknown option: %c\n", optopt);
                return -1;

            default:
                fprintf(stderr, "Unexpected option: %c\n", c);
                abort();
        }
    }

    if (work_dir == NULL) {
        fprintf(stderr, "A working directory must be set\n");
        return -1;
    }

    if (optind + 1 != argc)
        return -1;

    if ((control_path = realpath(argv[optind], NULL)) == NULL) {
        fprintf(stderr, "realpath(%s) failed: %s\n", argv[optind],
                strerror(errno));
        return -1;
    }
    return 0;
}
示例#26
0
static Object *
apply_primitive( Primitive *p, Array *spine, unsigned int nargs, Manager *m )
{
    unsigned int i;
    Object *ap, *arg;
    void *args[PRIM__MAX_PARAMS];
    void *result;
    Type *t;

    if ( DEBUG__SAFE && ( !p || !spine || !m || p->arity > PRIM__MAX_PARAMS ) )
        abort();

    if ( PRIM__ALLOW_NULLARY )
    {
        /* Not supported. */
    }

    else
        /* Make the compiler happy. */
        ap = 0;

    /* Apply the primitive, provided that there are enough arguments, and that
       they reduce to objects of the expected types. */
    if ( nargs >= p->arity )
    {
        /* For each argument... */
        for ( i = 0; i < p->arity; i++ )
        {
            ap = array__pop( spine );
            arg = reduce__graph_lazy( OPERAND( ap ), spine, m );

            /* Argument reduced to a non-null object. */
            if ( arg )
            {
                t = p->parameters[i].type;

                /* Check for type agreement. */
                if ( PRIM__CHECKS__PARAM_TYPE )
                {
                    if ( t != arg->type
                    && ( !PRIM__ALLOW_GENERIC_PARAMS || t != BOXED_TYPE ) )
                    {
                        ERROR( "prim_reduce: argument type mismatch" );

                        goto bad_arg;
                    }
                }

                /* Argument type is boxed. */
                if ( PRIM__ALLOW_GENERIC_PARAMS && t == BOXED_TYPE )
                    args[i] = arg;

                /* Argument type is unboxed. */
                else
                    args[i] = arg->value;
            }

            /* Argument reduced to null. */
            else
                goto bad_arg;
        }

        /* Caution: there is no exception handling at this level. */
        result = p->cstub( args );

        /* Return value is an existing typed object. */
        if ( PRIM__ALLOW_GENERIC_RESULTS && p->return_type == BOXED_TYPE )
            substitute_boxed( ap, result );

        /* Return type is a raw data reference which needs to be bound to a type ("boxed"). */
        else
        {
            if ( result )
                substitute_unboxed( ap, p->return_type, result );

            else if ( FIRST_CLASS_NULL )
                substitute_boxed( ap, 0 );

            else
                abort();
        }

        return ap;
    }

    else
        return 0;

bad_arg:

/* FIXME: OBJECT__IRREDUCIBLE property is not used */
    if ( COMPILER__ALLOW_NONREDUX )
        ap->flags |= OBJECT__IRREDUCIBLE;

    /* f 0 --> 0 */
    substitute_boxed( ap, 0 );

    return ap;
}
示例#27
0
void
foo (struct S *x)
{
  if (x->a != C || x->b != D)
    abort ();
}
示例#28
0
文件: srvec.c 项目: NexMirror/MPICH
int main(int argc, char **argv)
{
    int size;
    int rank;
    int niter = 1;
    int msg_count = 0;
    int msg_blocklength = 1;
    int msg_stride = 1;
    int msg_sz;
    int * buf;
    int buf_sz;
    int iter;
    int i;
    MPI_Datatype dt;
    
    if (MPI_Init(&argc, &argv) != MPI_SUCCESS)
    {
        printf("ERROR: problem with MPI_Init\n"); fflush(stdout);
    }

    if (MPI_Comm_size(MPI_COMM_WORLD, &size) != MPI_SUCCESS)
    {
	printf("ERROR: problem with MPI_Comm_size\n"); fflush(stdout);
    }
    
    if (MPI_Comm_rank(MPI_COMM_WORLD, &rank) != MPI_SUCCESS)
    {
	printf("ERROR: problem with MPI_Comm_rank\n"); fflush(stdout);
    }

    printf("srvec: size %d rank %d\n", size, rank); fflush(stdout);
    
    if (size < 2)
    {
	if (rank == 0)
	{
	    printf("ERROR: needs to be run with at least 2 procs\n");
	    fflush(stdout);
	}
	goto main_exit;
    }

    if (argc > 1)
    {
	sscanf(argv[1], "%d", &niter);
    }

    if (argc > 2)
    {
	sscanf(argv[2], "%d", &msg_count);
    }
    
    if (argc > 3)
    {
	sscanf(argv[3], "%d", &msg_blocklength);
    }
    
    if (argc > 4)
    {
	sscanf(argv[4], "%d", &msg_stride);
    }

    if (msg_stride < msg_blocklength)
    {
	if (rank == 0)
	{
	    printf("ERROR: stride < blocklength\n");
	    fflush(stdout);
	}
	goto main_exit;
    }
    

    msg_sz = msg_count * msg_blocklength;
    buf_sz = msg_count * msg_stride;
    
    if (rank == 0)
    {
	printf("niter=%d, msg_count=%d, msg_blocklength=%d, msg_stride=%d\n",
	    niter, msg_count, msg_blocklength, msg_stride);
	printf("msg_sz=%d, buf_sz=%d\n", msg_sz, buf_sz);
	fflush(stdout);
    }

    if (buf_sz > 0)
    {
	buf = (int *) malloc(buf_sz * sizeof(int));
	/* printf("%d: buf=%p\n", rank, buf); fflush(stdout); */
    }
    else
    {
	buf = NULL;
    }

    MPI_Type_vector(msg_count, msg_blocklength, msg_stride, MPI_INT, &dt);
    MPI_Type_commit(&dt);

    if (rank == 0)
    {
	/* usleep(10000); */

	for (i = 0; i < buf_sz; i++)
	{
	    buf[i] = INT_MAX;
	}
	
	for (iter = 0; iter < niter; iter++)
	{
	    for (i = 0; i < buf_sz; i++)
	    {
		buf[i] = iter * buf_sz + i;
	    }
	    
	    if (MPI_Send(buf, 1, dt, 1, iter, MPI_COMM_WORLD) != MPI_SUCCESS)
	    {
		printf("ERROR: problem with MPI_Send\n"); fflush(stdout);
	    }
	}
	
    }
    else if (rank == 1)
    {
	MPI_Status status;
	    
	for (i = 0; i < buf_sz; i++)
	{
	    buf[i] = INT_MIN;
	}

	for (iter = 0; iter < niter; iter++)
	{
#	    if defined(TEST_RECV_VECTOR)
	    {
		if (MPI_Recv(buf, msg_sz, MPI_INT, 0, iter, MPI_COMM_WORLD,
		    &status) != MPI_SUCCESS)
		{
		    printf("ERROR: problem with MPI_Recv\n"); fflush(stdout);
		}
		
		for (i = 0; i < msg_sz; i++)
		{
		    const int expected = iter * buf_sz + i / msg_blocklength *
			msg_stride + i % msg_blocklength;
		    if (buf[i] != expected)
		    {
			printf("ERROR: %d != %d, i=%d iter=%d\n", buf[i],
			    expected, i, iter);
			fflush(stdout);
			abort();
		    }
		}
	    }
#	    else
	    {
		if (MPI_Recv(buf, 1, dt, 0, iter, MPI_COMM_WORLD, &status)
		    != MPI_SUCCESS)
		{
		    printf("ERROR: problem with MPI_Recv\n"); fflush(stdout);
		}
		
		for (i = 0; i < buf_sz; i++)
		{
		    if (i % msg_stride < msg_blocklength && buf[i] != iter *
			buf_sz + i)
		    {
			printf("ERROR: %d != %d, i=%d iter=%d\n", buf[i],
			    iter * buf_sz + i, i, iter);
			fflush(stdout);
			abort();
		    }
		}
	    }
#	    endif
	}
	
	printf("All messages successfully received!\n");
	fflush(stdout);
    }

  main_exit:
    MPI_Barrier(MPI_COMM_WORLD);
    printf("srvec: process %d finished\n", rank); fflush(stdout);
    
    if (MPI_Finalize() != MPI_SUCCESS)
    {
        printf("ERROR: problem with MPI_Finalize\n"); fflush(stdout);
    }

    return 0;
}
示例#29
0
void
gamma_rate_mixture_summarize(
        arb_ptr rate_mix_prior, arb_ptr rate_mix_rates, arb_ptr rate_mix_expect,
        const gamma_rate_mixture_t x, enum rate_mixture_mode mode, slong prec)
{
    slong i;
    arb_ptr r;

    arb_t p, q;
    arb_init(p);
    arb_init(q);
    arb_set_d(p, x->invariable_prior);
    arb_sub_si(q, p, 1, prec);
    arb_neg(q, q);

    /* the expectation is designed to be 1 */
    arb_one(rate_mix_expect);

    /* probabilities corresponding to gamma rate categories */
    for (i = 0; i < x->gamma_categories; i++)
    {
        r = rate_mix_prior + i;
        arb_div_si(r, q, x->gamma_categories, prec);
    }

    /* optional probability corresponding to the invariable category */
    if (x->invariable_prior)
    {
        r = rate_mix_prior + x->gamma_categories;
        arb_set(r, p);
    }

    /* set the discretized gamma rates */
    {
        arb_t s;
        arb_init(s);
        arb_set_d(s, x->gamma_shape);
        if (mode == RATE_MIXTURE_GAMMA)
        {
            gamma_rates(
                    rate_mix_rates, x->gamma_categories, s, prec);
        }
        else if (mode == RATE_MIXTURE_GAMMA_MEDIAN)
        {
            normalized_median_gamma_rates(
                    rate_mix_rates, x->gamma_categories, s, prec);
        }
        else
        {
            abort(); /* assert */
        }
        arb_clear(s);
    }

    /* normalize the rates to account for a possible invariable category */
    for (i = 0; i < x->gamma_categories; i++)
    {
        r = rate_mix_rates + i;
        arb_div(r, r, q, prec);
    }

    arb_clear(p);
    arb_clear(q);
}
示例#30
0
文件: run.c 项目: braydonf/lightning
int main(int argc, char *argv[])
{
	pid_t child;
	int infd, outfd, errfd, status;
	char buf[5] = "test";

	/* We call ourselves, to test pipe. */
	if (argc == 2) {
		if (strcmp(argv[1], "out") == 0) {
			if (write(STDOUT_FILENO, buf, sizeof(buf)) != sizeof(buf))
				exit(1);
		} else if (strcmp(argv[1], "in") == 0) {
			if (read(STDIN_FILENO, buf, sizeof(buf)) != sizeof(buf))
				exit(1);
			if (memcmp(buf, "test", sizeof(buf)) != 0)
				exit(1);
		} else if (strcmp(argv[1], "inout") == 0) {
			if (read(STDIN_FILENO, buf, sizeof(buf)) != sizeof(buf))
				exit(1);
			buf[0]++;
			if (write(STDOUT_FILENO, buf, sizeof(buf)) != sizeof(buf))
				exit(1);
		} else if (strcmp(argv[1], "err") == 0) {
			if (write(STDERR_FILENO, buf, sizeof(buf)) != sizeof(buf))
				exit(1);
		} else
			abort();
		exit(0);
	}

	/* We assume no fd leaks, so close them now. */
	close(3);
	close(4);
	close(5);
	close(6);
	close(7);
	close(8);
	close(9);
	close(10);
	
	/* This is how many tests you plan to run */
	plan_tests(67);
	child = pipecmd(&outfd, &infd, &errfd, argv[0], "inout", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(write(infd, buf, sizeof(buf)) == sizeof(buf));
	ok1(read(outfd, buf, sizeof(buf)) == sizeof(buf));
	ok1(read(errfd, buf, sizeof(buf)) == 0);
	ok1(close(infd) == 0);
	ok1(close(outfd) == 0);
	ok1(close(errfd) == 0);
	buf[0]--;
	ok1(memcmp(buf, "test", sizeof(buf)) == 0);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	child = pipecmd(NULL, &infd, NULL, argv[0], "in", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(write(infd, buf, sizeof(buf)) == sizeof(buf));
	ok1(close(infd) == 0);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	child = pipecmd(&outfd, NULL, NULL, argv[0], "out", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(read(outfd, buf, sizeof(buf)) == sizeof(buf));
	ok1(close(outfd) == 0);
	ok1(memcmp(buf, "test", sizeof(buf)) == 0);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	/* Errfd only should be fine. */
	child = pipecmd(NULL, NULL, &errfd, argv[0], "err", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(read(errfd, buf, sizeof(buf)) == sizeof(buf));
	ok1(close(errfd) == 0);
	ok1(memcmp(buf, "test", sizeof(buf)) == 0);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	/* errfd == outfd should work with both. */
	child = pipecmd(&errfd, NULL, &errfd, argv[0], "err", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(read(errfd, buf, sizeof(buf)) == sizeof(buf));
	ok1(close(errfd) == 0);
	ok1(memcmp(buf, "test", sizeof(buf)) == 0);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	child = pipecmd(&outfd, NULL, &outfd, argv[0], "out", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(read(outfd, buf, sizeof(buf)) == sizeof(buf));
	ok1(close(outfd) == 0);
	ok1(memcmp(buf, "test", sizeof(buf)) == 0);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	// Writing to /dev/null should be fine.
	child = pipecmd(NULL, NULL, NULL, argv[0], "out", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	// Reading should fail.
	child = pipecmd(NULL, NULL, NULL, argv[0], "in", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 1);

	child = pipecmd(NULL, NULL, NULL, argv[0], "err", NULL);
	if (!ok1(child > 0))
		exit(1);
	ok1(waitpid(child, &status, 0) == child);
	ok1(WIFEXITED(status));
	ok1(WEXITSTATUS(status) == 0);

	// Can't run non-existent file, but errno set correctly.
	child = pipecmd(NULL, NULL, NULL, "/doesnotexist", "in", NULL);
	ok1(errno == ENOENT);
	ok1(child < 0);

	/* No fd leaks! */
	ok1(close(3) == -1 && errno == EBADF);
	ok1(close(4) == -1 && errno == EBADF);
	ok1(close(5) == -1 && errno == EBADF);
	ok1(close(6) == -1 && errno == EBADF);
	ok1(close(7) == -1 && errno == EBADF);
	ok1(close(8) == -1 && errno == EBADF);
	ok1(close(9) == -1 && errno == EBADF);
	ok1(close(10) == -1 && errno == EBADF);

	/* This exits depending on whether all tests passed */
	return exit_status();
}