예제 #1
0
파일: mcs.c 프로젝트: mark-mb/abs-software
MCSPacket *mcs_create_packet(MCSCommand cmd, unsigned short nargs,
        unsigned char *args, unsigned short data_size, unsigned char *data)
{
    MCSPacket *pkt;

    pkt = abs_malloc0(sizeof(*pkt));
    pkt->type = (cmd & 0xF0000) >> 16;
    pkt->cmd = cmd & 0xFFFF;

    if (pkt->type == MCS_TYPE_PAYLOAD) {
        pkt->id = (unsigned char)(generate_id()) & 0x7F;
    } else {
        pkt->id = generate_id();
    }

    pkt->nargs = nargs;
    if(nargs != 0) {
        pkt->args = abs_malloccpy(args, nargs);
    }
    pkt->data_size = data_size;
    if(data_size != 0) {
        pkt->data = abs_malloccpy(data, data_size);
    }

    if(check_packet(pkt) >= 0) {
        return pkt;
    } else {
        return NULL;
    }
}
예제 #2
0
int freq_add(int cpu, int bus)
{
	int id;

	id = generate_id();

	if (freqs_cnt == 0) {
		freqs_cnt++;
		freqs = malloc(sizeof(freqs[0]));
		freqs[0].cpu = cpu;
		freqs[0].bus = bus;
		freqs[0].id = id;
	} else {
		freqs = safe_realloc(freqs, sizeof(freqs[0]) * (freqs_cnt + 1));

		if (freqs == NULL)
			return -1;

		freqs[freqs_cnt].cpu = cpu;
		freqs[freqs_cnt].bus = bus;
		freqs[freqs_cnt].id = id;
		freqs_cnt++;
	}

	return id;
}
예제 #3
0
void firmadat::commit(void) {
	BString sql;
	int ret;
//printf("commit\n");
	if (id>=0) {	// UPDATE
		sql = "UPDATE firma SET ";
		sql += "nazwa = %Q, symbol = %Q, adres = %Q, kod = %Q, miejscowosc = %Q, telefon = %Q, email = %Q";
		sql += ", nip = %Q, regon = %Q, bank = %Q, konto = %Q";
		sql += ", odbiorca = %i, dostawca = %i, aktywny = %i, zablokowany = %i";
		sql += " WHERE id = %i";
	} else {		// INSERT
		id = generate_id();
		sql += "INSERT INTO firma ( ";
		sql += "nazwa, symbol, adres, kod, miejscowosc, telefon, email";
		sql += ", nip, regon, bank, konto";
		sql += ", odbiorca, dostawca, aktywny, zablokowany";
		sql += ", id ) VALUES ( ";
		sql += "%Q, %Q, %Q, %Q, %Q, %Q, %Q";
		sql += ", %Q, %Q, %Q, %Q";
		sql += ", %i, %i, %i, %i";
		sql += ", %i)";
	}
//printf("sql:[%s]\n",sql.String());
	ret = sqlite_exec_printf(dbData, sql.String(), 0, 0, &dbErrMsg,
		data[0].String(), data[1].String(), data[2].String(), data[3].String(),
		data[4].String(), data[5].String(), data[6].String(), data[7].String(),
		data[8].String(), data[9].String(), data[10].String(),
		odbiorca, dostawca, aktywny, zablokowany,
		id);
//printf("result: %i, %s; id=%i\n", ret, dbErrMsg, id);
}
예제 #4
0
    std::string process_ids(id_state& state, std::string const& xml)
    {
        placeholder_index placeholders = index_placeholders(state, xml);

        typedef std::vector<id_placeholder*>::iterator iterator;

        iterator it = placeholders.begin(),
            end = placeholders.end();

        // Placeholder ids are processed in blocks of ids with
        // an equal number of dots.
        while (it != end) {
            unsigned num_dots = (*it)->num_dots;

            // ids can't clash with ids at a different num_dots, so
            // this only needs to track the id generation data
            // for a single num_dots at a time.
            allocated_ids ids;

            iterator it2 = it;
            do {
                resolve_id(**it2++, ids);
            } while(it2 != end && (*it2)->num_dots == num_dots);

            do {
                generate_id(**it++, ids);
            } while(it != it2);
        }

        return replace_ids(state, xml);
    }
