Exemplo n.º 1
0
Arquivo: sets.c Projeto: OPSF/uClinux
xaset_t *xaset_create(pool *work_pool, XASET_COMPARE compf) {
  xaset_t *newset = palloc(POOL(work_pool), sizeof(xaset_t));

  if (!newset) return NULL;
  newset->xas_list = NULL;
  newset->pool = POOL(work_pool);
  newset->xas_compare = compf;
  return newset;
}
Exemplo n.º 2
0
/* gets the homedir of the current user. Probably should take username as an argument */
MVMString * MVM_proc_gethomedir(MVMThreadContext *tc) {
    apr_uid_t userid = (apr_uid_t)MVM_proc_getuid(tc);
    MVMString *result;
    apr_status_t rv;
    char *namestring;
    apr_pool_t *tmp_pool;
    char *dirname;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to get user name from uid: ");
    }

    if ((rv = apr_uid_name_get(&namestring, (apr_uid_t)userid, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get user name from uid: ");
    }

    if ((rv = apr_uid_homepath_get(&dirname, namestring, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get homedir: ");
    }

    result = MVM_string_utf8_decode(tc, tc->instance->VMString, dirname, strlen(dirname));

    apr_pool_destroy(tmp_pool);

    return result;
}
Exemplo n.º 3
0
static apr_finfo_t MVM_file_info(MVMThreadContext *tc, MVMString *filename, apr_int32_t wanted) {
    apr_status_t rv;
    apr_pool_t *tmp_pool;
    apr_file_t *file_handle;
    apr_finfo_t finfo;

    char *fname = MVM_string_utf8_encode_C_string(tc, filename);

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        free(fname);
        MVM_exception_throw_apr_error(tc, rv, "Open file failed to create pool: ");
    }

    if ((rv = apr_file_open(&file_handle, (const char *)fname, APR_FOPEN_READ, APR_OS_DEFAULT, tmp_pool)) != APR_SUCCESS) {
        free(fname);
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to open file: ");
    }

    free(fname);

    if((rv = apr_file_info_get(&finfo, wanted, file_handle)) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to stat file: ");
    }

    if ((rv = apr_file_close(file_handle)) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to close filehandle: ");
    }

    return finfo;
}
Exemplo n.º 4
0
/* gets environment variable value */
MVMString * MVM_proc_getenv(MVMThreadContext *tc, MVMString *var) {
    MVMString *result;
    apr_status_t rv;
    char *varstring = MVM_string_utf8_encode_C_string(tc, var);
    char *value;
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        free(varstring);
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get env variable: ");
    }

    if ((rv = apr_env_get(&value, (const char *)varstring, tmp_pool)) != APR_SUCCESS && rv != 2) {
        free(varstring);
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get env variable: ");
    }

    /* TODO find out the define for the magic value 2 (env var not found) */
    result = MVM_string_utf8_decode(tc, tc->instance->VMString, rv == 2 ? "" : value, rv == 2 ? 0 : strlen(value));

    free(varstring);
    apr_pool_destroy(tmp_pool);

    return result;
}
Exemplo n.º 5
0
void		OvMemoryPool::report_abnormal_memory_release(OvPoolHeader* _pPoolList)
{
	if (_pPoolList)
	{
		for (;_pPoolList;_pPoolList = _pPoolList->mNext)
		{
			for (int i=0;i < STATIC_ALLOC_COUNT;i++)
			{
				OvMemHeader*	k_sequence  = NULL;
				k_sequence			=	(OvMemHeader*)(POOL(_pPoolList)+(MEM_BLOCK_SIZE*i));
				if ( k_sequence && ( k_sequence->m_pBlock && k_sequence->m_iLine != -1 ) )
				{
					OutputDebugString(
						OU::string::format(
						"=================================================\n"
						"[Block: %8s]\n"
						"[Line: %5d]\n"
						"[Size: %5d Byte]\n"
						"[Address: %p]\n"
						"=================================================\n"
						,k_sequence->m_pBlock
						,k_sequence->m_iLine
						,m_stTypeIndexFromMemSize
						,MEMORY(k_sequence)
						).c_str()
						);
				}
			}
		}
	}
}
Exemplo n.º 6
0
bool		OvMemoryPool::add_pool()
{
	// MEM_POOL_SIZE澗 古滴稽陥.
	// MEM_POOL_SIZE = ( 眼雁滴奄 * 奄沙拝雁遂姐呪(256鯵稽 績税竺舛) ) + sizeof(OvPoolHeader)
	OvPoolHeader*	k_pool = (OvPoolHeader*)malloc(sizeof(BYTE)*MEM_POOL_SIZE);
	
	// 搾闘級聖 0生稽 熟 舛軒, 瓜戚 照背操亀 鞠走幻 重持焼艦猿.
	memset(k_pool,0,sizeof(BYTE)*MEM_POOL_SIZE);
	OvPoolHeader*	k_search = NULL;

	// 軒什闘拭 蓄亜. 戚背亜 照亜檎 益顕生稽 背左檎 岩, 榎号蟹紳陥.
	// 尻衣幻 吉陥.
	k_pool->mNext	=	m_pPoolList;
	m_pPoolList		=	k_pool;

	// 紫遂 亜管廃 五乞軒攻帖研 企奄五乞軒 匂昔斗拭 実特廃陥.
	m_pFreeMemoryList	=	(OvMemHeader*)POOL(k_pool);
	OvMemHeader*	k_sequence  = NULL;
	// 拝舘吉 五乞軒攻帖 = ( 眼雁滴奄 * 奄沙拝雁遂姐呪(256鯵稽 績税竺舛) )
	// 研 紫遂亜管馬惟 ( sizeof(OvMemHeader) + 眼雁滴奄 )稽 促牽壱,
	// OvMemHeader研 是廃 蒋楕 4郊戚闘継 戚推背辞 辞稽研 広澗陥.
	for (int i=0;i<(STATIC_ALLOC_COUNT - 1);i++)
	{
		k_sequence			=	(OvMemHeader*)(POOL(k_pool)+(MEM_BLOCK_SIZE*i));
		k_sequence->mNext	=	(OvMemHeader*)(POOL(k_pool)+(MEM_BLOCK_SIZE*(i+1)));
#ifdef _DEBUG
		k_sequence->m_pBlock=	NULL;
		k_sequence->m_iLine	=	-1;
#endif
	}
#ifdef _DEBUG
	g_dMemoryCount++;
	OutputDebugString(OU::string::format("Olive Memory Pool Report Alloc(%8d byte) CallCount: %4d\n",MEM_POOL_SIZE,g_dMemoryCount).c_str());
#endif
	return true;
}
Exemplo n.º 7
0
Shader::~Shader()
{
	cleanShaderProgram(m_shaderProgram, m_vertexShader, m_fragmentShader);

	SAFE_RELEASE(m_name);
	SAFE_RELEASE(m_strVertexShader);
	SAFE_RELEASE(m_strFragmentShader);

	for (int i = 0; i < m_uniforms->count(); ++i)
	{
		ByteArray* str = m_uniforms->get(i).sValueName;
		SAFE_RELEASE(str);
	}
	POOL(Array<SPVRTPFXUniform>)->deallocate(m_uniforms);
}
Exemplo n.º 8
0
/* open a filehandle; takes a type object */
MVMObject * MVM_file_open_fh(MVMThreadContext *tc, MVMString *filename, MVMString *mode) {
    MVMOSHandle *result;
    apr_status_t rv;
    apr_pool_t *tmp_pool;
    apr_file_t *file_handle;
    apr_int32_t flag;
    MVMObject *type_object = tc->instance->boot_types->BOOTIO;
    char *fname = MVM_string_utf8_encode_C_string(tc, filename);
    char *fmode;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        free(fname);
        MVM_exception_throw_apr_error(tc, rv, "Open file failed to create pool: ");
    }

    fmode = MVM_string_utf8_encode_C_string(tc, mode);

    /* generate apr compatible open mode flags */
    if (0 == strcmp("r", fmode))
        flag = APR_FOPEN_READ;
    else if (0 == strcmp("w", fmode))
        flag = APR_FOPEN_WRITE|APR_FOPEN_CREATE|APR_FOPEN_TRUNCATE;
    else if (0 == strcmp("wa", fmode))
        flag = APR_FOPEN_WRITE|APR_FOPEN_CREATE|APR_FOPEN_APPEND;
    else
        MVM_exception_throw_adhoc(tc, "invalid open mode: %d", fmode);

    /* try to open the file */
    if ((rv = apr_file_open(&file_handle, (const char *)fname, flag, APR_OS_DEFAULT, tmp_pool)) != APR_SUCCESS) {
        free(fname);
        free(fmode);
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to open file: ");
    }

    /* initialize the object */
    result = (MVMOSHandle *)REPR(type_object)->allocate(tc, STABLE(type_object));

    result->body.file_handle = file_handle;
    result->body.handle_type = MVM_OSHANDLE_FILE;
    result->body.mem_pool = tmp_pool;
    result->body.encoding_type = MVM_encoding_type_utf8;

    free(fname);
    free(fmode);
    return (MVMObject *)result;
}
Exemplo n.º 9
0
/* read all of a filehandle into a string. */
MVMString * MVM_file_readall_fh(MVMThreadContext *tc, MVMObject *oshandle) {
    MVMString *result;
    apr_status_t rv;
    MVMOSHandle *handle;
    apr_finfo_t finfo;
    apr_pool_t *tmp_pool;
    char *buf;
    MVMint64 bytes_read;

    /* XXX TODO length currently means bytes. alter it to mean graphemes. */
    /* XXX TODO handle length == -1 to mean read to EOF */

    verify_filehandle_type(tc, oshandle, &handle, "Readall from filehandle");

    ENCODING_VALID(handle->body.encoding_type);

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Readall failed to create pool: ");
    }

    if ((rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, handle->body.file_handle)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Readall failed to get info about file: ");
    }
    apr_pool_destroy(tmp_pool);

    if (finfo.size > 0) {
        buf = malloc(finfo.size);
        bytes_read = finfo.size;

        if ((rv = apr_file_read(handle->body.file_handle, buf, (apr_size_t *)&bytes_read)) != APR_SUCCESS) {
            free(buf);
            MVM_exception_throw_apr_error(tc, rv, "Readall from filehandle failed: ");
        }
                                                   /* XXX should this take a type object? */
        result = MVM_decode_C_buffer_to_string(tc, tc->instance->VMString, buf, bytes_read, handle->body.encoding_type);
        free(buf);
    }
    else {
        result = (MVMString *)REPR(tc->instance->VMString)->allocate(tc, STABLE(tc->instance->VMString));
    }

    return result;
}
Exemplo n.º 10
0
/* gets the gid of the calling process */
MVMint64 MVM_proc_getgid(MVMThreadContext *tc) {
    apr_status_t rv;
    apr_uid_t userid;
    apr_gid_t groupid;
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to get current gid: ");
    }

    if ((rv = apr_uid_current(&userid, &groupid, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get current gid: ");
    }

    apr_pool_destroy(tmp_pool);
    return (MVMint64)groupid;
}
Exemplo n.º 11
0
/* gets the current encoding of the system */
MVMString * MVM_proc_getencoding(MVMThreadContext *tc) {
    MVMString *result;
    apr_status_t rv;
    apr_pool_t *tmp_pool;
    char *encoding;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to get encoding: ");
    }

    encoding = (char *)apr_os_locale_encoding(tmp_pool);

    result = MVM_string_utf8_decode(tc, tc->instance->VMString, encoding, strlen(encoding));

    apr_pool_destroy(tmp_pool);

    return result;
}
Exemplo n.º 12
0
MVMint64 MVM_file_exists(MVMThreadContext *tc, MVMString *f) {
    apr_status_t rv;
    char *a;
    apr_finfo_t  stat_info;
    apr_pool_t *tmp_pool;
    MVMint64 result;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to exists file: ");
    }

    a = MVM_string_utf8_encode_C_string(tc, f);

    result = ((rv = apr_stat(&stat_info, (const char *)a, APR_FINFO_SIZE, tmp_pool)) == APR_SUCCESS)
        ? 1 : 0;
    free(a);
    apr_pool_destroy(tmp_pool);
    return result;
}
Exemplo n.º 13
0
/* delete environment variable */
void MVM_proc_delenv(MVMThreadContext *tc, MVMString *var) {
    apr_status_t rv;
    char *varstring = MVM_string_utf8_encode_C_string(tc, var);
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        free(varstring);
        MVM_exception_throw_apr_error(tc, rv, "Failed to delete env variable: ");
    }

    if ((rv = apr_env_delete((const char *)varstring, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        free(varstring);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get delete variable: ");
    }

    apr_pool_destroy(tmp_pool);
    free(varstring);
}
Exemplo n.º 14
0
/* rename one file to another. */
void MVM_file_rename(MVMThreadContext *tc, MVMString *src, MVMString *dest) {
    apr_status_t rv;
    char *a, *b, *afull, *bfull;
    MVMuint32 len;
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to rename file: ");
    }

    afull = MVM_file_get_full_path(tc, tmp_pool, a = MVM_string_utf8_encode_C_string(tc, src));
    bfull = MVM_file_get_full_path(tc, tmp_pool, b = MVM_string_utf8_encode_C_string(tc, dest));
    free(a); free(b);

    if ((rv = apr_file_rename((const char *)afull, (const char *)bfull, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to rename file: ");
    }
    apr_pool_destroy(tmp_pool);
}
Exemplo n.º 15
0
/* translates groupid to groupname */
MVMString * MVM_proc_gidtoname(MVMThreadContext *tc, MVMint64 groupid) {
    MVMString *result;
    apr_status_t rv;
    char *namestring;
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to get group name from gid: ");
    }

    if ((rv = apr_gid_name_get(&namestring, (apr_gid_t)groupid, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get group name from gid: ");
    }

    result = MVM_string_utf8_decode(tc, tc->instance->VMString, namestring, strlen(namestring));

    apr_pool_destroy(tmp_pool);

    return result;
}
Exemplo n.º 16
0
void MVM_file_delete(MVMThreadContext *tc, MVMString *f) {
    apr_status_t rv;
    char *a;
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to delete file: ");
    }

    a = MVM_string_utf8_encode_C_string(tc, f);

    /* 720002 means file wasn't there on windows, 2 on linux...  */
    /* TODO find defines for these and make it os-specific */
    if ((rv = apr_file_remove((const char *)a, tmp_pool)) != APR_SUCCESS && rv != 720002 && rv != 2) {
        free(a);
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to delete file: ");
    }
    free(a);
    apr_pool_destroy(tmp_pool);
}
Exemplo n.º 17
0
/* translates groupname to groupid */
MVMint64 MVM_proc_nametogid(MVMThreadContext *tc, MVMString *name) {
    apr_status_t rv;
    apr_gid_t groupid;
    char *namestring = MVM_string_utf8_encode_C_string(tc, name);
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        free(namestring);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get gid from group name: ");
    }

    if ((rv = apr_gid_get(&groupid, (const char *)namestring, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        free(namestring);
        MVM_exception_throw_apr_error(tc, rv, "Failed to get gid from group name: ");
    }

    apr_pool_destroy(tmp_pool);
    free(namestring);

    return (MVMint64)groupid;
}
Exemplo n.º 18
0
/* append one file to another. */
void MVM_file_append(MVMThreadContext *tc, MVMString *src, MVMString *dest) {
    apr_status_t rv;
    char *a, *b, *afull, *bfull;
    MVMuint32 len;
    apr_pool_t *tmp_pool;

    /* need a temporary pool */
    if ((rv = apr_pool_create(&tmp_pool, POOL(tc))) != APR_SUCCESS) {
        MVM_exception_throw_apr_error(tc, rv, "Failed to append file: ");
    }

    afull = MVM_file_get_full_path(tc, tmp_pool, a = MVM_string_utf8_encode_C_string(tc, src));
    bfull = MVM_file_get_full_path(tc, tmp_pool, b = MVM_string_utf8_encode_C_string(tc, dest));
    free(a); free(b);

    if ((rv = apr_file_append((const char *)afull, (const char *)bfull,
            APR_FPROT_FILE_SOURCE_PERMS, tmp_pool)) != APR_SUCCESS) {
        apr_pool_destroy(tmp_pool);
        MVM_exception_throw_apr_error(tc, rv, "Failed to append file: ");
    }
    /* note: destroying the pool deallocates afull, bfull */
    apr_pool_destroy(tmp_pool);
}
Exemplo n.º 19
0
void ByteArray::destroy()
{
	this->~ByteArray();
	POOL(ByteArray)->deallocate(this);
}
Exemplo n.º 20
0
void RenderTexture::destroy()
{
	this->~RenderTexture();
	POOL(RenderTexture)->deallocate(this);
}
Exemplo n.º 21
0
void VertexList::destroy()
{
	this->~VertexList();
	POOL(VertexList)->deallocate(this);
}
Exemplo n.º 22
0
void Shader::destroy()
{
	this->~Shader();
	POOL(Shader)->deallocate(this);
}
Exemplo n.º 23
0
void Transform::destroy()
{
    this->~Transform();
    POOL(Transform)->deallocate(this);
}
Exemplo n.º 24
0
void Camera::destroy()
{
	this->~Camera();
	POOL(Camera)->deallocate(this);
}