Example #1
0
CtCondition * CtCondition_New(void)
{
    CtCondition *thiz = NULL;
    
    do
    {
        CtRet ret = CT_RET_OK;

        thiz = (CtCondition *)ct_malloc(sizeof(CtCondition));
        if (thiz == NULL)
        {
            break;
        }

        ret = CtCondition_Construct(thiz);
        if (RET_FAILED(ret))
        {
            CtCondition_Delete(thiz);
            thiz = NULL;
            break;
        }
    }
    while (0);

    return thiz;
}
Example #2
0
uint32_t bco_sym(bcout_t *bco, const char *str, bool force_new) {
    constant_string_t *cs;
    size_t len;
    int found;

    if (!force_new) {
        found = bco_find_sym(bco, str);
        if (-1 < found) {
            return (found);
        }
    }

    len = strlen(str);

    /* round up to the multiple of 4 */
    len = (len + 3) & ~3;

    cs = (constant_string_t *) ct_malloc(bco, sizeof(constant_string_t) + len);
    cs->h.t = KEK_SYM;
    cs->length = len;
    strcpy(cs->string, str);

    bcout_items_add(bco, (constant_item_t *) cs);

    return ((uint8_t *) cs - bco->const_table);
}
Example #3
0
uint32_t bco_exinfo(bcout_t *bco, size_t try_block_cnt) {
    constant_exinfo_t *cei;

    cei = (constant_exinfo_t *) ct_malloc(bco, sizeof(constant_exinfo_t)
                                          + (try_block_cnt - 1) * sizeof(try_range_t));
    cei->h.t = KEK_EXINFO;
    cei->length = 0;

    return ((uint8_t *) cei - bco->const_table);
}
CtMoveGenerator
ct_move_generator_new(CtPosition position, CtMoveCommand pseudo_legal_move_command)
{
  CtMoveGenerator move_generator = ct_malloc(sizeof(CtMoveGeneratorStruct));

  move_generator->position = position;
  move_generator->pseudo_legal_move_command = pseudo_legal_move_command;
  move_generator->white_piece_mgs = ct_piece_mgs_new(position, pseudo_legal_move_command, WHITE_PIECE);
  move_generator->black_piece_mgs = ct_piece_mgs_new(position, pseudo_legal_move_command, BLACK_PIECE);
  return move_generator;
}
Example #5
0
static CtRet udp_join_multicast_group_with_all_ip(int fd, const char *group)
{
    IP_ADAPTER_INFO * pNextAdapter = NULL;
    IP_ADAPTER_INFO * ipAdaptersInfo = NULL;
    ULONG infolen = sizeof(IP_ADAPTER_INFO);

    ipAdaptersInfo = (IP_ADAPTER_INFO *)ct_malloc(infolen);

    if (GetAdaptersInfo(ipAdaptersInfo, &infolen) == ERROR_BUFFER_OVERFLOW)
    {
        ct_free(ipAdaptersInfo);
        ipAdaptersInfo = (IP_ADAPTER_INFO *)ct_malloc(infolen);
    }

    if (GetAdaptersInfo(ipAdaptersInfo, &infolen))
    {
        ct_free(ipAdaptersInfo);
        return CT_RET_E_INTERNAL;
    }

    for (pNextAdapter = ipAdaptersInfo; pNextAdapter; pNextAdapter = pNextAdapter->Next)
    {
        IP_ADDR_STRING *pNextIp = NULL;
        for (pNextIp = &(pNextAdapter->IpAddressList); pNextIp; pNextIp = pNextIp->Next)
        {
            unsigned long ip = inet_addr(pNextIp->IpAddress.String);
            if (ip == 0)
            {
                break;
            }

            LOG_D(TAG, "join MultiGroup ip: %s", pNextIp->IpAddress.String);

            udp_join_multicast_group_with_ip(fd, group, ip);
        }
    }

    ct_free(ipAdaptersInfo);

    return CT_RET_OK;
}
Example #6
0
uint32_t bco_arr(bcout_t *bco, size_t len) {
    constant_array_t *ca;

    // Size of the allocated memory is already a multiple of four in this case.
    ca = (constant_array_t *) ct_malloc(bco,
                                        sizeof(constant_array_t) + (len - 1) * sizeof(uint32_t));
    ca->h.t = KEK_ARR;
    ca->length = len;
    ca->alloc_size = 0; // This will be initialized at runtime

    return ((uint8_t *) ca - bco->const_table);
}
static CtPgnReader
ct_pgn_reader_new(CtGraph graph, CtGameTags game_tags, char *error_message)
{
  CtPgnReader pgn_reader;

  pgn_reader = ct_malloc(sizeof(CtPgnReaderStruct));
  pgn_reader->graph = graph;
  pgn_reader->game_tags = game_tags;
  pgn_reader->error_message = error_message;
  yylex_init_extra(pgn_reader, &pgn_reader->pgn_scanner);
  ct_pgn_reader_reset(pgn_reader);
  return pgn_reader;
}
static CtPieceMovers
ct_piece_mgs_new(CtPosition position, CtMoveCommand pseudo_legal_move_command, CtPieceColor piece_color)
{
  CtPieceMovers piece_mgs = ct_malloc(sizeof(CtPieceMoversStruct));

  piece_mgs->position = position;
  piece_mgs->pawn = ct_pawn_new(pseudo_legal_move_command, piece_color);
  piece_mgs->stepers[0] = ct_king_new(pseudo_legal_move_command, piece_color);
  piece_mgs->stepers[1] = ct_knight_new(pseudo_legal_move_command, piece_color);
  piece_mgs->sliders[0] = ct_queen_new(pseudo_legal_move_command, piece_color);
  piece_mgs->sliders[1] = ct_rook_new(pseudo_legal_move_command, piece_color);
  piece_mgs->sliders[2] = ct_bishop_new(pseudo_legal_move_command, piece_color);
  return piece_mgs;
}
Example #9
0
/* create an integer, save it into the constant table and create
 * a pointer in the items array
 * usage:
 *
 * int i;
 * i = bco_int(bco, 666);
 * constant_int_t *j = (constant_int_t *)(bco->const_table + i));
 *
 */
uint32_t bco_int(bcout_t *bco, int v) {
    constant_int_t *ci;
    int found;

    found = bco_find_int(bco, v);
    if (-1 < found) {
        return (found);
    }

    ci = (constant_int_t *) ct_malloc(bco, sizeof(constant_int_t));
    ci->h.t = KEK_INT;
    ci->value = v;

    bcout_items_add(bco, (constant_item_t *) ci);

    return ((uint8_t *) ci - bco->const_table);
}
Example #10
0
uint32_t bco_nil(bcout_t *bco) {
    constant_nil_t *cn;
    static int singleton = 0;
    static uint32_t ret;

    if (singleton) {
        return (ret);
    } else {
        cn = (constant_nil_t *) ct_malloc(bco, sizeof(constant_nil_t));
        cn->h.t = KEK_NIL;
        ret = ((uint8_t *) cn - bco->const_table);
        singleton = 1;
    }

    //bcout_items_add(bco, (constant_item_t *) cn);

    return (ret);
}