<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 14, 2016 at 7:59 AM, Juha-Pekka Heikkila <span dir="ltr"><<a href="mailto:juhapekka.heikkila@gmail.com" target="_blank">juhapekka.heikkila@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">ralloc originally had had idea of using malloc but somehow<br>
had slipped in calloc. Without these changes rzalloc did double<br>
job of zeroing the memory, first calloc and then memset.<br>
Now change ralloc to use malloc, leave rzalloc to use calloc and<br>
make needed changes in ralloc functions to get things working.<br>
<br>
Signed-off-by: Juha-Pekka Heikkila <<a href="mailto:juhapekka.heikkila@gmail.com">juhapekka.heikkila@gmail.com</a>><br>
---<br>
src/util/ralloc.c | 49 +++++++++++++++++++++++++++++++++----------------<br>
src/util/ralloc.h | 2 +-<br>
2 files changed, 34 insertions(+), 17 deletions(-)<br>
<br>
diff --git a/src/util/ralloc.c b/src/util/ralloc.c<br>
index 9526011..527385d 100644<br>
--- a/src/util/ralloc.c<br>
+++ b/src/util/ralloc.c<br>
@@ -104,25 +104,12 @@ add_child(ralloc_header *parent, ralloc_header *info)<br>
void *<br>
ralloc_context(const void *ctx)<br>
{<br>
- return ralloc_size(ctx, 0);<br>
+ return rzalloc_size(ctx, 0);<br>
}<br>
<br>
-void *<br>
-ralloc_size(const void *ctx, size_t size)<br>
-{<br>
- /* ralloc_size was originally implemented using calloc, which meant some<br>
- * code accidentally relied on its zero filling behavior.<br>
- *<br>
- * TODO: Make ralloc_size not zero fill memory, and cleanup any code that<br>
- * should instead be using rzalloc.<br>
- */<br>
- return rzalloc_size(ctx, size);<br>
-}<br>
-<br>
-void *<br>
-rzalloc_size(const void *ctx, size_t size)<br>
+static void*<br>
+ralloc_header_helper(const void *ctx, const void *block)<br>
{<br>
- void *block = calloc(1, size + sizeof(ralloc_header));<br>
ralloc_header *info;<br>
ralloc_header *parent;<br>
<br>
@@ -131,6 +118,12 @@ rzalloc_size(const void *ctx, size_t size)<br>
info = (ralloc_header *) block;<br>
parent = ctx != NULL ? get_header(ctx) : NULL;<br>
<br>
+ info->child = NULL;<br>
+ info->parent = NULL;<br>
+ info->prev = NULL;<br>
+ info->next = NULL;<br>
+ info->destructor = NULL;<br>
+<br>
add_child(parent, info);<br>
<br>
#ifdef DEBUG<br>
@@ -140,6 +133,30 @@ rzalloc_size(const void *ctx, size_t size)<br>
return PTR_FROM_HEADER(info);<br>
}<br>
<br>
+void *<br>
+ralloc_size(const void *ctx, size_t size)<br>
+{<br>
+ void *block;<br>
+<br>
+ if (size + sizeof(ralloc_header) < size )<br>
+ return NULL;<br>
+<br>
+ block = malloc(size + sizeof(ralloc_header));<br></blockquote><div><br></div><div>One more thing that I think I'd like to see you try is to add<br><br></div><div>memset(block, 139, size + sizeof(ralloc_header));<br><br></div><div>right here and see if everything still works. Frequently malloc will return zerod memory and we'd like to be 100% sure that isn't a problem. For that matter, I think it'd be good to just put that inside of a "#ifndef NDEBUG" and leave it so that it gets tested in debug builds.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ return ralloc_header_helper(ctx, block);<br>
+}<br>
+<br>
+void *<br>
+rzalloc_size(const void *ctx, size_t size)<br>
+{<br>
+ void *block;<br>
+<br>
+ if (size + sizeof(ralloc_header) < size )<br>
+ return NULL;<br>
+<br>
+ block = calloc(1, size + sizeof(ralloc_header));<br>
+ return ralloc_header_helper(ctx, block);<br>
+}<br>
+<br>
/* helper function - assumes ptr != NULL */<br>
static void *<br>
resize(void *ptr, size_t size)<br>
diff --git a/src/util/ralloc.h b/src/util/ralloc.h<br>
index 7587e11..462db7d 100644<br>
--- a/src/util/ralloc.h<br>
+++ b/src/util/ralloc.h<br>
@@ -430,7 +430,7 @@ private: \<br>
public: \<br>
static void* operator new(size_t size, void *mem_ctx) \<br>
{ \<br>
- void *p = ralloc_size(mem_ctx, size); \<br>
+ void *p = rzalloc_size(mem_ctx, size); \<br>
assert(p != NULL); \<br>
if (!HAS_TRIVIAL_DESTRUCTOR(TYPE)) \<br>
ralloc_set_destructor(p, _ralloc_destructor); \<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>