From 1dffca2929062ad824c60d7651914240a27adbc9 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Fri, 4 Dec 2015 11:21:55 +0100 Subject: [PATCH 1/2] Added --use-rpath option to setup.py --- setup.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2de8c5ef..406ece74 100644 --- a/setup.py +++ b/setup.py @@ -236,10 +236,12 @@ class psycopg_build_ext(build_ext): "Compile with OpenSSL built PostgreSQL libraries (Windows only)."), ('static-libpq', None, "Statically link the PostgreSQL client library"), + ('use-rpath', None, + "Set -rpath to the runtime location of libpq as given by pg_config") ]) boolean_options = build_ext.boolean_options[:] - boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq')) + boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq', 'use-rpath')) def __init__(self, *args, **kwargs): build_ext.__init__(self, *args, **kwargs) @@ -253,6 +255,7 @@ class psycopg_build_ext(build_ext): self.have_ssl = have_ssl self.static_libpq = static_libpq self.pg_config = None + self.use_rpath = 0 def compiler_is_msvc(self): return self.get_compiler_name().lower().startswith('msvc') @@ -387,6 +390,8 @@ class psycopg_build_ext(build_ext): os.path.join(pg_config_helper.query("libdir"), "libpq.a")) else: self.libraries.append("pq") + if self.use_rpath: + self.rpath = [pg_config_helper.query("libdir")] try: self.library_dirs.append(pg_config_helper.query("libdir")) @@ -441,6 +446,13 @@ class psycopg_build_ext(build_ext): if hasattr(self, "finalize_" + sys.platform): getattr(self, "finalize_" + sys.platform)() + def build_extension(self, ext): + # HACK: runtime library dirs are correctly fixed by ccompiler only + # if ext.runtime_library_dirs is None, but the build_ext sets it + # to null. + ext.runtime_library_dirs = None + build_ext.build_extension(self, ext) + def is_py_64(): # sys.maxint not available since Py 3.1; # sys.maxsize not available before Py 2.6; From cb6b6d0e68f2025c29dafe5ce4cc1c7c9f973fb2 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Sun, 31 Jan 2016 10:22:44 +0100 Subject: [PATCH 2/2] Add little libpq crazyness test to sandbox --- sandbox/pqcrazyness/escaping.c | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sandbox/pqcrazyness/escaping.c diff --git a/sandbox/pqcrazyness/escaping.c b/sandbox/pqcrazyness/escaping.c new file mode 100644 index 00000000..43116b5f --- /dev/null +++ b/sandbox/pqcrazyness/escaping.c @@ -0,0 +1,40 @@ +#include +#include +#include + +/* Compile me with: + * + * gcc -p escaping -I$(pg_config --includedir) escaping.c -lpq" + * + * then: + * + * ./escaping dbname=test foo\\\\bar +*/ + +int main(int argc, char** argv) +{ + PGconn* conn; + int rl, len; + char* result; + + if (argc != 3) { + fprintf(stderr, "Usage: %s [dsn] [string]\n", argv[0]); + return 1; + } + + len = strlen(argv[1]); + result = malloc(len * 2 * sizeof(char)); + + rl = PQescapeString(result, argv[2], len); + result[rl] = '\0'; + printf("%s\n", result); + + conn = PQconnectdb(argv[1]); + + rl = PQescapeString(result, argv[2], len); + result[rl] = '\0'; + printf("%s\n", result); + + return 0; +} +