Make all get/putenv() calls compile-time optional

* Modify the SIMD dispatchers so they guard their usage of getenv() with
  the existing NO_GETENV preprocessor definition.
* Introduce a new NO_PUTENV preprocessor definition to guard the
  usage of putenv() in the TurboJPEG API library.

This at least puts Windows Store compatibility within the realm of
possibility, although further steps are required.
This commit is contained in:
DRC
2018-03-17 00:06:10 -05:00
parent 25758055ac
commit bd96b30b74
7 changed files with 45 additions and 7 deletions

View File

@@ -3,7 +3,7 @@
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander.
* Copyright (C) 2009-2011, 2013-2014, 2016, 2018, D. R. Commander.
* Copyright (C) 2015-2016, Matthieu Darbois.
*
* Based on the x86 SIMD extension for IJG JPEG library,
@@ -100,7 +100,9 @@ parse_proc_cpuinfo (int bufsize)
LOCAL(void)
init_simd (void)
{
#ifndef NO_GETENV
char *env = NULL;
#endif
#if !defined(__ARM_NEON__) && defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#endif
@@ -123,6 +125,7 @@ init_simd (void)
}
#endif
#ifndef NO_GETENV
/* Force different settings through environment variables */
env = getenv("JSIMD_FORCENEON");
if ((env != NULL) && (strcmp(env, "1") == 0))
@@ -133,6 +136,7 @@ init_simd (void)
env = getenv("JSIMD_NOHUFFENC");
if ((env != NULL) && (strcmp(env, "1") == 0))
simd_huffman = 0;
#endif
}
GLOBAL(int)

View File

@@ -3,7 +3,7 @@
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander.
* Copyright (C) 2009-2011, 2013-2014, 2016, 2018, D. R. Commander.
* Copyright (C) 2015-2016, Matthieu Darbois.
*
* Based on the x86 SIMD extension for IJG JPEG library,
@@ -121,7 +121,9 @@ parse_proc_cpuinfo (int bufsize)
LOCAL(void)
init_simd (void)
{
#ifndef NO_GETENV
char *env = NULL;
#endif
#if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#endif
@@ -140,6 +142,7 @@ init_simd (void)
}
#endif
#ifndef NO_GETENV
/* Force different settings through environment variables */
env = getenv("JSIMD_FORCENEON");
if ((env != NULL) && (strcmp(env, "1") == 0))
@@ -160,6 +163,7 @@ init_simd (void)
simd_features |= JSIMD_FASTST3;
if ((env != NULL) && (strcmp(env, "0") == 0))
simd_features &= ~JSIMD_FASTST3;
#endif
}
GLOBAL(int)

View File

@@ -2,7 +2,7 @@
* jsimd_i386.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2011, 2013-2014, 2016, D. R. Commander.
* Copyright (C) 2009-2011, 2013-2014, 2016, 2018, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois.
*
* Based on the x86 SIMD extension for IJG JPEG library,
@@ -41,13 +41,16 @@ static unsigned int simd_huffman = 1;
LOCAL(void)
init_simd (void)
{
#ifndef NO_GETENV
char *env = NULL;
#endif
if (simd_support != ~0U)
return;
simd_support = jpeg_simd_cpu_support();
#ifndef NO_GETENV
/* Force different settings through environment variables */
env = getenv("JSIMD_FORCEMMX");
if ((env != NULL) && (strcmp(env, "1") == 0))
@@ -67,6 +70,7 @@ init_simd (void)
env = getenv("JSIMD_NOHUFFENC");
if ((env != NULL) && (strcmp(env, "1") == 0))
simd_huffman = 0;
#endif
}
GLOBAL(int)

View File

