Ejemplo n.º 1
0
static int get_path_class_ext(pString **tokens, pString arg) {   
#define EXT_TOKENS 2    

    // index last path/file separator
    int fp_index = SEND(arg, lastIndexOfChar, *file_separator);
    // index of filename/suffix separator
    int ssep_index = SEND(arg, lastIndexOfChar, '.');
    
    if(fp_index < 0) { //no new path
        return ERR_FAIL;    
    } else {
        // copy path token
        // alloc result String array
        *tokens = (pString *)internal_allocate(EXT_TOKENS * sizeof(pString));

        (*tokens)[0] = SEND(arg, substring, 0, fp_index - 1);
    }
    
    // copy filename to 2nd slot
    // strip suffix if present
    ssep_index = ( (ssep_index >= 0)  && (ssep_index > fp_index)) ?
                 (ssep_index - 1):
                 SEND(arg, length);
    // copy substring
    (*tokens)[1] = SEND(arg, substring, fp_index + 1, ssep_index);
    
    return ERR_SUCCESS;
    
}
Ejemplo n.º 2
0
/**
 * Allocate a new Hashmap
 */
pHashmap Hashmap_new(void) {
    pHashmap result = (pHashmap)internal_allocate(sizeof(Hashmap));
    if(result) {
        result->_vtable = Hashmap_vtable();
        INIT(result, HASHMAP_DEFAULT_SIZE);
    }    
    return result;    
}
Ejemplo n.º 3
0
pHashmapElem HashmapElem_new(void* k, void* v) {
    pHashmapElem result = (pHashmapElem)internal_allocate(sizeof(HashmapElem));
    if(result) {
        result->_vtable = HashmapElem_vtable();
        INIT(result, (pOOObject)k, (pOOObject)v);
    }
    return result;
}
Ejemplo n.º 4
0
Archivo: List.c Proyecto: SOM-st/CSOM
/**
 * Allocate a new List
 */
pList List_new(void) {
    pList result = (pList)internal_allocate(sizeof(List));
    if(result) {
        result->_vtable = List_vtable();
        INIT(result);        
    }    
    return result;    
}
Ejemplo n.º 5
0
Archivo: List.c Proyecto: SOM-st/CSOM
pListElem ListElem_new(void* data) {
    pListElem result = (pListElem)internal_allocate(sizeof(ListElem));
    if(result) {
        result->_vtable = ListElem_vtable();
        INIT(result, data);
    }
    return result;
}
Ejemplo n.º 6
0
void JNiftiImage2Private::copy_from(const JNiftiImage2 &X) {
	internal_allocate(X.d->m_data_type,X.d->m_N1,X.d->m_N2,X.d->m_N3,X.d->m_N4);
	for (int tt=0; tt<m_N4; tt++) {
		q->setDataXYZ(X.dataXYZ(tt),tt);
	}
	m_header_parameters=X.d->m_header_parameters;
	m_transformation=X.d->m_transformation;
}
Ejemplo n.º 7
0
void  _BigInteger_asString(pVMObject object, pVMFrame frame) {
    pVMBigInteger self = (pVMBigInteger)SEND(frame, pop);
    // temporary storage for the number string
    // use c99 snprintf-goodie
    int64_t bigint = SEND(self, get_embedded_biginteger);
    char* strbuf = (char*)internal_allocate(snprintf(0, 0, "%lld", bigint) +1);
    sprintf(strbuf, "%lld", bigint);
    SEND(frame, push, (pVMObject)Universe_new_string(strbuf));
    internal_free(strbuf);
}
Ejemplo n.º 8
0
 void allocate(const dtype& dt) {
     delete[] m_storage;
     m_storage = 0;
     if (m_metadata) {
         m_dtype.extended()->metadata_destruct(m_metadata);
         delete[] m_metadata;
         m_metadata = NULL;
     }
     m_dtype = dt;
     internal_allocate();
 }
Ejemplo n.º 9
0
/**
 * Set up the Hashmap object
 */
void _Hashmap_init(void* _self, ...) {
    pHashmap self = (pHashmap)_self;
    SUPER(OOObject, self, init);

    va_list argp;
    va_start(argp, _self);
    self->size = va_arg(argp, size_t);
    va_end(argp);
    self->elems = 
        (pHashmapElem*)internal_allocate(self->size * sizeof(pHashmapElem));
    SEND(self, clear);
}
Ejemplo n.º 10
0
 void allocate(const ndt::type &dt)
 {
   delete[] m_storage;
   m_storage = 0;
   if (m_arrmeta) {
     m_type.extended()->arrmeta_destruct(m_arrmeta);
     delete[] m_arrmeta;
     m_arrmeta = NULL;
   }
   m_type = dt;
   internal_allocate();
 }