static void
gibber_file_transfer_set_property (GObject *object,
                                   guint property_id,
                                   const GValue *value,
                                   GParamSpec *pspec)
{
  GibberFileTransfer *self = GIBBER_FILE_TRANSFER (object);

  switch (property_id)
    {
      case PROP_ID:
        self->id = g_value_dup_string (value);
        if (self->id == NULL)
          self->id = generate_id ();
        break;
      case PROP_SELF_ID:
        self->self_id = g_value_dup_string (value);
        if (self->self_id == NULL)
          g_critical ("'self-id' cannot be NULL");
        break;
      case PROP_PEER_ID:
        self->peer_id = g_value_dup_string (value);
        if (self->peer_id == NULL)
          g_critical ("'peer-id' cannot be NULL");
        break;
      case PROP_FILENAME:
        self->filename = g_value_dup_string (value);
        break;
      case PROP_DIRECTION:
        self->direction = g_value_get_uint (value);
        break;
      case PROP_PORTER:
        {
          self->priv->porter = g_value_dup_object (value);

          self->priv->stanza_id =
            wocky_porter_register_handler_from_anyone (self->priv->porter,
                WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_NONE,
                WOCKY_PORTER_HANDLER_PRIORITY_NORMAL, received_stanza_cb,
                self, NULL);
        }
        break;
      case PROP_CONTACT:
        self->priv->contact = g_value_dup_object (value);
        break;
      case PROP_DESCRIPTION:
        self->description = g_value_dup_string (value);
        break;
      case PROP_CONTENT_TYPE:
        self->content_type = g_value_dup_string (value);
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}
예제 #6
0
파일: todo.c 프로젝트: peterhgombos/todo
void add_todo(char string[])
{
    char* id = generate_id();

	FILE *fp;
	fp = open_list("ar");
	fprintf(fp, "%s\t%s\n", id, string);
	fclose(fp);


	printf("Added task with id %s%s%s:\t%s\n",colors[COLOR_GREEN], id, colors[COLOR_RESET], string);
    free(id);
}
예제 #7
0
void
database_1(char *host, char *action, char *message)
{
    CLIENT *clnt;
    rpc_args  *result_1;
    //struct rpc_args  action_1_arg;
    
    clnt = clnt_create (host, DATABASE, ASSIGNMENT_7, "udp");
    if (clnt == NULL) {
        clnt_pcreateerror (host);
        exit (1);
    }
    //rpc arguments struct to pass to server
    struct rpc_args *args = malloc(sizeof(struct rpc_args));
    
    char *id = generate_id();
    strcpy(args->id, id);
    strcpy(args->action, "PUT"); 
    int n = 0;
    while(n != 5){
        char pureMessage[80];
        pureMessage[79] = '\0';
        FILE *file = popen("fortune","r");
        if (file == NULL) {
            perror("errorpopen");
        }
        if(fread(pureMessage, 79, 1, file) == 0) {
            if(feof(file) == 0) {
                perror("errorfread");
            }
        }
        strcpy(args->message, pureMessage);
        put(args,clnt);
        sleep(1);
        n += 1;
    }
    
    sleep(5); //wait for 5 seconds
    
    strcpy(args->action, "GET");
    int q = 0;
    while(q != 10){
        get(args,clnt);
        sleep(1);
        q += 1;
    }
    free(args);
    #ifndef    DEBUG
    clnt_destroy (clnt);
    #endif     /* DEBUG */
}
예제 #8
0
파일: node.c 프로젝트: abed-hawa/amara
static PyObject *get_id(PyObject *obj, void *arg)
{
  PyObject *buffer, *item, *result=NULL;
  Py_ssize_t i, n, size;
  char *p;

  buffer = PyList_New(0);
  if (buffer == NULL)
    return NULL;
  if (generate_id(Node(obj), buffer) < 0)
    goto finally;

  n = PyList_GET_SIZE(buffer);
  if (n == 1) {
    result = PyList_GET_ITEM(buffer, 0);
    Py_INCREF(result);
  } else {
    for (size = 0, i = 0; i < n; i++) {
      item = PyList_GET_ITEM(buffer, i);
      if (!PyString_Check(item)) {
        PyErr_Format(PyExc_TypeError,
                     "sequence item %zd: expected string, %s found",
                     i, item->ob_type->tp_name);
        goto finally;
      }
      size += PyString_GET_SIZE(item);
      if (size < 0 || size > PY_SSIZE_T_MAX) {
        PyErr_SetString(PyExc_OverflowError,
                        "join() result is too long for a Python string");
        goto finally;
      }
    }
    result = PyString_FromStringAndSize(NULL, size);
    if (result == NULL)
      goto finally;
    p = PyString_AS_STRING(result);
    for (i = 0; i < n; i++) {
      item = PyList_GET_ITEM(buffer, i);
      size = PyString_GET_SIZE(item);
      Py_MEMCPY(p, PyString_AS_STRING(item), size);
      p += size;
    }
  }
finally:
  Py_DECREF(buffer);
  return result;
}
예제 #9
0
static struct radeon_cs_int *cs_gem_create(struct radeon_cs_manager *csm,
                                       uint32_t ndw)
{
    struct cs_gem *csg;

    /* max cmd buffer size is 64Kb */
    if (ndw > (64 * 1024 / 4)) {
        return NULL;
    }
    csg = (struct cs_gem*)calloc(1, sizeof(struct cs_gem));
    if (csg == NULL) {
        return NULL;
    }
    csg->base.csm = csm;
    csg->base.ndw = 64 * 1024 / 4;
    csg->base.packets = (uint32_t*)calloc(1, 64 * 1024);
    if (csg->base.packets == NULL) {
        free(csg);
        return NULL;
    }
    csg->base.relocs_total_size = 0;
    csg->base.crelocs = 0;
    csg->base.id = generate_id();
    csg->nrelocs = 4096 / (4 * 4) ;
    csg->relocs_bo = (struct radeon_bo_int**)calloc(1,
                                                csg->nrelocs*sizeof(void*));
    if (csg->relocs_bo == NULL) {
        free(csg->base.packets);
        free(csg);
        return NULL;
    }
    csg->base.relocs = csg->relocs = (uint32_t*)calloc(1, 4096);
    if (csg->relocs == NULL) {
        free(csg->relocs_bo);
        free(csg->base.packets);
        free(csg);
        return NULL;
    }
    csg->chunks[0].chunk_id = RADEON_CHUNK_ID_IB;
    csg->chunks[0].length_dw = 0;
    csg->chunks[0].chunk_data = (uint64_t)(uintptr_t)csg->base.packets;
    csg->chunks[1].chunk_id = RADEON_CHUNK_ID_RELOCS;
    csg->chunks[1].length_dw = 0;
    csg->chunks[1].chunk_data = (uint64_t)(uintptr_t)csg->relocs;
    return (struct radeon_cs_int*)csg;
}
예제 #10
0
ring_user_id_t ring_bond::generate_id(const address_t src_mac, const address_t dst_mac, uint16_t eth_proto, uint16_t encap_proto, uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) {

	if (m_type != net_device_val::LAG_8023ad)
		return 0;

	ring_logdbg("generate_id for policy %d from src_mac=" ETH_HW_ADDR_PRINT_FMT ", dst_mac=" ETH_HW_ADDR_PRINT_FMT ", eth_proto=%#x, encap_proto=%#x, src_ip=%d.%d.%d.%d, dst_ip=%d.%d.%d.%d, src_port=%d, dst_port=%d",
			m_xmit_hash_policy, ETH_HW_ADDR_PRINT_ADDR(src_mac), ETH_HW_ADDR_PRINT_ADDR(dst_mac), ntohs(eth_proto), ntohs(encap_proto), NIPQUAD(src_ip), NIPQUAD(dst_ip), ntohs(src_port), ntohs(dst_port));

	uint32_t hash = 0;

	if (m_xmit_hash_policy > net_device_val::XHP_LAYER_2_3 && eth_proto == htons(ETH_P_8021Q)) {
		eth_proto = encap_proto;
	}

	if (eth_proto != htons(ETH_P_IP)) {
		hash = dst_mac[5] ^ src_mac[5] ^ eth_proto;
		return hash % m_n_num_resources;
	}

	switch (m_xmit_hash_policy) {
	case(net_device_val::XHP_LAYER_2):
		hash = dst_mac[5] ^ src_mac[5] ^ eth_proto;
		break;
	case(net_device_val::XHP_LAYER_2_3):
	case(net_device_val::XHP_ENCAP_2_3):
		hash = dst_mac[5] ^ src_mac[5] ^ eth_proto;
		hash ^= dst_ip ^ src_ip;
		hash ^= (hash >> 16);
		hash ^= (hash >> 8);
		break;
	case(net_device_val::XHP_LAYER_3_4):
	case(net_device_val::XHP_ENCAP_3_4):
		hash = src_port | (dst_port << 16);
		hash ^= dst_ip ^ src_ip;
		hash ^= (hash >> 16);
		hash ^= (hash >> 8);
		break;
	default:
		return generate_id();
	}

	return hash % m_n_num_resources;
}
예제 #11
0
void fakturadat::commit(void) {
//printf("in commit with %i\n",id);
	BString sql;
	int ret;
	if (id>=0) {	// UPDATE
		sql = "UPDATE faktura SET ";
		sql += "nazwa = %Q";
		sql += ", miejsce_wystawienia = %Q, wystawil = %Q, data_wystawienia = %Q, data_sprzedazy = %Q";
		sql += ", srodek_transportu = %Q, sposob_zaplaty = %Q, termin_zaplaty = %Q",
		sql += ", zapl_kwota = %Q, zapl_dnia = %Q, uwagi = %Q";
		sql += ", onazwa = %Q, oadres = %Q, okod = %Q, omiejscowosc = %Q, otelefon = %Q, oemail = %Q";
		sql += ", onip = %Q, oregon = %Q, obank = %Q, okonto = %Q";
		sql += " WHERE id = %i";
	} else {		// INSERT
		id = generate_id();
		sql += "INSERT INTO faktura ( ";
		sql += "nazwa";
		sql += ", miejsce_wystawienia, wystawil, data_wystawienia, data_sprzedazy";
		sql += ", srodek_transportu, sposob_zaplaty, termin_zaplaty";
		sql += ", zapl_kwota, zapl_dnia, uwagi";
		sql += ", onazwa, oadres, okod, omiejscowosc, otelefon, oemail";
		sql += ", onip, oregon, obank, okonto";
		sql += ", id ) VALUES ( ";
		sql += "%Q";
		sql += ", %Q, %Q, %Q, %Q";
		sql += ", %Q, %Q, %Q";
		sql += ", %Q, %Q, %Q";
		sql += ", %Q, %Q, %Q, %Q, %Q, %Q";
		sql += ", %Q, %Q, %Q, %Q";
		sql += ", %i)";
	}
//printf("sql:[%s]\n",sql.String());
	ret = sqlite_exec_printf(dbData, sql.String(), 0, 0, &dbErrMsg,
		nazwa.String(), ogol[0].String(), ogol[1].String(), ogol[2].String(), ogol[3].String(),
		ogol[4].String(), ogol[5].String(), ogol[6].String(),
		ogol[8].String(), ogol[9].String(), uwagi.String(),
		odata[0].String(), odata[2].String(), odata[3].String(), odata[4].String(), odata[5].String(), odata[6].String(),
		odata[7].String(), odata[8].String(), odata[9].String(), odata[10].String(),
		id);
//printf("result: %i, %s; id=%i\n", ret, dbErrMsg, id);
}
예제 #12
0
void pozfaklist::commititem(int fakturaid, pozfakitem *item) {
	BString sql;
	pozfakdata *data = item->data;
	int ret, id;
	/// XXX really INSERT only?
	id = generate_id();
	sql = "INSERT INTO pozycjafakt ( ";
	sql += "id, lp, ilosc";
	sql += ", nazwa, pkwiu, jm, vatid, netto, rabat";
	sql += ", fakturaid ) VALUES ( ";
	sql += "%i, %i, %Q";
	sql += ", %Q, %Q, %Q, %i, %Q, %Q";
	sql += ", %i )";
//printf("commit for %i #%i\n", id, fakturaid);
//printf("sql:[%s]\n",sql.String());
	ret = sqlite_exec_printf(dbData, sql.String(), 0, 0, &dbErrMsg,
		id, item->lp, data->data[3].String(),
		data->data[1].String(), data->data[2].String(), data->data[4].String(), data->vatid, data->data[11].String(), data->data[5].String(),
		fakturaid
	);
//printf("result: %i, %s; id=%i\n", ret, dbErrMsg, id);
}
예제 #13
0
unsigned int CodeChunk::insert_flagpoint( bool user_defined, unsigned int id ) {
    unsigned int instr_pos = instrs.size() - 1;

    bool id_assigned = false;
    if ( user_defined ) { /* try to assign the requested id */
        std::map< unsigned int, unsigned int >::iterator it = instr_ids.find( id );

        if ( it == instr_ids.end() ) { /* if not found, then assign to it */
            instr_ids[ id ] = instr_pos;
            id_assigned = true;
        }
    }

    /* in all other cases: assign a new value */
    /** TODO: implement exceptions (like out of ids) */
    if ( !id_assigned ) {
        id = generate_id();
        instr_ids[ id ] = instr_pos;
    }

    return id;
}
예제 #14
0
파일: json.c 프로젝트: phorque/maytrics
int
add_id_to_object (struct maytrics *     maytrics,
                  json_t *              json_root,
                  long *                id)
{
    json_t *    json_id;

    int         status;

    if (*id == 0) {
        *id = generate_id (maytrics);
    }
    if (*id == -1) {
        status = EVHTP_RES_SERVERR;
        goto exit;
    }

    json_id = json_integer (*id);
    if (json_id == NULL) {
        log_error ("json_integer() failed.");
        status = EVHTP_RES_SERVERR;
        goto exit;
    }

    if (json_object_set_new (json_root, "id", json_id) == -1) {
        log_error ("json_object_set() failed.");
        status = EVHTP_RES_SERVERR;
        goto json_decref;
    }

    return (0);

  json_decref:
    json_decref (json_id);

  exit:
    return (status);
}
예제 #15
0
static void remider_add_pin(int iID, const RoadMapPosition *position){
   RoadMapDynamicString dID = generate_id(iID);
   RoadMapDynamicString dName = generate_name(iID);
   RoadMapDynamicString dSprite= roadmap_string_new( "Reminder");
   RoadMapDynamicString dGroup = roadmap_string_new( "Reminders");
   RoadMapDynamicString dImage_Reminder = roadmap_string_new( "reminder_pin");
   RoadMapGpsPosition   Pos;

   Pos.longitude  = position->longitude;
   Pos.latitude   = position->latitude;
   Pos.altitude   = 0;
   Pos.speed      = 0;
   Pos.steering   = 0;

   roadmap_object_add( dGroup, dID, dName, dSprite, dImage_Reminder, &Pos, NULL, 0, NULL);
   roadmap_object_set_action(dID, OnReminderShortClick);

   roadmap_string_release(dID);
   roadmap_string_release(dName);
   roadmap_string_release(dGroup);
   roadmap_string_release(dSprite);
   roadmap_string_release(dImage_Reminder);
}
예제 #16
0
void towardat::commit(void) {
	BString sql;
	int ret;
//printf("commit\n");
	if (id>=0) {	// UPDATE
		sql = "UPDATE towar SET ";
		sql += "nazwa = %Q, symbol = %Q, pkwiu = %Q, jm = %Q";
		sql += ", usluga = %i, dodany = date('now'), notatki = %Q, vatid = %i";
		sql += ", netto = %Q, zakupu = %Q, marza = %Q, rabat = %Q, kurs = %Q, clo = %Q";
		sql += ", magazyn = %Q, magzmiana = date('now')";
		sql += " WHERE id = %i";
	} else {		// INSERT
		id = generate_id();
		sql += "INSERT INTO towar ( ";
		sql += "nazwa, symbol, pkwiu, jm";
		sql += ", usluga, dodany, notatki, vatid";
		sql += ", netto, zakupu, marza, rabat";
		sql += ", kurs, clo";
		sql += ", magazyn, magzmiana";
		sql += ", id ) VALUES ( ";
		sql += "%Q, %Q, %Q, %Q";
		sql += ", %i, date('now'), %Q, %i";
		sql += ", %Q, %Q, %Q, %Q";
		sql += ", %Q, %Q";
		sql += ", %Q, date('now')";
		sql += ", %i)";
	}
//printf("sql:[%s]\n",sql.String());
	ret = sqlite_exec_printf(dbData, sql.String(), 0, 0, &dbErrMsg,
		data[0].String(), data[1].String(), data[2].String(), data[3].String(),
		usluga, notatki.String(), vatid,
		ceny[0].String(), ceny[1].String(), ceny[2].String(), ceny[3].String(),
		ceny[4].String(), ceny[5].String(),
		magazyn.String(),
		id);
//printf("result: %i, %s; id=%i\n", ret, dbErrMsg, id);
}
예제 #17
0
static void show_reminder(int id, int distance){
   SsdWidget button;
   SsdWidget spacer;
   SsdWidget txt;
   SsdWidget bg;

   if (ssd_dialog_is_currently_active() && (!strcmp(ssd_dialog_currently_active_name(), REMINDER_POP_DLG_NAME)))
      ssd_dialog_hide_current(dec_close);


   bg = create_reminder_dlg();

   if (id != -1){
      Reminder reminder;
      SsdWidget container;
      char msg[250];
      int rem_distance;

      container = ssd_container_new( "container_txt", "", SSD_MIN_SIZE, SSD_MIN_SIZE, 0 );
      ssd_widget_set_color( container, NULL, NULL );

      reminder = ReminderTable.reminder[id];
      txt = ssd_text_new("reminder_title",&reminder.title[0] ,22, SSD_END_ROW);
      ssd_text_set_color(txt, "#ab5939");
      ssd_widget_set_offset(txt, 25, 0);
      ssd_widget_add(container, txt);

      spacer = ssd_container_new( "space", "", SSD_MIN_SIZE, 10, SSD_END_ROW );
      ssd_widget_set_color( spacer, NULL, NULL );
      ssd_widget_add( container, spacer );

      txt = ssd_text_new("reminder_desc",&reminder.description[0] ,18, SSD_END_ROW);
      ssd_text_set_color(txt, "#ab5939");
      ssd_widget_set_offset(txt, 30, 0);
      ssd_widget_add(container, txt);

      spacer = ssd_container_new( "space", "", SSD_MIN_SIZE, 10, SSD_END_ROW );
      ssd_widget_set_color( spacer, NULL, NULL );
      ssd_widget_add( container, spacer );

      rem_distance = roadmap_math_to_trip_distance_tenths(reminder.distance);
      sprintf(msg, "%s: %.1f %s",roadmap_lang_get("Distance"), rem_distance/10.0, roadmap_lang_get(roadmap_math_trip_unit()) );
      txt = ssd_text_new("reminder_dist",&msg[0] ,14, SSD_END_ROW);
      ssd_text_set_color(txt, "#ab5939");
      ssd_widget_set_offset(txt, 30, 0);
      ssd_widget_add(container, txt);

      ssd_widget_add( bg, container );
   }

#ifdef TOUCH_SCREEN
   spacer = ssd_container_new( "space", "", 10, 30, SSD_END_ROW );
   ssd_widget_set_color( spacer, NULL, NULL );
   ssd_widget_add( bg, spacer );

   button = create_close_button();
   button->context = (void *)roadmap_string_get(generate_id(id));
   ssd_widget_add(bg, button);

   if (ReminderTable.reminder[id].repeat == 1){
      button = create_del_button();
      button->context = (void *)roadmap_string_get(generate_id(id));
      ssd_widget_add(bg, button);
   }

#endif //TOUCH_SCREEN

   show_reminder_dlg();

}
예제 #18
0
파일: ast_fwd.hpp 프로젝트: rhysd/Dachs
 base() noexcept
     : location()
     , id(generate_id())
 {}
예제 #19
0
파일: node.c 프로젝트: abed-hawa/amara
generate_id(NodeObject *node, PyObject *buffer)
{
  NodeObject *parent;
  PyObject *typecode, *index;
  Py_ssize_t pos;

  assert(node != NULL && buffer != NULL && PyList_CheckExact(buffer));

  parent = Node_GET_PARENT(node);
  if (parent != NULL) {
    if (generate_id(parent, buffer) < 0)
      return -1;
    typecode = _PyType_Lookup(node->ob_type, typecode_string);
    if (typecode == NULL)
      return -1;
    if (PyList_Append(buffer, typecode) < 0)
      return -1;
    if (Element_Check(parent)) {
      if (Attr_Check(node)) {
        PyObject *nodemap = Element_ATTRIBUTES(parent);
        AttrObject *attr;
        /* `nodemap` should not be NULL as the attribute `node` claims to be
         * owned by the element `parent`. */
        assert(nodemap != NULL);
        pos = 0;
        while ((attr = AttributeMap_Next(nodemap, &pos)) != NULL) {
          if (attr == (AttrObject *)node)
            break;
        }
        assert(attr != NULL);
      }
      else if (Namespace_Check(node)) {
        PyObject *nodemap = Element_NAMESPACES(parent);
        NamespaceObject *decl;
        /* `nodemap` should not be NULL as the namespace `node` claims to be
         * owned by the element `parent`. */
        assert(nodemap != NULL);
        pos = 0;
        while ((decl = NamespaceMap_Next(nodemap, &pos)) != NULL) {
          if (decl == (NamespaceObject *)node)
            break;
        }
        assert(decl != NULL);
      } else {
        pos = Container_Index(parent, node);
      }
    } else {
      pos = Container_Index(parent, node);
    }
    if (pos < 0)
      return -1;
    index = PyString_FromFormat("%zd", pos);
    if (index == NULL)
      return -1;
    if (PyList_Append(buffer, index) < 0) {
      Py_DECREF(index);
      return -1;
    }
    Py_DECREF(index);
  } else {
    /* the top of the tree */
    typecode = _PyType_Lookup(node->ob_type, typecode_string);
    if (typecode == NULL)
      return -1;
    if (PyList_Append(buffer, typecode) < 0)
      return -1;
    if (Entity_Check(node)) {
      index = PyObject_Str(Entity_GET_INDEX(node));
    } else {
      /* a tree fragment; just use its id() */
      PyObject *id = PyLong_FromVoidPtr(node);
      if (id == NULL)
        return -1;
      index = PyObject_Str(id);
      Py_DECREF(id);
    }
    if (index == NULL)
      return -1;
    if (PyList_Append(buffer, index) < 0) {
      Py_DECREF(index);
      return -1;
    }
    Py_DECREF(index);
  }
  return 0;
}
예제 #20
0
 explicit pure_pointer(T *ptr,
     IdDistributor &idDistributor)
   : ptr_(ptr), int_id_(generate_id(ptr, idDistributor))
 {
 }
예제 #21
0
int main(int argc, char **argv)
{
    boot_img_hdr_v2 hdr;

    char *kernel_fn = NULL;
    void *kernel_data = NULL;
    char *ramdisk_fn = NULL;
    void *ramdisk_data = NULL;
    char *second_fn = NULL;
    void *second_data = NULL;
    char *dtb_fn = NULL;
    void *dtb_data = NULL;
    char *recovery_dtbo_fn = NULL;
    void *recovery_dtbo_data = NULL;
    char *cmdline = "";
    char *bootimg = NULL;
    char *board = "";
    int os_version = 0;
    int os_patch_level = 0;
    int header_version = 0;
    char *dt_fn = NULL;
    void *dt_data = NULL;
    uint32_t pagesize = 2048;
    int fd;
    uint32_t base           = 0x10000000U;
    uint32_t kernel_offset  = 0x00008000U;
    uint32_t ramdisk_offset = 0x01000000U;
    uint32_t second_offset  = 0x00f00000U;
    uint32_t tags_offset    = 0x00000100U;
    uint32_t kernel_sz      = 0;
    uint32_t ramdisk_sz     = 0;
    uint32_t second_sz      = 0;
    uint32_t dt_sz          = 0;
    uint32_t rec_dtbo_sz    = 0;
    uint64_t rec_dtbo_offset= 0;
    uint32_t header_sz      = 0;
    uint32_t dtb_sz         = 0;
    uint64_t dtb_offset     = 0x01f00000U;

    size_t cmdlen;
    enum hash_alg hash_alg = HASH_SHA1;

    argc--;
    argv++;

    memset(&hdr, 0, sizeof(hdr));

    bool get_id = false;
    while(argc > 0){
        char *arg = argv[0];
        if(!strcmp(arg, "--id")) {
            get_id = true;
            argc -= 1;
            argv += 1;
        } else if(argc >= 2) {
            char *val = argv[1];
            argc -= 2;
            argv += 2;
            if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) {
                bootimg = val;
            } else if(!strcmp(arg, "--kernel")) {
                kernel_fn = val;
            } else if(!strcmp(arg, "--ramdisk")) {
                ramdisk_fn = val;
            } else if(!strcmp(arg, "--second")) {
                second_fn = val;
            } else if(!strcmp(arg, "--dtb")) {
                dtb_fn = val;
            } else if(!strcmp(arg, "--recovery_dtbo") || !strcmp(arg, "--recovery_acpio")) {
                recovery_dtbo_fn = val;
            } else if(!strcmp(arg, "--cmdline")) {
                cmdline = val;
            } else if(!strcmp(arg, "--base")) {
                base = strtoul(val, 0, 16);
            } else if(!strcmp(arg, "--kernel_offset")) {
                kernel_offset = strtoul(val, 0, 16);
            } else if(!strcmp(arg, "--ramdisk_offset")) {
                ramdisk_offset = strtoul(val, 0, 16);
            } else if(!strcmp(arg, "--second_offset")) {
                second_offset = strtoul(val, 0, 16);
            } else if(!strcmp(arg, "--tags_offset")) {
                tags_offset = strtoul(val, 0, 16);
            } else if(!strcmp(arg, "--dtb_offset")) {
                dtb_offset = strtoul(val, 0, 16);
            } else if(!strcmp(arg, "--board")) {
                board = val;
            } else if(!strcmp(arg,"--pagesize")) {
                pagesize = strtoul(val, 0, 10);
                if((pagesize != 2048) && (pagesize != 4096)
                    && (pagesize != 8192) && (pagesize != 16384)
                    && (pagesize != 32768) && (pagesize != 65536)
                    && (pagesize != 131072)) {
                    fprintf(stderr,"error: unsupported page size %d\n", pagesize);
                    return -1;
                }
            } else if(!strcmp(arg, "--dt")) {
                dt_fn = val;
            } else if(!strcmp(arg, "--os_version")) {
                os_version = parse_os_version(val);
            } else if(!strcmp(arg, "--os_patch_level")) {
                os_patch_level = parse_os_patch_level(val);
            } else if(!strcmp(arg, "--header_version")) {
                header_version = strtoul(val, 0, 10);
            } else if(!strcmp(arg, "--hash")) {
                hash_alg = parse_hash_alg(val);
                if(hash_alg == HASH_UNKNOWN) {
                    fprintf(stderr, "error: unknown hash algorithm '%s'\n", val);
                    return -1;
                }
            } else {
                return usage();
            }
        } else {
            return usage();
        }
    }
    hdr.page_size = pagesize;

    hdr.kernel_addr =  base + kernel_offset;
    hdr.ramdisk_addr = base + ramdisk_offset;
    hdr.second_addr =  base + second_offset;
    hdr.tags_addr =    base + tags_offset;

    hdr.header_version = header_version;
    hdr.os_version = (os_version << 11) | os_patch_level;

    if(bootimg == 0) {
        fprintf(stderr,"error: no output filename specified\n");
        return usage();
    }

    if(kernel_fn == 0) {
        fprintf(stderr,"error: no kernel image specified\n");
        return usage();
    }

    if(strlen(board) >= BOOT_NAME_SIZE) {
        fprintf(stderr,"error: board name too large\n");
        return usage();
    }

    strcpy((char *) hdr.name, board);

    memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE);

    cmdlen = strlen(cmdline);
    if(cmdlen <= BOOT_ARGS_SIZE) {
        strcpy((char *)hdr.cmdline, cmdline);
    } else if(cmdlen <= BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE) {
        /* exceeds the limits of the base command-line size, go for the extra */
        memcpy(hdr.cmdline, cmdline, BOOT_ARGS_SIZE);
        strcpy((char *)hdr.extra_cmdline, cmdline+BOOT_ARGS_SIZE);
    } else {
        fprintf(stderr,"error: kernel commandline too large\n");
        return 1;
    }

    kernel_data = load_file(kernel_fn, &kernel_sz);
    if(kernel_data == 0) {
        fprintf(stderr,"error: could not load kernel '%s'\n", kernel_fn);
        return 1;
    }
    hdr.kernel_size = kernel_sz;

    if(ramdisk_fn == NULL) {
        ramdisk_data = 0;
    } else {
        ramdisk_data = load_file(ramdisk_fn, &ramdisk_sz);
        if(ramdisk_data == 0) {
            fprintf(stderr,"error: could not load ramdisk '%s'\n", ramdisk_fn);
            return 1;
        }
    }
    hdr.ramdisk_size = ramdisk_sz;

    if(second_fn) {
        second_data = load_file(second_fn, &second_sz);
        if(second_data == 0) {
            fprintf(stderr,"error: could not load secondstage '%s'\n", second_fn);
            return 1;
        }
    }
    hdr.second_size = second_sz;

    if(header_version == 0) {
        if(dt_fn) {
            dt_data = load_file(dt_fn, &dt_sz);
            if(dt_data == 0) {
                fprintf(stderr,"error: could not load device tree image '%s'\n", dt_fn);
                return 1;
            }
        }
        hdr.dt_size = dt_sz; /* overrides hdr.header_version */
    } else {
        if(recovery_dtbo_fn) {
            recovery_dtbo_data = load_file(recovery_dtbo_fn, &rec_dtbo_sz);
            if(recovery_dtbo_data == 0) {
                fprintf(stderr,"error: could not load recovery dtbo image '%s'\n", recovery_dtbo_fn);
                return 1;
            }
            /* header occupies a page */
            rec_dtbo_offset = pagesize * (1 + \
                                          (kernel_sz + pagesize - 1) / pagesize + \
                                          (ramdisk_sz + pagesize - 1) / pagesize + \
                                          (second_sz + pagesize - 1) / pagesize);
        }
        if(header_version == 1) {
            header_sz = 1648;
        } else {
            header_sz = sizeof(hdr);
        }
        if(header_version > 1) {
            if(dtb_fn) {
                dtb_data = load_file(dtb_fn, &dtb_sz);
                if(dtb_data == 0) {
                    fprintf(stderr,"error: could not load recovery dtb image '%s'\n", dtb_fn);
                    return 1;
                }
            }
        }
    }
    hdr.recovery_dtbo_size = rec_dtbo_sz;
    hdr.recovery_dtbo_offset = rec_dtbo_offset;
    hdr.header_size = header_sz;
    hdr.dtb_size = dtb_sz;
    if(header_version > 1) {
        hdr.dtb_addr = base + dtb_offset;
    } else {
        hdr.dtb_addr = 0;
    }

    /* put a hash of the contents in the header so boot images can be
     * differentiated based on their first 2k.
     */
    generate_id(hash_alg, &hdr, kernel_data, ramdisk_data, second_data, dt_data, recovery_dtbo_data, dtb_data);

    fd = open(bootimg, O_CREAT | O_TRUNC | O_WRONLY, 0644);
    if(fd < 0) {
        fprintf(stderr,"error: could not create '%s'\n", bootimg);
        return 1;
    }

    if(write(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) goto fail;
    if(write_padding(fd, pagesize, sizeof(hdr))) goto fail;

    if(write(fd, kernel_data, hdr.kernel_size) != (ssize_t) hdr.kernel_size) goto fail;
    if(write_padding(fd, pagesize, hdr.kernel_size)) goto fail;

    if(write(fd, ramdisk_data, hdr.ramdisk_size) != (ssize_t) hdr.ramdisk_size) goto fail;
    if(write_padding(fd, pagesize, hdr.ramdisk_size)) goto fail;

    if(second_data) {
        if(write(fd, second_data, hdr.second_size) != (ssize_t) hdr.second_size) goto fail;
        if(write_padding(fd, pagesize, hdr.second_size)) goto fail;
    }

    if(dt_data) {
        if(write(fd, dt_data, hdr.dt_size) != (ssize_t) hdr.dt_size) goto fail;
        if(write_padding(fd, pagesize, hdr.dt_size)) goto fail;
    } else {
        if(recovery_dtbo_data) {
            if(write(fd, recovery_dtbo_data, hdr.recovery_dtbo_size) != (ssize_t) hdr.recovery_dtbo_size) goto fail;
            if(write_padding(fd, pagesize, hdr.recovery_dtbo_size)) goto fail;
        }
        if(dtb_data) {
            if(write(fd, dtb_data, hdr.dtb_size) != (ssize_t) hdr.dtb_size) goto fail;
            if(write_padding(fd, pagesize, hdr.dtb_size)) goto fail;
        }
    }

    if(get_id) {
        print_id((uint8_t *) hdr.id, sizeof(hdr.id));
    }
    return 0;

fail:
    unlink(bootimg);
    close(fd);
    fprintf(stderr,"error: failed writing '%s': %s\n", bootimg,
            strerror(errno));
    return 1;
}
int Simulator::dispatch() {
	bool dispatch = true;
	int num_dispatch = 0;
	while (dispatch_buffer.size() > 0 && dispatch && num_dispatch < n_width) {
		dispatch = false;
		if (dispatch_buffer.front().opcode <= 2) {
			if (RS[0].size() < rs_width) {
				dispatch = true;
			}
		}
		else if (dispatch_buffer.front().opcode <= 4) {
			if (RS[1].size() < rs_width) {
				dispatch = true;
			}
		}
		else if (dispatch_buffer.front().opcode <= 6) {
			if (RS[2].size() < rs_width) {
				dispatch = true;
			}
		}
		else {
			dispatch = true;
		}

		if (dispatch) {
			rs_entry rs;
			rob_entry r;
			pipeline_instr p = dispatch_buffer.front();
			int id = generate_id();
			int tag = generate_tag();
			p.id = id;

			r.id = id;
			rs.id = id;
			r.busy = true;

			if (p.opcode <= 2) {
				if (arf_flags[p.op2].valid) {
					p.A = register_file[p.op2];
					rs_f e1;
					e1.valid = true;
					rs.operand.push_back(e1);
				}
				else {
					rs_f e1;
					e1.valid = false;
					e1.tag = arf_flags[p.op2].tag;
					rs.operand.push_back(e1);
				}
				if (p.immediate) {
					p.imm_field = p.op3;
					rs_f e1;
					e1.valid = true;
					rs.operand.push_back(e1);
				}
				else {	
					if (arf_flags[p.op3].valid) {
						p.B = register_file[p.op3];
						rs_f e1;
						e1.valid = true;
						rs.operand.push_back(e1);
					}
					else {
						rs_f e1;
						e1.valid = false;
						e1.tag = arf_flags[p.op3].tag;
						rs.operand.push_back(e1);
					}
				}
				arf_flags[p.op1].valid = false;
				arf_flags[p.op1].tag = tag;
				p.rs_tag = tag;
				rs.instr = p;
				r.instr = p;
				RS[0].push_back(rs);
				rob.push_back(r);
			}
			else if (p.opcode == 3) {
				if (arf_flags[p.op2].valid) {
					p.A = register_file[p.op2];
					rs_f e1;
					e1.valid = true;
					rs.operand.push_back(e1);
				}
				else {
					rs_f e1;
					e1.valid = false;
					e1.tag = arf_flags[p.op2].tag;
					rs.operand.push_back(e1);
				}
				arf_flags[p.op1].valid = false;
				arf_flags[p.op1].tag = tag;
				p.rs_tag = tag;
				rs.instr = p;
				r.instr = p;
				RS[1].push_back(rs);
				rob.push_back(r);
			}
			else if (p.opcode == 4) {
				if (arf_flags[p.op2].valid) {
					p.B = register_file[p.op2];
					rs_f e1;
					e1.valid = true;
					rs.operand.push_back(e1);
				}
				else {
					rs_f e1;
					e1.valid = false;
					e1.tag = arf_flags[p.op2].tag;
					rs.operand.push_back(e1);
				}
				if (arf_flags[p.op1].valid) {
					p.A = register_file[p.op1];
					rs_f e1;
					e1.valid = true;
					rs.operand.push_back(e1);
				}
				else {
					rs_f e1;
					e1.valid = false;
					e1.tag = arf_flags[p.op1].tag;
					rs.operand.push_back(e1);
				}
				p.rs_tag = tag;
				rs.instr = p;
				r.instr = p;
				RS[1].push_back(rs);
				rob.push_back(r);
			}
			else if (p.opcode == 5) {
				p.imm_field = p.op1;
				p.rs_tag = tag;
				rs.instr = p;
				r.instr = p;
				RS[2].push_back(rs);
				rob.push_back(r);
			}
			else if (p.opcode == 6) {
				p.imm_field = p.op2;
				if (arf_flags[p.op1].valid) {
					p.A = register_file[p.op1];
					rs_f e1;
					e1.valid = true;
					rs.operand.push_back(e1);
				}
				else {
					rs_f e1;
					e1.valid = false;
					e1.tag = arf_flags[p.op1].tag;
					rs.operand.push_back(e1);
				}
				p.rs_tag = tag;
				rs.instr = p;
				r.instr = p;
				RS[2].push_back(rs);
				rob.push_back(r);
			}
			else {
				r.finished = true;
				r.instr = p;
				rob.push_back(r);
			}

		    cout<<"Dispatch: "<<p.IR<<endl;	
			num_dispatch++;
			dispatch_buffer.pop();
		}

	}
	return 1;
}