Commit 478c05fcab6cb4137b9cbaf55fdcdb6ff74107c0
1 parent
88c29873
Allow -DNO_GET_ENVIRONMENT to avoid GetEnvironmentVariable
If NO_GET_ENVIRONMENT is #defined at compile time on Windows, do not call GetEnvironmentVariable. QUtil::get_env will always return false. This option is not available through configure. This was added to support a specific user's requirements to avoid calling GetEnvironmentVariable from the Windows API. Nothing in qpdf outside the test coverage system in qtest relies on QUtil::get_env.
Showing
6 changed files
with
36 additions
and
4 deletions
ChangeLog
| 1 | 2013-11-29 Jay Berkenbilt <ejb@ql.org> | 1 | 2013-11-29 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * If NO_GET_ENVIRONMENT is #defined, for Windows only, | ||
| 4 | + QUtil::get_env will always return false. This was added to | ||
| 5 | + support a user who needs to avoid calling GetEnvironmentVariable | ||
| 6 | + from the Windows API. QUtil::get_env is not used for any | ||
| 7 | + functionality in qpdf and exists only to support the test suite | ||
| 8 | + including test coverage support with QTC (part of qtest). | ||
| 9 | + | ||
| 3 | * Add /FS to msvc builds to allow parallel builds to work with | 10 | * Add /FS to msvc builds to allow parallel builds to work with |
| 4 | Visual C++ 2013. | 11 | Visual C++ 2013. |
| 5 | 12 |
examples/pdf-double-page-size.cc
| @@ -51,6 +51,15 @@ int main(int argc, char* argv[]) | @@ -51,6 +51,15 @@ int main(int argc, char* argv[]) | ||
| 51 | whoami += 3; | 51 | whoami += 3; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | + // For test suite | ||
| 55 | + bool static_id = false; | ||
| 56 | + if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) | ||
| 57 | + { | ||
| 58 | + static_id = true; | ||
| 59 | + --argc; | ||
| 60 | + ++argv; | ||
| 61 | + } | ||
| 62 | + | ||
| 54 | if (! ((argc == 3) || (argc == 4))) | 63 | if (! ((argc == 3) || (argc == 4))) |
| 55 | { | 64 | { |
| 56 | usage(); | 65 | usage(); |
| @@ -88,7 +97,7 @@ int main(int argc, char* argv[]) | @@ -88,7 +97,7 @@ int main(int argc, char* argv[]) | ||
| 88 | 97 | ||
| 89 | // Write out a new file | 98 | // Write out a new file |
| 90 | QPDFWriter w(qpdf, outfilename); | 99 | QPDFWriter w(qpdf, outfilename); |
| 91 | - if (QUtil::get_env("IN_TESTSUITE")) | 100 | + if (static_id) |
| 92 | { | 101 | { |
| 93 | // For the test suite, uncompress streams and use static | 102 | // For the test suite, uncompress streams and use static |
| 94 | // IDs. | 103 | // IDs. |
examples/pdf-invert-images.cc
| @@ -70,6 +70,15 @@ int main(int argc, char* argv[]) | @@ -70,6 +70,15 @@ int main(int argc, char* argv[]) | ||
| 70 | whoami += 3; | 70 | whoami += 3; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | + // For test suite | ||
| 74 | + bool static_id = false; | ||
| 75 | + if ((argc > 1) && (strcmp(argv[1], " --static-id") == 0)) | ||
| 76 | + { | ||
| 77 | + static_id = true; | ||
| 78 | + --argc; | ||
| 79 | + ++argv; | ||
| 80 | + } | ||
| 81 | + | ||
| 73 | if (! ((argc == 3) || (argc == 4))) | 82 | if (! ((argc == 3) || (argc == 4))) |
| 74 | { | 83 | { |
| 75 | usage(); | 84 | usage(); |
| @@ -149,7 +158,7 @@ int main(int argc, char* argv[]) | @@ -149,7 +158,7 @@ int main(int argc, char* argv[]) | ||
| 149 | 158 | ||
| 150 | // Write out a new file | 159 | // Write out a new file |
| 151 | QPDFWriter w(qpdf, outfilename); | 160 | QPDFWriter w(qpdf, outfilename); |
| 152 | - if (QUtil::get_env("IN_TESTSUITE")) | 161 | + if (static_id) |
| 153 | { | 162 | { |
| 154 | // For the test suite, uncompress streams and use static | 163 | // For the test suite, uncompress streams and use static |
| 155 | // IDs. | 164 | // IDs. |
examples/qtest/double-page-size.test
| @@ -12,7 +12,8 @@ my $td = new TestDriver('double-page-size'); | @@ -12,7 +12,8 @@ my $td = new TestDriver('double-page-size'); | ||
| 12 | cleanup(); | 12 | cleanup(); |
| 13 | 13 | ||
| 14 | $td->runtest("double page size", | 14 | $td->runtest("double page size", |
| 15 | - {$td->COMMAND => "pdf-double-page-size in.pdf a.pdf"}, | 15 | + {$td->COMMAND => ['pdf-double-page-size', ' --static-id', |
| 16 | + 'in.pdf', 'a.pdf']}, | ||
| 16 | {$td->STRING => | 17 | {$td->STRING => |
| 17 | "pdf-double-page-size: new file written to a.pdf\n", | 18 | "pdf-double-page-size: new file written to a.pdf\n", |
| 18 | $td->EXIT_STATUS => 0}, | 19 | $td->EXIT_STATUS => 0}, |
examples/qtest/invert-images.test
| @@ -12,7 +12,8 @@ my $td = new TestDriver('invert-images'); | @@ -12,7 +12,8 @@ my $td = new TestDriver('invert-images'); | ||
| 12 | cleanup(); | 12 | cleanup(); |
| 13 | 13 | ||
| 14 | $td->runtest("double page size", | 14 | $td->runtest("double page size", |
| 15 | - {$td->COMMAND => "pdf-invert-images in.pdf a.pdf"}, | 15 | + {$td->COMMAND => ['pdf-invert-images', ' --static-id', |
| 16 | + 'in.pdf', 'a.pdf']}, | ||
| 16 | {$td->STRING => | 17 | {$td->STRING => |
| 17 | "pdf-invert-images: new file written to a.pdf\n", | 18 | "pdf-invert-images: new file written to a.pdf\n", |
| 18 | $td->EXIT_STATUS => 0}, | 19 | $td->EXIT_STATUS => 0}, |
libqpdf/QUtil.cc
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | #include <cmath> | 7 | #include <cmath> |
| 8 | #include <iomanip> | 8 | #include <iomanip> |
| 9 | #include <sstream> | 9 | #include <sstream> |
| 10 | +#include <stdexcept> | ||
| 10 | #include <stdio.h> | 11 | #include <stdio.h> |
| 11 | #include <errno.h> | 12 | #include <errno.h> |
| 12 | #include <ctype.h> | 13 | #include <ctype.h> |
| @@ -262,6 +263,9 @@ QUtil::get_env(std::string const& var, std::string* value) | @@ -262,6 +263,9 @@ QUtil::get_env(std::string const& var, std::string* value) | ||
| 262 | { | 263 | { |
| 263 | // This was basically ripped out of wxWindows. | 264 | // This was basically ripped out of wxWindows. |
| 264 | #ifdef _WIN32 | 265 | #ifdef _WIN32 |
| 266 | +# ifdef NO_GET_ENVIRONMENT | ||
| 267 | + return false; | ||
| 268 | +# else | ||
| 265 | // first get the size of the buffer | 269 | // first get the size of the buffer |
| 266 | DWORD len = ::GetEnvironmentVariable(var.c_str(), NULL, 0); | 270 | DWORD len = ::GetEnvironmentVariable(var.c_str(), NULL, 0); |
| 267 | if (len == 0) | 271 | if (len == 0) |
| @@ -279,6 +283,7 @@ QUtil::get_env(std::string const& var, std::string* value) | @@ -279,6 +283,7 @@ QUtil::get_env(std::string const& var, std::string* value) | ||
| 279 | } | 283 | } |
| 280 | 284 | ||
| 281 | return true; | 285 | return true; |
| 286 | +# endif | ||
| 282 | #else | 287 | #else |
| 283 | char* p = getenv(var.c_str()); | 288 | char* p = getenv(var.c_str()); |
| 284 | if (p == 0) | 289 | if (p == 0) |