intel/tools: move ascii85_decode to common code
We have 3 copies of this function, so put it in the shared static library. Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34118>
This commit is contained in:
@@ -261,34 +261,6 @@ struct section {
|
||||
static unsigned num_sections;
|
||||
static struct section sections[MAX_SECTIONS];
|
||||
|
||||
static int ascii85_decode(const char *in, uint32_t **out, bool inflate)
|
||||
{
|
||||
int len = 0, size = 1024;
|
||||
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
|
||||
while (*in >= '!' && *in <= 'z') {
|
||||
uint32_t v = 0;
|
||||
|
||||
if (len == size) {
|
||||
size *= 2;
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
in = ascii85_decode_char(in, &v);
|
||||
(*out)[len++] = v;
|
||||
}
|
||||
|
||||
if (!inflate)
|
||||
return len;
|
||||
|
||||
return zlib_inflate(out, len);
|
||||
}
|
||||
|
||||
static int qsort_hw_context_first(const void *a, const void *b)
|
||||
{
|
||||
const struct section *sa = a, *sb = b;
|
||||
|
||||
@@ -42,34 +42,6 @@
|
||||
|
||||
#define fail(...) fail_if(true, __VA_ARGS__)
|
||||
|
||||
static int ascii85_decode(const char *in, uint32_t **out, bool inflate)
|
||||
{
|
||||
int len = 0, size = 1024;
|
||||
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
|
||||
while (*in >= '!' && *in <= 'z') {
|
||||
uint32_t v = 0;
|
||||
|
||||
if (len == size) {
|
||||
size *= 2;
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
in = ascii85_decode_char(in, &v);
|
||||
(*out)[len++] = v;
|
||||
}
|
||||
|
||||
if (!inflate)
|
||||
return len;
|
||||
|
||||
return zlib_inflate(out, len);
|
||||
}
|
||||
|
||||
static void
|
||||
print_help(const char *progname, FILE *file)
|
||||
{
|
||||
|
||||
@@ -41,34 +41,6 @@
|
||||
|
||||
#define XE_KMD_ERROR_DUMP_IDENTIFIER "**** Xe Device Coredump ****"
|
||||
|
||||
static int ascii85_decode(const char *in, uint32_t **out, bool inflate)
|
||||
{
|
||||
int len = 0, size = 1024;
|
||||
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
|
||||
while (*in >= '!' && *in <= 'z') {
|
||||
uint32_t v = 0;
|
||||
|
||||
if (len == size) {
|
||||
size *= 2;
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
in = ascii85_decode_char(in, &v);
|
||||
(*out)[len++] = v;
|
||||
}
|
||||
|
||||
if (!inflate)
|
||||
return len;
|
||||
|
||||
return zlib_inflate(out, len);
|
||||
}
|
||||
|
||||
static void
|
||||
print_help(const char *progname, FILE *file)
|
||||
{
|
||||
|
||||
@@ -76,3 +76,31 @@ int zlib_inflate(uint32_t **ptr, int len)
|
||||
*ptr = out;
|
||||
return zstream.total_out / 4;
|
||||
}
|
||||
|
||||
int ascii85_decode(const char *in, uint32_t **out, bool inflate)
|
||||
{
|
||||
int len = 0, size = 1024;
|
||||
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
|
||||
while (*in >= '!' && *in <= 'z') {
|
||||
uint32_t v = 0;
|
||||
|
||||
if (len == size) {
|
||||
size *= 2;
|
||||
*out = realloc(*out, sizeof(uint32_t)*size);
|
||||
if (*out == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
in = ascii85_decode_char(in, &v);
|
||||
(*out)[len++] = v;
|
||||
}
|
||||
|
||||
if (!inflate)
|
||||
return len;
|
||||
|
||||
return zlib_inflate(out, len);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
const char *ascii85_decode_char(const char *in, uint32_t *v);
|
||||
|
||||
int zlib_inflate(uint32_t **ptr, int len);
|
||||
|
||||
int ascii85_decode(const char *in, uint32_t **out, bool inflate);
|
||||
|
||||
Reference in New Issue
Block a user