Use bzalloc instead of bmalloc then memset

Reduces needless code repetition and still allows for proper memory
alignment.  Cleans up the code a bit.
This commit is contained in:
jp9000
2014-02-09 12:34:07 -07:00
parent 6ffcd5e74e
commit b067440f73
32 changed files with 58 additions and 113 deletions

View File

@@ -37,9 +37,8 @@ indexbuffer_t device_create_indexbuffer(device_t device,
enum gs_index_type type, void *indices, size_t num,
uint32_t flags)
{
struct gs_index_buffer *ib = bmalloc(sizeof(struct gs_index_buffer));
struct gs_index_buffer *ib = bzalloc(sizeof(struct gs_index_buffer));
size_t width = type == GS_UNSIGNED_LONG ? sizeof(long) : sizeof(short);
memset(ib, 0, sizeof(struct gs_index_buffer));
ib->device = device;
ib->data = indices;

View File

@@ -48,8 +48,7 @@ static void gl_get_program_info(GLuint program, const char *file,
if (!gl_success("glGetProgramiv") || !info_len)
return;
errors = bmalloc(info_len+1);
memset(errors, 0, info_len+1);
errors = bzalloc(info_len+1);
glGetProgramInfoLog(program, info_len, &chars_written, errors);
gl_success("glGetProgramInfoLog");
@@ -238,11 +237,10 @@ static bool gl_shader_init(struct gs_shader *shader,
static struct gs_shader *shader_create(device_t device, enum shader_type type,
const char *shader_str, const char *file, char **error_string)
{
struct gs_shader *shader = bmalloc(sizeof(struct gs_shader));
struct gs_shader *shader = bzalloc(sizeof(struct gs_shader));
struct gl_shader_parser glsp;
bool success = true;
memset(shader, 0, sizeof(struct gs_shader));
shader->device = device;
shader->type = type;

View File

@@ -69,9 +69,7 @@ stagesurf_t device_create_stagesurface(device_t device, uint32_t width,
uint32_t height, enum gs_color_format color_format)
{
struct gs_stage_surface *surf;
surf = bmalloc(sizeof(struct gs_stage_surface));
memset(surf, 0, sizeof(struct gs_stage_surface));
surf = bzalloc(sizeof(struct gs_stage_surface));
surf->format = color_format;
surf->width = width;
surf->height = height;

View File

@@ -169,8 +169,7 @@ void convert_sampler_info(struct gs_sampler_state *sampler,
device_t device_create(struct gs_init_data *info)
{
struct gs_device *device = bmalloc(sizeof(struct gs_device));
memset(device, 0, sizeof(struct gs_device));
struct gs_device *device = bzalloc(sizeof(struct gs_device));
device->plat = gl_platform_create(device, info);
if (!device->plat)
@@ -219,8 +218,7 @@ void device_destroy(device_t device)
swapchain_t device_create_swapchain(device_t device, struct gs_init_data *info)
{
struct gs_swap_chain *swap = bmalloc(sizeof(struct gs_swap_chain));
memset(swap, 0, sizeof(struct gs_swap_chain));
struct gs_swap_chain *swap = bzalloc(sizeof(struct gs_swap_chain));
swap->device = device;
swap->info = *info;
@@ -273,8 +271,7 @@ samplerstate_t device_create_samplerstate(device_t device,
{
struct gs_sampler_state *sampler;
sampler = bmalloc(sizeof(struct gs_sampler_state));
memset(sampler, 0, sizeof(struct gs_sampler_state));
sampler = bzalloc(sizeof(struct gs_sampler_state));
sampler->device = device;
sampler->ref = 1;

View File

@@ -78,9 +78,7 @@ texture_t device_create_texture(device_t device, uint32_t width,
uint32_t height, enum gs_color_format color_format,
uint32_t levels, const void **data, uint32_t flags)
{
struct gs_texture_2d *tex = bmalloc(sizeof(struct gs_texture_2d));
memset(tex, 0, sizeof(struct gs_texture_2d));
struct gs_texture_2d *tex = bzalloc(sizeof(struct gs_texture_2d));
tex->base.device = device;
tex->base.type = GS_TEXTURE_2D;
tex->base.format = color_format;

View File

@@ -62,9 +62,7 @@ texture_t device_create_cubetexture(device_t device, uint32_t size,
enum gs_color_format color_format, uint32_t levels,
const void **data, uint32_t flags)
{
struct gs_texture_cube *tex = bmalloc(sizeof(struct gs_texture_cube));
memset(tex, 0, sizeof(struct gs_texture_2d));
struct gs_texture_cube *tex = bzalloc(sizeof(struct gs_texture_cube));
tex->base.device = device;
tex->base.type = GS_TEXTURE_CUBE;
tex->base.format = color_format;

View File

@@ -79,9 +79,7 @@ static bool create_buffers(struct gs_vertex_buffer *vb)
vertbuffer_t device_create_vertexbuffer(device_t device,
struct vb_data *data, uint32_t flags)
{
struct gs_vertex_buffer *vb = bmalloc(sizeof(struct gs_vertex_buffer));
memset(vb, 0, sizeof(struct gs_vertex_buffer));
struct gs_vertex_buffer *vb = bzalloc(sizeof(struct gs_vertex_buffer));
vb->device = device;
vb->data = data;
vb->num = data->num;

View File

@@ -337,11 +337,10 @@ static inline bool gl_setpixelformat(HDC hdc, int format,
static struct gl_windowinfo *gl_windowinfo_bare(struct gs_init_data *info)
{
struct gl_windowinfo *wi = bmalloc(sizeof(struct gl_windowinfo));
memset(wi, 0, sizeof(struct gl_windowinfo));
struct gl_windowinfo *wi = bzalloc(sizeof(struct gl_windowinfo));
wi->hwnd = info->window.hwnd;
wi->hdc = GetDC(wi->hwnd);
if (!wi->hdc) {
blog(LOG_ERROR, "Unable to get device context from window");
bfree(wi);
@@ -375,12 +374,11 @@ void gl_update(device_t device)
struct gl_platform *gl_platform_create(device_t device,
struct gs_init_data *info)
{
struct gl_platform *plat = bmalloc(sizeof(struct gl_platform));
struct gl_platform *plat = bzalloc(sizeof(struct gl_platform));
struct dummy_context dummy;
int pixel_format;
PIXELFORMATDESCRIPTOR pfd;
memset(plat, 0, sizeof(struct gl_platform));
memset(&dummy, 0, sizeof(struct dummy_context));
if (!gl_dummy_context_init(&dummy))

View File

@@ -57,9 +57,7 @@ extern struct gs_swap_chain *gl_platform_getswap(struct gl_platform *platform)
extern struct gl_windowinfo *gl_windowinfo_create(struct gs_init_data *info)
{
struct gl_windowinfo *wi = bmalloc(sizeof(struct gl_windowinfo));
memset(wi, 0, sizeof(struct gl_windowinfo));
struct gl_windowinfo *wi = bzalloc(sizeof(struct gl_windowinfo));
wi->id = info->window.id;
/* wi->display = info->window.display; */
@@ -108,13 +106,11 @@ struct gl_platform *gl_platform_create(device_t device,
int num_configs = 0;
int error_base = 0, event_base = 0;
Display *display = XOpenDisplay(NULL); /* Open default screen */
struct gl_platform *plat = bmalloc(sizeof(struct gl_platform));
struct gl_platform *plat = bzalloc(sizeof(struct gl_platform));
GLXFBConfig* configs;
print_info_stuff(info);
memset(plat, 0, sizeof(struct gl_platform));
if (!display) {
blog(LOG_ERROR, "Unable to find display. DISPLAY variable "
"may not be set correctly.");

View File

@@ -53,8 +53,7 @@ zstencil_t device_create_zstencil(device_t device, uint32_t width,
{
struct gs_zstencil_buffer *zs;
zs = bmalloc(sizeof(struct gs_zstencil_buffer));
memset(zs, 0, sizeof(struct gs_zstencil_buffer));
zs = bzalloc(sizeof(struct gs_zstencil_buffer));
zs->format = convert_zstencil_format(format);
zs->attachment = get_attachment(format);
zs->device = device;