Ejemplo n.º 11
0
void _VMArray_set_indexable_field(void* _self, int index, pVMObject value) {
    pVMArray self = (pVMArray)_self;
    //CHECK_INDEX;
    if(index >= SEND(self, get_number_of_indexable_fields) || index < 0) {
        char* s = (char*)internal_allocate(128);
        if(index >= SEND(self, get_number_of_indexable_fields))
            sprintf(s, "index too large in array access: %d", index);
        else
            sprintf(s, "index too small in array access: %d", index);
        Universe_error_exit(s);
    }
    // set the indexable field with the given index to the given value
    self->fields[index + SEND(self, _get_offset)] = value;
}
Ejemplo n.º 12
0
Archivo: Lexer.c Proyecto: SOM-st/CSOM
Lexer* Lexer_create(const FILE* fp, const char* file_name) {
  Lexer* lexer = internal_allocate(sizeof(Lexer));
  lexer->infile = (FILE*)fp;
  lexer->file_name = file_name;
  lexer->line_num = 0;
  lexer->sym = NONE;
  lexer->symc = 0;
  lexer->text[0] = 0;
  lexer->peekDone = false;
  lexer->nextSym = NONE;
  lexer->nextSymc = 0;
  lexer->nextText[0] = 0;
  lexer->buf[0] = 0;
  lexer->bufp = 0;
  return lexer;
}
Ejemplo n.º 13
0
void _Hashmap_rehash(void* _self, size_t newSize) {
    pHashmap self = (pHashmap)_self;
    size_t oldSize = self->size;
    pHashmapElem* oldElems = self->elems;
    self->size = newSize;
    self->elems = (pHashmapElem*)internal_allocate(
        self->size * sizeof(pHashmapElem));
    SEND(self, clear);
    
    for(size_t i = 0; i < oldSize; i++)
        if(oldElems[i]) {
            if(!attemptPut(self, oldElems[i],
                hashf(self, SEND(oldElems[i], key_hash))))
                // not good, can't help
                Universe_error_exit("Hashmap overflow while rehashing.\n");
            else
                oldElems[i] = NULL;
        }
            
    internal_free(oldElems);
}
Ejemplo n.º 14
0
pVMClass VMClass_assemble(class_generation_context* cgc) {
    // build class class name
    const char* cgc_name = SEND(cgc->name, get_chars);
    char* ccname =
        (char*)internal_allocate(strlen(cgc_name) + 6 + 1); // 6: " class"
    strcpy(ccname, cgc_name);
    strcat(ccname, " class");
    pVMSymbol ccname_sym = Universe_symbol_for(ccname);
    internal_free(ccname);
    
    // Load the super class
    pVMClass super_class = Universe_load_class(cgc->super_name);
    
    // Allocate the class of the resulting class
    pVMClass result_class = Universe_new_class(metaclass_class);

    // Initialize the class of the resulting class
    SEND(result_class, set_instance_fields,
         Universe_new_array_list(cgc->class_fields));
    SEND(result_class, set_instance_invokables,
         Universe_new_array_list(cgc->class_methods));
    SEND(result_class, set_name, ccname_sym);
    pVMClass super_mclass = SEND(super_class, get_class);
    SEND(result_class, set_super_class, super_mclass);
    
    // Allocate the resulting class
    pVMClass result = Universe_new_class(result_class);
    
    // Initialize the resulting class
    SEND(result, set_instance_fields,
         Universe_new_array_list(cgc->instance_fields));
    SEND(result, set_instance_invokables,
         Universe_new_array_list(cgc->instance_methods));
    SEND(result, set_name, cgc->name);
    SEND(result, set_super_class, super_class);
    
    return result;
}
Ejemplo n.º 15
0
 inline buffer_storage(const dtype& dt)
     : m_storage(NULL), m_metadata(NULL), m_dtype(dt)
 {
     internal_allocate();
 }
Ejemplo n.º 16
0
 inline buffer_storage(const buffer_storage& rhs)
     : m_storage(NULL), m_metadata(NULL), m_dtype(rhs.m_dtype)
 {
     internal_allocate();
 }
Ejemplo n.º 17
0
 inline buffer_storage(const ndt::type &tp)
     : m_storage(NULL), m_arrmeta(NULL), m_type(tp)
 {
   internal_allocate();
 }