Commit 120d0513 authored by m4xw's avatar m4xw
Browse files

git subrepo clone --force ../libretro-common-mupen64plus-nx libretro-common/

subrepo:
  subdir:   "libretro-common"
  merged:   "59e3f6af"
upstream:
  origin:   "../libretro-common-mupen64plus-nx"
  branch:   "master"
  commit:   "59e3f6af"
git-subrepo:
  version:  "0.4.0"
  origin:   "???"
  commit:   "???"
parent 5cbca0e5
glsm/
*.o
*.[od]
*.dll
*.so
*.dylib
......
......@@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/libretro-fork/libretro-common-mupen64plus-nx.git
branch = master
commit = 592927e3e1263ab5983d78aa3a23de77b10440ca
parent = ecfc77e9a49617d25b683aec7a8217bd044cfc6a
commit = 59e3f6afd6d31286c3bb3f67a61ae1d8b6a4af06
parent = 5cbca0e53e256648bec89c830482c9b837e392bc
method = rebase
cmdver = 0.4.0
OBJDIR = ../obj-unix
TEST_UNIT_CFLAGS = $(CFLAGS) -Iinclude $(LDFLAGS) -lcheck $(LIBCHECK_CFLAGS) -Werror -Wdeclaration-after-statement -fsanitize=address -fsanitize=undefined -ftest-coverage -fprofile-arcs -ggdb
TEST_GENERIC_QUEUE = test/queues/test_generic_queue
TEST_GENERIC_QUEUE_SRC = test/queues/test_generic_queue.c queues/generic_queue.c
TEST_LINKED_LIST = test/lists/test_linked_list
TEST_LINKED_LIST_SRC = test/lists/test_linked_list.c lists/linked_list.c
TEST_STDSTRING = test/string/test_stdstring
TEST_STDSTRING_SRC = test/string/test_stdstring.c string/stdstring.c encodings/encoding_utf.c \
compat/compat_strl.c
TEST_UTILS = test/utils/test_utils
TEST_UTILS_SRC = test/utils/test_utils.c utils/md5.c encodings/encoding_crc32.c \
streams/file_stream.c vfs/vfs_implementation.c file/file_path.c \
compat/compat_strl.c time/rtime.c string/stdstring.c encodings/encoding_utf.c
TEST_HASH = test/hash/test_hash
TEST_HASH_SRC = test/hash/test_hash.c hash/lrc_hash.c \
streams/file_stream.c vfs/vfs_implementation.c file/file_path.c \
compat/compat_strl.c time/rtime.c string/stdstring.c encodings/encoding_utf.c
all:
# Build and execute tests in order, to avoid coverage file collision
# string
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_STDSTRING_SRC) -o $(TEST_STDSTRING)
$(TEST_STDSTRING)
lcov -c -d . -o `dirname $(TEST_STDSTRING)`/coverage.info
# utils
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_UTILS_SRC) -o $(TEST_UTILS)
$(TEST_UTILS)
lcov -c -d . -o `dirname $(TEST_UTILS)`/coverage.info
# utils
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_HASH_SRC) -o $(TEST_HASH)
$(TEST_HASH)
lcov -c -d . -o `dirname $(TEST_HASH)`/coverage.info
# list
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_LINKED_LIST_SRC) -o $(TEST_LINKED_LIST)
$(TEST_LINKED_LIST)
lcov -c -d . -o `dirname $(TEST_LINKED_LIST)`/coverage.info
# queue
$(CC) $(TEST_UNIT_CFLAGS) $(TEST_GENERIC_QUEUE_SRC) -o $(TEST_GENERIC_QUEUE)
$(TEST_GENERIC_QUEUE)
lcov -c -d . -o `dirname $(TEST_GENERIC_QUEUE)`/coverage.info
lcov -o test/coverage.info \
-a test/utils/coverage.info \
-a test/string/coverage.info \
-a test/lists/coverage.info \
-a test/queues/coverage.info
genhtml -o test/coverage/ test/coverage.info
clean:
rm -f *.gcda *.gcno
......@@ -25,6 +25,8 @@
#include <string.h>
#include <memalign.h>
#include <retro_environment.h>
#if defined(__SSE2__)
#include <emmintrin.h>
#elif defined(__ALTIVEC__)
......
......@@ -328,14 +328,21 @@ audio_mixer_sound_t* audio_mixer_load_wav(void *buffer, int32_t size)
#ifdef HAVE_RWAV
/* WAV data */
rwav_t wav;
enum rwav_state rwav_ret;
/* WAV samples converted to float */
float* pcm = NULL;
size_t samples = 0;
/* Result */
audio_mixer_sound_t* sound = NULL;
enum rwav_state rwav_ret = rwav_load(&wav, buffer, size);
if (rwav_ret != RWAV_ITERATE_DONE)
wav.bitspersample = 0;
wav.numchannels = 0;
wav.samplerate = 0;
wav.numsamples = 0;
wav.subchunk2size = 0;
wav.samples = NULL;
if ((rwav_ret = rwav_load(&wav, buffer, size)) != RWAV_ITERATE_DONE)
return NULL;
samples = wav.numsamples * 2;
......@@ -991,18 +998,15 @@ static void audio_mixer_mix_mod(float* buffer, size_t num_frames,
{
int i;
float samplef = 0.0f;
int samplei = 0;
unsigned temp_samples = 0;
unsigned buf_free = (unsigned)(num_frames * 2);
int* pcm = NULL;
if (voice->types.mod.position == voice->types.mod.samples)
if (voice->types.mod.samples == 0)
{
again:
temp_samples = replay_get_audio(
voice->types.mod.stream, voice->types.mod.buffer );
temp_samples *= 2; /* stereo */
voice->types.mod.stream, voice->types.mod.buffer, 0 ) * 2;
if (temp_samples == 0)
{
......@@ -1031,10 +1035,9 @@ again:
{
for (i = voice->types.mod.samples; i != 0; i--)
{
samplei = *pcm++ * volume;
samplef = (float)((int)samplei + 32768) / 65535.0f;
samplef = ((float)(*pcm++) + 32768.0f) / 65535.0f;
samplef = samplef * 2.0f - 1.0f;
*buffer++ += samplef;
*buffer++ += samplef * volume;
}
buf_free -= voice->types.mod.samples;
......@@ -1043,10 +1046,9 @@ again:
for (i = buf_free; i != 0; --i )
{
samplei = *pcm++ * volume;
samplef = (float)((int)samplei + 32768) / 65535.0f;
samplef = ((float)(*pcm++) + 32768.0f) / 65535.0f;
samplef = samplef * 2.0f - 1.0f;
*buffer++ += samplef;
*buffer++ += samplef * volume;
}
voice->types.mod.position += buf_free;
......
......@@ -28,10 +28,16 @@
#include <altivec.h>
#endif
#if (defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)) || defined(HAVE_NEON)
#ifndef HAVE_ARM_NEON_OPTIMIZATIONS
#define HAVE_ARM_NEON_OPTIMIZATIONS
#endif
#endif
#include <features/features_cpu.h>
#include <audio/conversion/float_to_s16.h>
#if defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)
#if defined(HAVE_ARM_NEON_OPTIMIZATIONS)
static bool float_to_s16_neon_enabled = false;
void convert_float_s16_asm(int16_t *out, const float *in, size_t samples);
#endif
......@@ -91,7 +97,7 @@ void convert_float_to_s16(int16_t *out,
samples = samples_in;
i = 0;
#elif defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)
#elif defined(HAVE_ARM_NEON_OPTIMIZATIONS)
if (float_to_s16_neon_enabled)
{
size_t aligned_samples = samples & ~7;
......@@ -151,7 +157,7 @@ void convert_float_to_s16(int16_t *out,
**/
void convert_float_to_s16_init_simd(void)
{
#if defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)
#if defined(HAVE_ARM_NEON_OPTIMIZATIONS)
unsigned cpu = cpu_features_get();
if (cpu & RETRO_SIMD_NEON)
......
......@@ -29,7 +29,13 @@
#include <features/features_cpu.h>
#include <audio/conversion/s16_to_float.h>
#if defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)
#if (defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)) || defined(HAVE_NEON)
#ifndef HAVE_ARM_NEON_OPTIMIZATIONS
#define HAVE_ARM_NEON_OPTIMIZATIONS
#endif
#endif
#if defined(HAVE_ARM_NEON_OPTIMIZATIONS)
static bool s16_to_float_neon_enabled = false;
/* Avoid potential hard-float/soft-float ABI issues. */
......@@ -98,7 +104,7 @@ void convert_s16_to_float(float *out,
samples = samples_in;
i = 0;
#elif defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)
#elif defined(HAVE_ARM_NEON_OPTIMIZATIONS)
if (s16_to_float_neon_enabled)
{
size_t aligned_samples = samples & ~7;
......@@ -181,7 +187,7 @@ void convert_s16_to_float(float *out,
**/
void convert_s16_to_float_init_simd(void)
{
#if defined(__ARM_NEON__) && !defined(DONT_WANT_ARM_OPTIMIZATIONS)
#if defined(HAVE_ARM_NEON_OPTIMIZATIONS)
unsigned cpu = cpu_features_get();
if (cpu & RETRO_SIMD_NEON)
......
......@@ -50,6 +50,45 @@ else ifeq ($(platform), osx)
compiler := $(CC)
DYLIB = dylib
ldflags := -dynamiclib
ARCHFLAGS=
MINVERFLAGS=
ifeq ($(shell uname -p),arm)
MINVERFLAGS = -mmacosx-version-min=10.15 -stdlib=libc++ # macOS (Metal, ARM 64bit)
MINVERFLAGS += -DDONT_WANT_ARM_OPTIMIZATIONS
else ifeq ($(HAVE_METAL),1)
MINVERFLAGS = -mmacosx-version-min=10.13 -stdlib=libc++ # macOS (Metal, x86 64bit)
else ifeq ($(shell uname -p),powerpc)
MINVERFLAGS = -mmacosx-version-min=10.5 # macOSX (PowerPC 32-bit)
else ifeq ($(shell uname -m),i386)
MINVERFLAGS = -mmacosx-version-min=10.6 # macOSX (OpenGL, x86 32bit)
else
MINVERFLAGS = -mmacosx-version-min=10.7 -stdlib=libc++ # macOSX (OpenGL, x86 64bit)
endif
# Build for a specific architecture when ARCH is defined as a switch
ifeq ($(ARCH),arm64)
MINVERFLAGS = -mmacosx-version-min=10.15 -stdlib=libc++ # macOS (Metal, ARM 64bit)
MINVERFLAGS += -DDONT_WANT_ARM_OPTIMIZATIONS
ARCHFLAGS = -arch arm64
else ifeq ($(ARCH),x86_64)
ifeq ($(HAVE_METAL),1)
MINVERFLAGS = -mmacosx-version-min=10.13 -stdlib=libc++
else
MINVERFLAGS = -mmacosx-version-min=10.7 -stdlib=libc++
endif
ARCHFLAGS = -arch x86_64
else ifeq ($(ARCH),x86)
MINVERFLAGS = -mmacosx-version-min=10.6
ARCHFLAGS = -arch x86
else ifeq ($(ARCH),ppc)
MINVERFLAGS = -mmacosx-version-min=10.5
ARCHFLAGS = -arch ppc
endif
ifeq ($(BUILDBOT),1)
ARCHFLAGS = -target $(LIBRETRO_APPLE_PLATFORM) -isysroot $(LIBRETRO_APPLE_ISYSROOT)
endif
extraflags += $(MINVERFLAGS) $(ARCHFLAGS)
ldflags += $(MINVERFLAGS) $(ARCHFLAGS)
else
extra_flags += -static-libgcc -static-libstdc++
DYLIB = dll
......
......@@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <compat/strl.h>
#include <compat/strcasestr.h>
#include <retro_math.h>
#include <retro_timers.h>
#include <streams/file_stream.h>
......
......@@ -49,9 +49,14 @@ void *fopen_utf8(const char * filename, const char * mode)
#else
wchar_t * filename_w = utf8_to_utf16_string_alloc(filename);
wchar_t * mode_w = utf8_to_utf16_string_alloc(mode);
FILE* ret = _wfopen(filename_w, mode_w);
free(filename_w);
free(mode_w);
FILE* ret = NULL;
if (filename_w && mode_w)
ret = _wfopen(filename_w, mode_w);
if (filename_w)
free(filename_w);
if (mode_w)
free(mode_w);
return ret;
#endif
}
......
......@@ -100,8 +100,6 @@ dylib_t dylib_load(const char *path)
path_wide = utf8_to_utf16_string_alloc(relative_path);
lib = LoadPackagedLibrary(path_wide, 0);
free(path_wide);
free(relative_path_abbrev);
#elif defined(LEGACY_WIN32)
dylib_t lib = LoadLibrary(path);
#else
......
......@@ -43,12 +43,12 @@
#include <lv2/systime.h>
#endif
#if defined(__CELLOS_LV2__)
#ifndef _PPU_INTRINSICS_H
#include <ppu_intrinsics.h>
#endif
#elif defined(_XBOX360)
#if defined(_XBOX360)
#include <PPCIntrinsics.h>
#elif !defined(__MACH__) && (defined(__POWERPC__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC64__) || defined(__powerpc64__))
#ifndef _PPU_INTRINSICS_H
#include <ppu_intrinsics.h>
#endif
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(ANDROID) || defined(__QNX__) || defined(DJGPP)
/* POSIX_MONOTONIC_CLOCK is not being defined in Android headers despite support being present. */
#include <time.h>
......@@ -60,7 +60,13 @@
#if defined(PSP)
#include <pspkernel.h>
#endif
#if defined(PSP) || defined(__PSL1GHT__)
#include <sys/time.h>
#endif
#if defined(PSP)
#include <psprtc.h>
#endif
......@@ -73,9 +79,7 @@
#include <ps2sdkapi.h>
#endif
#if defined(__PSL1GHT__)
#include <sys/time.h>
#elif defined(__CELLOS_LV2__)
#if !defined(__PSL1GHT__) && defined(__PS3__)
#include <sys/sys_time.h>
#endif
......@@ -169,7 +173,11 @@ retro_perf_tick_t cpu_features_get_perf_counter(void)
tv_sec = (long)((ularge.QuadPart - epoch) / 10000000L);
tv_usec = (long)(system_time.wMilliseconds * 1000);
time_ticks = (1000000 * tv_sec + tv_usec);
#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__)
#elif defined(GEKKO)
time_ticks = gettime();
#elif !defined(__MACH__) && (defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) || defined(__PSL1GHT__) || defined(__PPC64__) || defined(__powerpc64__))
time_ticks = __mftb();
#elif (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0) || defined(__QNX__) || defined(ANDROID)
struct timespec tv = {0};
if (ra_clock_gettime(CLOCK_MONOTONIC, &tv) == 0)
time_ticks = (retro_perf_tick_t)tv.tv_sec * 1000000000 +
......@@ -183,10 +191,8 @@ retro_perf_tick_t cpu_features_get_perf_counter(void)
time_ticks = (retro_perf_tick_t)a | ((retro_perf_tick_t)d << 32);
#elif defined(__ARM_ARCH_6__)
__asm__ volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(time_ticks) );
#elif defined(__CELLOS_LV2__) || defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) || defined(__PSL1GHT__)
time_ticks = __mftb();
#elif defined(GEKKO)
time_ticks = gettime();
#elif defined(__aarch64__)
__asm__ volatile( "mrs %0, cntvct_el0" : "=r"(time_ticks) );
#elif defined(PSP) || defined(VITA)
time_ticks = sceKernelGetSystemTimeWide();
#elif defined(PS2)
......@@ -226,7 +232,7 @@ retro_time_t cpu_features_get_time_usec(void)
return (count.QuadPart / freq.QuadPart * 1000000) + (count.QuadPart % freq.QuadPart * 1000000 / freq.QuadPart);
#elif defined(__PSL1GHT__)
return sysGetSystemTime();
#elif defined(__CELLOS_LV2__)
#elif !defined(__PSL1GHT__) && defined(__PS3__)
return sys_time_get_system_time();
#elif defined(GEKKO)
return ticks_to_microsecs(gettime());
......@@ -318,6 +324,7 @@ static uint64_t xgetbv_x86(uint32_t idx)
#endif
#if defined(__ARM_NEON__)
#if defined(__arm__)
static void arm_enable_runfast_mode(void)
{
/* RunFast mode. Enables flush-to-zero and some
......@@ -335,6 +342,7 @@ static void arm_enable_runfast_mode(void)
);
}
#endif
#endif
#if defined(__linux__) && !defined(CPU_X86)
static unsigned char check_arm_cpu_feature(const char* feature)
......@@ -492,8 +500,10 @@ unsigned cpu_features_get_core_amount(void)
return sysinfo.dwNumberOfProcessors;
#elif defined(GEKKO)
return 1;
#elif defined(PSP) || defined(PS2) || defined(__CELLOS_LV2__)
#elif defined(PSP) || defined(PS2)
return 1;
#elif defined(__PSL1GHT__) || !defined(__PSL1GHT__) && defined(__PS3__)
return 1; /* Only one PPU, SPUs don't really count */
#elif defined(VITA)
return 4;
#elif defined(HAVE_LIBNX) || defined(SWITCH)
......@@ -592,16 +602,18 @@ uint64_t cpu_features_get(void)
#endif
#if defined(__MACH__)
size_t len = sizeof(size_t);
if (sysctlbyname("hw.optional.mmx", NULL, &len, NULL, 0) == 0)
if (sysctlbyname("hw.optional.floatingpoint", NULL, &len, NULL, 0) == 0)
{
cpu |= RETRO_SIMD_MMX;
cpu |= RETRO_SIMD_MMXEXT;
cpu |= RETRO_SIMD_CMOV;
}
#if defined(CPU_X86)
len = sizeof(size_t);
if (sysctlbyname("hw.optional.floatingpoint", NULL, &len, NULL, 0) == 0)
if (sysctlbyname("hw.optional.mmx", NULL, &len, NULL, 0) == 0)
{
cpu |= RETRO_SIMD_CMOV;
cpu |= RETRO_SIMD_MMX;
cpu |= RETRO_SIMD_MMXEXT;
}
len = sizeof(size_t);
......@@ -644,10 +656,19 @@ uint64_t cpu_features_get(void)
if (sysctlbyname("hw.optional.altivec", NULL, &len, NULL, 0) == 0)
cpu |= RETRO_SIMD_VMX;
#else
len = sizeof(size_t);
if (sysctlbyname("hw.optional.neon", NULL, &len, NULL, 0) == 0)
cpu |= RETRO_SIMD_NEON;
len = sizeof(size_t);
if (sysctlbyname("hw.optional.neon_fp16", NULL, &len, NULL, 0) == 0)
cpu |= RETRO_SIMD_VFPV3;
len = sizeof(size_t);
if (sysctlbyname("hw.optional.neon_hpfp", NULL, &len, NULL, 0) == 0)
cpu |= RETRO_SIMD_VFPV4;
#endif
#elif defined(_XBOX1)
cpu |= RETRO_SIMD_MMX;
cpu |= RETRO_SIMD_SSE;
......@@ -743,7 +764,7 @@ uint64_t cpu_features_get(void)
if (check_arm_cpu_feature("neon"))
{
cpu |= RETRO_SIMD_NEON;
#ifdef __ARM_NEON__
#if defined(__ARM_NEON__) && defined(__arm__)
arm_enable_runfast_mode();
#endif
}
......@@ -759,7 +780,9 @@ uint64_t cpu_features_get(void)
cpu |= RETRO_SIMD_ASIMD;
#ifdef __ARM_NEON__
cpu |= RETRO_SIMD_NEON;
#if defined(__arm__)
arm_enable_runfast_mode();
#endif
#endif
}
......@@ -778,7 +801,9 @@ uint64_t cpu_features_get(void)
#elif defined(__ARM_NEON__)
cpu |= RETRO_SIMD_NEON;
#if defined(__arm__)
arm_enable_runfast_mode();
#endif
#elif defined(__ALTIVEC__)
cpu |= RETRO_SIMD_VMX;
#elif defined(XBOX360)
......
......@@ -370,8 +370,7 @@ int file_archive_parse_file_progress(file_archive_transfer_t *state)
/**
* file_archive_extract_file:
* @archive_path : filename path to archive.
* @archive_path_size : size of archive.
* @archive_path : filename path to archive.
* @valid_exts : valid extensions for the file.
* @extraction_directory : the directory to extract temporary
* file to.
......@@ -382,8 +381,7 @@ int file_archive_parse_file_progress(file_archive_transfer_t *state)
* Returns : true (1) on success, otherwise false (0).
**/
bool file_archive_extract_file(
char *archive_path,
size_t archive_path_size,
const char *archive_path,
const char *valid_exts,
const char *extraction_directory,
char *out_path, size_t len)
......@@ -396,7 +394,6 @@ bool file_archive_extract_file(
userdata.current_file_path[0] = '\0';
userdata.first_extracted_file_path = NULL;
userdata.extraction_directory = extraction_directory;
userdata.archive_path_size = archive_path_size;
userdata.ext = list;
userdata.list = NULL;
userdata.found_file = false;
......@@ -454,7 +451,6 @@ bool file_archive_get_file_list_noalloc(struct string_list *list,
userdata.current_file_path[0] = '\0';
userdata.first_extracted_file_path = NULL;
userdata.extraction_directory = NULL;
userdata.archive_path_size = 0;
userdata.ext = NULL;
userdata.list = list;
userdata.found_file = false;
......@@ -484,7 +480,6 @@ struct string_list *file_archive_get_file_list(const char *path,
userdata.current_file_path[0] = '\0';
userdata.first_extracted_file_path = NULL;
userdata.extraction_directory = NULL;
userdata.archive_path_size = 0;
userdata.ext = NULL;
userdata.list = string_list_new();
userdata.found_file = false;
......
......@@ -38,6 +38,7 @@
#define SEVENZIP_MAGIC "7z\xBC\xAF\x27\x1C"
#define SEVENZIP_MAGIC_LEN 6
#define SEVENZIP_LOOKTOREAD_BUF_SIZE (1 << 14)
/* Assume W-functions do not work below Win2K and Xbox platforms */
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
......@@ -50,25 +51,25 @@ struct sevenzip_context_t
{
uint8_t *output;
CFileInStream archiveStream;
CLookToRead lookStream;
CLookToRead2 lookStream;
ISzAlloc allocImp;
ISzAlloc allocTempImp;
CSzArEx db;
size_t temp_size;
uint32_t block_index;
uint32_t parse_index;
uint32_t decompress_index;
uint32_t packIndex;
uint32_t block_index;
};
static void *sevenzip_stream_alloc_impl(void *p, size_t size)
static void *sevenzip_stream_alloc_impl(ISzAllocPtr p, size_t size)
{
if (size == 0)
return 0;
return malloc(size);
}
static void sevenzip_stream_free_impl(void *p, void *address)
static void sevenzip_stream_free_impl(ISzAllocPtr p, void *address)
{
(void)p;
......@@ -76,7 +77,7 @@ static void sevenzip_stream_free_impl(void *p, void *address)
free(address);
}
static void *sevenzip_stream_alloc_tmp_impl(void *p, size_t size)
static void *sevenzip_stream_alloc_tmp_impl(ISzAllocPtr p, size_t size)
{
(void)p;
if (size == 0)
......@@ -98,6 +99,12 @@ static void* sevenzip_stream_new(void)
sevenzip_context->block_index = 0xFFFFFFFF;
sevenzip_context->output = NULL;
sevenzip_context->lookStream.bufSize = SEVENZIP_LOOKTOREAD_BUF_SIZE * sizeof(Byte);
sevenzip_context->lookStream.buf = (Byte*)malloc(sevenzip_context->lookStream.bufSize);
if (!sevenzip_context->lookStream.buf)
sevenzip_context->lookStream.bufSize = 0;
return sevenzip_context;
}
......@@ -117,6 +124,9 @@ static void sevenzip_parse_file_free(void *context)
SzArEx_Free(&sevenzip_context->db, &sevenzip_context->allocImp);
File_Close(&sevenzip_context->archiveStream.file);
if (sevenzip_context->lookStream.buf)
free(sevenzip_context->lookStream.buf);
free(sevenzip_context);
}
......@@ -131,7 +141,7 @@ static int64_t sevenzip_file_read(
const char *optional_outfile)
{
CFileInStream archiveStream;
CLookToRead lookStream;
CLookToRead2 lookStream;
ISzAlloc allocImp;
ISzAlloc allocTempImp;
CSzArEx db;
......@@ -145,6 +155,12 @@ static int64_t sevenzip_file_read(
allocTempImp.Alloc = sevenzip_stream_alloc_tmp_impl;
allocTempImp.Free = sevenzip_stream_free_impl;
lookStream.bufSize = SEVENZIP_LOOKTOREAD_BUF_SIZE * sizeof(Byte);
lookStream.buf = (Byte*)malloc(lookStream.bufSize);
if (!lookStream.buf)
lookStream.bufSize = 0;
#if defined(_WIN32) && defined(USE_WINDOWS_FILE) && !defined(LEGACY_WIN32)
if (!string_is_empty(path))
{
......@@ -169,51 +185,34 @@ static int64_t sevenzip_file_read(
#endif