Skip to content

Commit ccdd864

Browse files
authored
Merge pull request #51 from bgaifullin/master
fixed loading crypto library for xmlsec >1.2.21 #50
2 parents a9d7f1c + 961b0bd commit ccdd864

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

setup.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,29 @@ def is_debug():
2121

2222

2323
if is_debug():
24-
macroses.append(("PYXMLSEC_ENABLE_DEBUG", 1))
24+
macroses.append(("PYXMLSEC_ENABLE_DEBUG", "1"))
2525
cflags.extend(["-Wall", "-O0"])
2626
else:
2727
cflags.extend(["-Os"])
2828

2929

30-
def add_to_list(target, up):
30+
# values which requires escaping
31+
require_escape = {"XMLSEC_CRYPTO"}
32+
33+
34+
def add_to_list(target, up, need_to_escape=None):
3135
if up is None:
3236
return target
3337

3438
value = set(target)
35-
value.update(up)
39+
if need_to_escape:
40+
for x in up:
41+
if x[0] in need_to_escape:
42+
value.add((x[0], '"{0}"'.format(x[1])))
43+
else:
44+
value.add(x)
45+
else:
46+
value.update(up)
3647
target[:] = list(value)
3748

3849

@@ -61,10 +72,12 @@ def patch_xmlsec(self):
6172

6273
ext = self.ext_map[__name__]
6374
config = pkgconfig.parse("xmlsec1")
75+
# need to escape XMLSEC_CRYPTO
6476
# added build flags from pkg-config
65-
for item in ('define_macros', 'libraries', 'library_dirs', 'include_dirs'):
77+
for item in ('libraries', 'library_dirs', 'include_dirs'):
6678
add_to_list(getattr(ext, item), config.get(item))
6779

80+
add_to_list(ext.define_macros, config.get('define_macros'), {"XMLSEC_CRYPTO"})
6881
add_to_list(ext.include_dirs, lxml.get_include())
6982

7083

src/main.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ static int PyXmlSec_Init(void) {
4646
}
4747

4848
#ifndef XMLSEC_NO_CRYPTO_DYNAMIC_LOADING
49-
if (xmlSecCryptoDLLoadLibrary((const xmlChar*) STRINGIFY(XMLSEC_CRYPTO)) < 0) {
49+
#if XMLSEC_VERSION_HEX > 308
50+
// xmlSecGetDefaultCrypto was introduced in version 1.2.21
51+
const xmlChar* cryptoLib = xmlSecGetDefaultCrypto();
52+
#else
53+
const xmlChar* cryptoLib = (const xmlChar*) XMLSEC_CRYPTO;
54+
#endif
55+
PYXMLSEC_DEBUGF("dynamic crypto library: %s", cryptoLib);
56+
if (xmlSecCryptoDLLoadLibrary(cryptoLib) < 0) {
5057
PyXmlSec_SetLastError("cannot load crypto library for xmlsec.");
5158
PyXmlSec_Free(_FREE_XMLSEC);
5259
return -1;
@@ -240,6 +247,5 @@ PYENTRY_FUNC_NAME(void)
240247

241248
PY_MOD_RETURN(module);
242249
ON_FAIL:
243-
Py_DECREF(module);
244250
PY_MOD_RETURN(NULL);
245251
}

0 commit comments

Comments
 (0)