/* Initialize parser state to be passed around as an opaque reference */ hcerr_t xml_create (start_element_handler_t start_element_callback, end_element_handler_t end_element_callback, void *data, xml_parser **parser, allocator_t a, deallocator_t d){ simple_xml_parser *simple_parser; ALLOCATOR(simple_parser, sizeof(simple_xml_parser)); simple_parser->start_element_callback = start_element_callback; simple_parser->end_element_callback = end_element_callback; simple_parser->data = data; simple_parser->attribute_arrays_size = ATTRIBUTE_ARRAYS_INITIAL_SIZE; simple_parser->current_attribute = 0; simple_parser->depth = 0; simple_parser->start_tag = FALSE; simple_parser->backslash = FALSE; simple_parser->state = OUTSIDE_ELEMENT; simple_parser->count = count++; simple_parser->allocator = a; simple_parser->deallocator = d; simple_parser->attribute_names = NULL; ALLOCATOR(simple_parser->attribute_values, (sizeof(char*) * ATTRIBUTE_ARRAYS_INITIAL_SIZE)); ALLOCATOR(simple_parser->attribute_names, (sizeof(char*) * ATTRIBUTE_ARRAYS_INITIAL_SIZE)); require_ok(make_buffer_list(&simple_parser->buffer_list)); *parser = (xml_parser*) simple_parser; return HCERR_OK; }
static hcerr_t token_append(buffer_list_t *buffer_list, char c){ unsigned int malloc_size = 0 ; buffer_cell_t *bl = NULL; /* Check for overflow, reserving an extra space for null terminator */ if (buffer_list->current_token_position + 2 >= buffer_list->current_token_buffer_size){ if (buffer_list->current_token_start == 0){ /* Token is biffer than buffer size. */ buffer_list->current_token_buffer_size = buffer_list->current_token_buffer_size * 2; } malloc_size = buffer_list->current_token_buffer_size * sizeof(char); if (DEBUG == TRUE){ printf("mallocing buffer size %d\n", malloc_size); fflush(stdout); } ALLOCATOR(bl, sizeof(buffer_cell_t)); ALLOCATOR(bl->data, malloc_size); bl->previous = buffer_list->string_buffer; /* copy fragment from old buffer */ strncpy(bl->data, buffer_list->string_buffer->data + buffer_list->current_token_start, buffer_list->current_token_position - buffer_list->current_token_start); buffer_list->current_token_position = buffer_list->current_token_position - buffer_list->current_token_start; buffer_list->current_token_start = 0; buffer_list->string_buffer = bl; } buffer_list->string_buffer->data[buffer_list->current_token_position++] = c; /* How do I detect out-of-memory? */ return HCERR_OK; }
static hcerr_t make_buffer_list(buffer_list_t *buffer_list){ buffer_list->current_token_buffer_size = CURRENT_TOKEN_BUFFER_INITIAL_SIZE; ALLOCATOR(buffer_list->string_buffer, sizeof(buffer_cell_t)); buffer_list->string_buffer->previous = NULL; buffer_list->current_token_start = 0; buffer_list->current_token_position = 0; ALLOCATOR(buffer_list->string_buffer->data, CURRENT_TOKEN_BUFFER_INITIAL_SIZE * sizeof(char)); return HCERR_OK; }
void ACE_TS_Clerk_Processor::alloc (void) { ACE_TRACE ("ACE_TS_Clerk_Processor::alloc"); ACE_NEW (this->shmem_, ALLOCATOR (this->poolname_)); void *temp = 0; // Only create the state if it doesn't already exist. if (this->shmem_->find (ACE_DEFAULT_TIME_SERVER_STR, temp) == -1) { // Allocate the space out of shared memory for the system time entry temp = (this->shmem_->malloc (2 * sizeof (time_t))); // Give it a name binding this->shmem_->bind (ACE_DEFAULT_TIME_SERVER_STR, temp); } // Set up pointers. Note that we add one to get to the second // field in the structure time_t *time_p = (time_t *)temp; this->system_time_.delta_time_ = time_p; this->system_time_.last_local_time_ = time_p + 1; // Initialize *(this->system_time_.delta_time_) = 0; *(this->system_time_.last_local_time_) = ACE_OS::time (0); }
/*=========================================================================*/ qmi_dispatch_service_type* qmi_dispatch_service_new(qmi_msg_handler_type *dispatch_table, uint32_t dispatch_table_size, qmi_dispatch_service_error_type *err) { qmi_dispatch_service_type *new_msg_handler; if (dispatch_table == NULL || dispatch_table_size <= 0 ) { *err = QMI_DISPATCH_SERVICE_INVALID_ARGS; return NULL; } new_msg_handler = ALLOCATOR(sizeof(qmi_dispatch_service_type)); if (new_msg_handler == NULL ) { *err = QMI_DISPATCH_SERVICE_MEM_ERR; return NULL; } new_msg_handler->dispatch_handler = dispatch_table; new_msg_handler->dispatch_table_size = dispatch_table_size; return new_msg_handler; }
static hcerr_t push_tag (hc_tag_stack_t **top, hc_tag_stack_t *old_top, char *tag){ /* copy string? */ ALLOCATOR(*top, sizeof(hc_tag_stack_t)); (*top)->enclosed_by = old_top; (*top)->tag = tag; return HCERR_OK; }
/*=========================================================================*/ ping_server* ping_server_new(char *object_name, uint32_t instance_id, ping_server_error *err) { ping_server* ping_server_object; qmi_core_server_error_type rc; /*The default priority of one greater than DIAG's task priority is considered if NULL is passed to the API */ uint32_t priority = 14; uint32_t index; unsigned long sig = QMI_PING_SVC_WAIT_SIG; ping_server_object = ALLOCATOR(sizeof(ping_server_class_type)); if (ping_server_object == NULL ) { *err = (ping_server_error)QMI_CORE_SERVER_MEMORY_ERR; return NULL; } /*Construct and Initialize the core server object */ rc = qmi_core_server_new(&(ping_server_object->core_object), object_name, instance_id,/* Instance id */ 1,/* Task flag */ (void*)ping_server_event_loop, (void*)&priority, NULL, (void *)&sig, NULL, ping_server_dispatcher, sizeof(ping_server_dispatcher)/sizeof(qmi_msg_handler_type)); if (rc == QMI_CORE_SERVER_NO_ERR ) { /* Initialize the client data */ for (index = 0; index < MAX_NUM_CLIENTS; index++ ) { memset(&(ping_server_object->client_data[index].conn_obj),0,sizeof (qmi_core_conn_obj_type)); /*Initialize each indication object declared in the client structure */ ping_server_initialize_indication_data(&(ping_server_object->client_data[index].ping_ind)); ping_server_object->client_data[index].transaction_counter = 0; ping_server_object->client_data[index].active_flag = 0; } ping_server_object->client_counter = 0; ping_server_object->client_index = 0; /* Initialize rest of the server data here */ ref_count++; return ping_server_object; } else { DEALLOCATE(ping_server_object); *err = (ping_server_error)rc; return NULL; } }
int TAO_Persistent_Context_Index::create_index (void) { // Make sure that the file name is of the legal length. if (ACE_OS::strlen (index_file_) >= MAXNAMELEN + MAXPATHLEN) { errno = ENAMETOOLONG; return -1; } ACE_MMAP_Memory_Pool::OPTIONS options (base_address_); // Create the allocator with the appropriate options. The name used // for the lock is the same as one used for the file. ACE_NEW_RETURN (this->allocator_, ALLOCATOR (this->index_file_, this->index_file_, &options), -1); #if !defined (ACE_LACKS_ACCESS) // Now check if the backing store has been created successfully. if (ACE_OS::access (this->index_file_, F_OK) != 0) ORBSVCS_ERROR_RETURN ((LM_ERROR, "create_index\n"), -1); #endif /* ACE_LACKS_ACCESS */ void *context_index = 0; // This is the easy case since if we find hash table in the // memory-mapped file we know it's already initialized. if (this->allocator_->find (TAO_NAMING_CONTEXT_INDEX, context_index) == 0) this->index_ = (CONTEXT_INDEX *) context_index; // Create a new <index_> (because we've just created a new // memory-mapped file). else { size_t index_size = sizeof (CONTEXT_INDEX); context_index = this->allocator_->malloc (index_size); if (context_index == 0 || create_index_helper (context_index) == -1 || this->allocator_->bind (TAO_NAMING_CONTEXT_INDEX, context_index) == -1) { // Attempt to clean up. ORBSVCS_ERROR ((LM_ERROR, "create_index\n")); this->allocator_->remove (); return -1; } } return 0; }
static hcerr_t grow_attribute_arrays(simple_xml_parser *parser){ char **names; char **values; int i = 0; //[???] Change the following to use "reallocator" ALLOCATOR(names, parser->attribute_arrays_size * 2 * sizeof(char*)); ALLOCATOR(values, parser->attribute_arrays_size * 2 * sizeof(char*)); for (i = 0; i < parser->current_attribute; i++){ names[i] = parser->attribute_names[i]; values[i] = parser->attribute_values[i]; } parser->attribute_arrays_size = parser->attribute_arrays_size * 2; deallocator(parser->attribute_names); parser->attribute_names = names; deallocator(parser->attribute_values); parser->attribute_values = values; return HCERR_OK; }
static hcerr_t base_start_document (char *document_tag, xml_writer **writer, allocator_t a, deallocator_t d, int pp){ hc_simple_xml_writer_t *simple_writer; PP_LF = pp; PP_INDENT = pp; ALLOCATOR(simple_writer, sizeof(hc_simple_xml_writer_t)); memset(simple_writer, 0, sizeof(hc_simple_xml_writer_t)); //simple_writer->position = 0; ALLOCATOR(simple_writer->document_tag, strlen(document_tag) + 1); strcpy(simple_writer->document_tag, document_tag); simple_writer->indent = 0; simple_writer->tag_stack = NULL; simple_writer->allocator = a; simple_writer->deallocator = d; *writer = (xml_writer*) simple_writer; return HCERR_OK; }
hcerr_t init_multi_cell(silo_t **silop) { silo_t *silo; ALLOCATOR(silo, sizeof(silo_t)); memset((char *)silo,0,sizeof(*silo)); // Whenever we recreate the silo, start out with version = -1.0 silo->major_version = MULTICELL_INIT_MAJOR_VERSION; silo->minor_version = MULTICELL_INIT_MINOR_VERSION; *silop = silo; return HCERR_OK; }
Object_Group_Factory_i::Object_Group_Factory_i (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) :orb_ (orb), poa_ (PortableServer::POA::_duplicate (poa)), random_groups_ (0), rr_groups_ (0), flags_ (0) { ACE_MMAP_Memory_Pool::OPTIONS options (ACE_DEFAULT_BASE_ADDR); ACE_NEW (this->mem_pool_, ALLOCATOR ("Mem_Pool", "Mem_Pool", &options)); }
Object_Group_i::Object_Group_i (const char * id, PortableServer::POA_ptr poa) :poa_ (PortableServer::POA::_duplicate (poa)), member_id_list_ (0), members_ (0), id_ (id), allocator_ (0) { if (!this->allocator_) { ACE_MMAP_Memory_Pool::OPTIONS options (ACE_DEFAULT_BASE_ADDR); ACE_NEW (this->allocator_, ALLOCATOR ("Mem_Pool", "Mem_Pool", &options)); } }
/* Write to supplied stream when our buffer fills. */ hcerr_t start_document (char *document_tag, write_bytes_callback_t backend_writer, void *stream, xml_writer **writer, allocator_t a, deallocator_t d, int pp){ char *buf; require_ok(base_start_document (document_tag, writer, a, d, pp)); ((hc_simple_xml_writer_t *) (*writer))->write_to_callback = TRUE; ALLOCATOR(buf, HC_XML_WRITE_BUFFER_SIZE * sizeof(char)); ((hc_simple_xml_writer_t *) (*writer))->buffer = buf; ((hc_simple_xml_writer_t *) (*writer))->write_callback = backend_writer; ((hc_simple_xml_writer_t *) (*writer))->stream = stream; require_ok(write_document_element(*writer)); return HCERR_OK; }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_System_Time::ACE_System_Time (const ACE_TCHAR *poolname) : shmem_ (0) , delta_time_ (0) { ACE_TRACE ("ACE_System_Time::ACE_System_Time"); // Only create a new unique filename for the memory pool file // if the user didn't supply one... if (poolname == 0) { #if defined (ACE_DEFAULT_BACKING_STORE) // Create a temporary file. ACE_OS::strcpy (this->poolname_, ACE_DEFAULT_BACKING_STORE); #else /* ACE_DEFAULT_BACKING_STORE */ if (ACE::get_temp_dir (this->poolname_, MAXPATHLEN - 17) == -1) // -17 for ace-malloc-XXXXXX { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Temporary path too long, ") ACE_TEXT ("defaulting to current directory\n"))); this->poolname_[0] = 0; } // Add the filename to the end ACE_OS::strcat (this->poolname_, ACE_TEXT ("ace-malloc-XXXXXX")); #endif /* ACE_DEFAULT_BACKING_STORE */ } else ACE_OS::strsncpy (this->poolname_, poolname, (sizeof this->poolname_ / sizeof (ACE_TCHAR))); ACE_NEW (this->shmem_, ALLOCATOR (this->poolname_)); }
inline ALLOCATOR(_Tp2) _STLP_CALL __stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) { return ALLOCATOR(_Tp2)(); }
int PersistenceUpdater::init(int argc, ACE_TCHAR *argv[]) { // discover the UpdateManager um_ = ACE_Dynamic_Service<Update::Manager>::instance ("UpdateManagerSvc"); if (um_ == 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("PersistenceUpdater initialization failed. ") ACE_TEXT("No UpdateManager discovered.\n"))); return -1; } this->parse(argc, argv); ACE_MMAP_Memory_Pool::OPTIONS options(ACE_DEFAULT_BASE_ADDR); // Create the allocator with the appropriate options. The name used // for the lock is the same as one used for the file. ACE_NEW_RETURN(allocator_, ALLOCATOR(persistence_file_.c_str(), persistence_file_.c_str(), &options), -1); std::string topic_tag("TopicIndex"); std::string participant_tag("ParticipantIndex"); std::string actor_tag("ActorIndex"); bool exists = false, ex = false; char* topic_index = (char*)createIndex(topic_tag, *allocator_ , sizeof(TopicIndex), ex); if (topic_index == 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("Initial allocation/Bind failed 1.\n"))); return -1; } exists = exists || ex; char* participant_index = (char*)createIndex(participant_tag, *allocator_ , sizeof(ParticipantIndex), ex); if (participant_index == 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("Initial allocation/Bind failed 2.\n"))); return -1; } exists = exists || ex; char* actor_index = (char*)createIndex(actor_tag, *allocator_ , sizeof(ActorIndex), ex); if (actor_index == 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("Initial allocation/Bind failed 2.\n"))); return -1; } exists = exists || ex; if (exists) { topic_index_ = reinterpret_cast<TopicIndex*>(topic_index); participant_index_ = reinterpret_cast<ParticipantIndex*>(participant_index); actor_index_ = reinterpret_cast<ActorIndex*>(actor_index); if (!(topic_index_ && participant_index_ && actor_index_)) { ACE_ERROR((LM_DEBUG, ACE_TEXT("Unable to narrow persistent indexes.\n"))); return -1; } } else { topic_index_ = new(topic_index) TopicIndex(allocator_); participant_index_ = new(participant_index) ParticipantIndex(allocator_); actor_index_ = new(actor_index) ActorIndex(allocator_); } if (reset_) { index_cleanup(topic_index_, allocator_); index_cleanup(participant_index_, allocator_); index_cleanup(actor_index_, allocator_); } // lastly register the callback um_->add(this); return 0; }