@@ -2,7 +2,7 @@
* jsimd_mips.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2011, 2014, 2016, D. R. Commander.
* Copyright (C) 2009-2011, 2014, 2016, 2018, D. R. Commander.
* Copyright (C) 2013-2014, MIPS Technologies, Inc., California.
* Copyright (C) 2015, Matthieu Darbois.
*
@@ -63,7 +63,9 @@ parse_proc_cpuinfo(const char* search_string)
LOCAL(void)
init_simd (void)
{
#ifndef NO_GETENV
char *env = NULL;
#endif
if (simd_support != ~0U)
return;
@@ -80,6 +82,7 @@ init_simd (void)
return;
#endif
#ifndef NO_GETENV
/* Force different settings through environment variables */
env = getenv("JSIMD_FORCEDSPR2");
if ((env != NULL) && (strcmp(env, "1") == 0))
@@ -87,6 +90,7 @@ init_simd (void)
env = getenv("JSIMD_FORCENONE");
if ((env != NULL) && (strcmp(env, "1") == 0))
simd_support = 0;
#endif
}
static const int mips_idct_ifast_coefs[4] = {

View File

@@ -2,7 +2,7 @@
* jsimd_powerpc.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2011, 2014-2016, D. R. Commander.
* Copyright (C) 2009-2011, 2014-2016, 2018, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois.
*
* Based on the x86 SIMD extension for IJG JPEG library,
@@ -109,7 +109,9 @@ parse_proc_cpuinfo (int bufsize)
LOCAL(void)
init_simd (void)
{
#ifndef NO_GETENV
char *env = NULL;
#endif
#if !defined(__ALTIVEC__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#elif defined(__amigaos4__)
@@ -142,6 +144,7 @@ init_simd (void)
simd_support |= JSIMD_ALTIVEC;
#endif
#ifndef NO_GETENV
/* Force different settings through environment variables */
env = getenv("JSIMD_FORCEALTIVEC");
if ((env != NULL) && (strcmp(env, "1") == 0))
@@ -149,6 +152,7 @@ init_simd (void)
env = getenv("JSIMD_FORCENONE");
if ((env != NULL) && (strcmp(env, "1") == 0))
simd_support = 0;
#endif
}
GLOBAL(int)

View File

@@ -2,7 +2,7 @@
* jsimd_x86_64.c
*
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2009-2011, 2014, 2016, D. R. Commander.
* Copyright (C) 2009-2011, 2014, 2016, 2018, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois.
*
* Based on the x86 SIMD extension for IJG JPEG library,
@@ -41,13 +41,16 @@ static unsigned int simd_huffman = 1;
LOCAL(void)
init_simd (void)
{
#ifndef NO_GETENV
char *env = NULL;
#endif
if (simd_support != ~0U)
return;
simd_support = JSIMD_SSE2 | JSIMD_SSE;
#ifndef NO_GETENV
/* Force different settings through environment variables */
env = getenv("JSIMD_FORCENONE");
if ((env != NULL) && (strcmp(env, "1") == 0))
@@ -55,6 +58,7 @@ init_simd (void)
env = getenv("JSIMD_NOHUFFENC");
if ((env != NULL) && (strcmp(env, "1") == 0))
simd_huffman = 0;
#endif
}
GLOBAL(int)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2009-2017 D. R. Commander. All Rights Reserved.
* Copyright (C)2009-2018 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -796,9 +796,11 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf,
cinfo->image_width=width;
cinfo->image_height=height;
#ifndef NO_PUTENV
if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
#endif
if(flags&TJFLAG_NOREALLOC)
{
@@ -912,9 +914,11 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle,
cinfo->image_width=width;
cinfo->image_height=height;
#ifndef NO_PUTENV
if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
#endif
if(setCompDefaults(cinfo, pixelFormat, subsamp, -1, flags)==-1) return -1;
@@ -1111,9 +1115,11 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle,
cinfo->image_width=width;
cinfo->image_height=height;
#ifndef NO_PUTENV
if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
#endif
if(flags&TJFLAG_NOREALLOC)
{
@@ -1392,9 +1398,11 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle,
|| height<0 || pixelFormat<0 || pixelFormat>=TJ_NUMPF)
_throw("tjDecompress2(): Invalid argument");
#ifndef NO_PUTENV
if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
#endif
if(setjmp(this->jerr.setjmp_buffer))
{
@@ -1592,9 +1600,11 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle,
dinfo->image_width=width;
dinfo->image_height=height;
#ifndef NO_PUTENV
if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
#endif
if(setDecodeDefaults(dinfo, pixelFormat, subsamp, flags)==-1)
{
@@ -1773,9 +1783,11 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle,
|| height<0)
_throw("tjDecompressToYUVPlanes(): Invalid argument");
#ifndef NO_PUTENV
if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
#endif
if(setjmp(this->jerr.setjmp_buffer))
{
@@ -2037,9 +2049,11 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle,
|| t==NULL || flags<0)
_throw("tjTransform(): Invalid argument");
#ifndef NO_PUTENV
if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1");
else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1");
else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1");
#endif
if((xinfo=(jpeg_transform_info *)malloc(sizeof(jpeg_transform_info)*n))
==NULL)