diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2014-01-21 18:14:11 -0800 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2014-01-21 18:14:11 -0800 |
commit | f96002687dcef4d6de8cc744c4a955cc9b138353 (patch) | |
tree | 31aca3f1b3c54f5fe2c7054b7e801d747c7ed01c | |
parent | 8cf045460a01ffe74654a4acd2a7534101976800 (diff) | |
parent | ec8af746797ad84a81160e663b50f3bd411cdb7f (diff) | |
download | pycurl-f96002687dcef4d6de8cc744c4a955cc9b138353.tar.gz |
Merge pull request #159 from p-push/avoid-stdio-option
Avoid stdio option
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | INSTALL.rst | 18 | ||||
-rw-r--r-- | setup.py | 20 | ||||
-rw-r--r-- | src/pycurl.c | 2 | ||||
-rwxr-xr-x | tests/travis/run.sh | 4 |
6 files changed, 45 insertions, 5 deletions
diff --git a/.travis.yml b/.travis.yml index f9d7b63..6b3d25a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,9 @@ matrix: env: - USECURL=7.34.0 - USESSL=none + - python: 2.7 + env: + - AVOIDSTDIO=yes install: > ./tests/travis/setup.sh before_script: > @@ -1,6 +1,9 @@ master ------ + * Added --avoid-stdio setup.py option to avoid passing FILE + pointers from Python to libcurl. Applies to Python 2 only. + * Added CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLMOPT_MAX_HOST_CONNECTIONS CURLMOPT_MAX_PIPELINE_LENGTH, CURLMOPT_MAX_TOTAL_CONNECTIONS diff --git a/INSTALL.rst b/INSTALL.rst index f96fa55..65475a3 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -92,12 +92,26 @@ and compiled libraries. Additional Windows setup.py options: -- ``--use-libcurl-dll`` - build against libcurl DLL, if not given PycURL will +- ``--use-libcurl-dll``: build against libcurl DLL, if not given PycURL will be built against libcurl statically. -- ``--libcurl-lib-name=libcurl_imp.lib`` - specify a different name for libcurl +- ``--libcurl-lib-name=libcurl_imp.lib``: specify a different name for libcurl import library. The default is ``libcurl.lib`` which is appropriate for static linking and is sometimes the correct choice for dynamic linking as well. The other possibility for dynamic linking is ``libcurl_imp.lib``. +- ``--avoid-stdio``: on windows, a process and each library it is using + may be linked to its own version of the C runtime (msvcrt). + FILE pointers from one C runtime may not be passed to another C runtime. + This option prevents direct passing of FILE pointers from Python to libcurl, + thus permitting Python and libcurl to be linked against different C runtimes. + This option may carry a performance penalty when Python file objects are + given directly to PycURL in CURLOPT_READDATA, CURLOPT_WRITEDATA or + CURLOPT_WRITEHEADER options. This option applies only on Python 2; on + Python 3, file objects no longer expose C library FILE pointers and the + C runtime issue does not exist. On Python 3, this option is recognized but + does nothing. You can also give ``--avoid-stdio`` option in + PYCURL_SETUP_OPTIONS environment variable as follows:: + + PYCURL_SETUP_OPTIONS=--avoid-stdio pip install pycurl A good ``setup.py`` target to use is ``bdist_wininst`` which produces an executable installer that you can run to install PycURL. @@ -240,9 +240,13 @@ class ExtensionConfiguration(object): self.define_macros.append(('HAVE_CURL_SSL', 1)) if not self.libraries: self.libraries.append("curl") + # Add extra compile flag for MacOS X if sys.platform[:-1] == "darwin": self.extra_link_args.append("-flat_namespace") + + # Recognize --avoid-stdio on Unix so that it can be tested + self.check_avoid_stdio() def configure_windows(self): @@ -279,6 +283,8 @@ class ExtensionConfiguration(object): fail("libcurl.lib does not exist at %s.\nCurl directory must point to compiled libcurl (bin/include/lib subdirectories): %s" %(libcurl_lib_path, curl_dir)) self.extra_objects.append(libcurl_lib_path) + self.check_avoid_stdio() + # make pycurl binary work on windows xp. # we use inet_ntop which was added in vista and implement a fallback. # our implementation will not be compiled with _WIN32_WINNT targeting @@ -302,6 +308,13 @@ class ExtensionConfiguration(object): configure = configure_windows else: configure = configure_unix + + + def check_avoid_stdio(self): + if 'PYCURL_SETUP_OPTIONS' in os.environ and '--avoid-stdio' in os.environ['PYCURL_SETUP_OPTIONS']: + self.extra_compile_args.append("-DPYCURL_AVOID_STDIO") + if scan_argv('--avoid-stdio') is not None: + self.extra_compile_args.append("-DPYCURL_AVOID_STDIO") def get_bdist_msi_version_hack(): # workaround for distutils/msi version requirement per @@ -339,9 +352,12 @@ def get_bdist_msi_version_hack(): def strip_pycurl_options(): if sys.platform == 'win32': - options = ['--curl-dir=', '--curl-lib-name=', '--use-libcurl-dll'] + options = [ + '--curl-dir=', '--curl-lib-name=', '--use-libcurl-dll', + '--avoid-stdio', + ] else: - options = ['--openssl-dir=', '--curl-config='] + options = ['--openssl-dir=', '--curl-config=', '--avoid-stdio'] for option in options: scan_argv(option) diff --git a/src/pycurl.c b/src/pycurl.c index 6e347d9..5f6afaa 100644 --- a/src/pycurl.c +++ b/src/pycurl.c @@ -2244,7 +2244,7 @@ do_curl_setopt(CurlObject *self, PyObject *args) #undef IS_LONG_OPTION #undef IS_OFF_T_OPTION -#if PY_MAJOR_VERSION < 3 +#if PY_MAJOR_VERSION < 3 && !defined(PYCURL_AVOID_STDIO) /* Handle the case of file objects */ if (PyFile_Check(obj)) { FILE *fp; diff --git a/tests/travis/run.sh b/tests/travis/run.sh index 035afea..a596588 100755 --- a/tests/travis/run.sh +++ b/tests/travis/run.sh @@ -37,4 +37,8 @@ fi export VSFTPD_PATH=vsftpd +if test -n "$AVOIDSTDIO"; then + export PYCURL_SETUP_OPTIONS=--avoid-stdio +fi + make test |