Convert exception_from_error_queue() macros into a single function. Besides code maintainability, this makes our fast path shorter for better cache performance.
diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c
index 2240df0..7a4228d 100644
--- a/src/crypto/crypto.c
+++ b/src/crypto/crypto.c
@@ -112,7 +112,7 @@
if (pkey == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -213,7 +213,7 @@
if (ret == 0)
{
BIO_free(bio);
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -264,7 +264,7 @@
if (cert == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -316,7 +316,7 @@
if (ret == 0)
{
BIO_free(bio);
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -367,7 +367,7 @@
if (req == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -419,7 +419,7 @@
if (ret == 0)
{
BIO_free(bio);
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -475,7 +475,7 @@
*/
if (pkcs7 == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -506,7 +506,7 @@
if ((p12 = d2i_PKCS12_bio(bio, NULL)) == NULL)
{
BIO_free(bio);
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
BIO_free(bio);
diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h
index 2322720..5d0bf27 100644
--- a/src/crypto/crypto.h
+++ b/src/crypto/crypto.h
@@ -27,15 +27,6 @@
extern PyObject *crypto_Error;
-#ifdef exception_from_error_queue
-# undef exception_from_error_queue
-#endif
-#define exception_from_error_queue() do { \
- PyObject *errlist = error_queue_to_list(); \
- PyErr_SetObject(crypto_Error, errlist); \
- Py_DECREF(errlist); \
-} while (0)
-
#define crypto_X509_New_NUM 0
#define crypto_X509_New_RETURN crypto_X509Obj *
#define crypto_X509_New_PROTO (X509 *, int)
diff --git a/src/crypto/netscape_spki.c b/src/crypto/netscape_spki.c
index d4255f0..4fa9d8d 100644
--- a/src/crypto/netscape_spki.c
+++ b/src/crypto/netscape_spki.c
@@ -57,7 +57,7 @@
spki = NETSCAPE_SPKI_new();
if (spki == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
return (PyObject *)crypto_NetscapeSPKI_New(spki, 1);
@@ -107,7 +107,7 @@
if (!NETSCAPE_SPKI_sign(self->netscape_spki, pkey->pkey, digest))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -133,7 +133,7 @@
if ((answer = NETSCAPE_SPKI_verify(self->netscape_spki, pkey->pkey)) < 0)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -176,7 +176,7 @@
if ((pkey = NETSCAPE_SPKI_get_pubkey(self->netscape_spki)) == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -200,7 +200,7 @@
if (!NETSCAPE_SPKI_set_pubkey(self->netscape_spki, pkey->pkey))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
diff --git a/src/crypto/pkcs12.c b/src/crypto/pkcs12.c
index 71ebcdd..28ea2fe 100644
--- a/src/crypto/pkcs12.c
+++ b/src/crypto/pkcs12.c
@@ -110,7 +110,7 @@
/* parse the PKCS12 lump */
if (!(cacerts && PKCS12_parse(p12, passphrase, &pkey, &cert, &cacerts)))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
diff --git a/src/crypto/pkey.c b/src/crypto/pkey.c
index 6632abe..583a2a1 100644
--- a/src/crypto/pkey.c
+++ b/src/crypto/pkey.c
@@ -21,7 +21,7 @@
*/
#define FAIL() \
do { \
- exception_from_error_queue(); \
+ exception_from_error_queue(crypto_Error); \
return NULL; \
} while (0)
diff --git a/src/crypto/x509.c b/src/crypto/x509.c
index 119c048..e089d40 100644
--- a/src/crypto/x509.c
+++ b/src/crypto/x509.c
@@ -136,7 +136,7 @@
if (bignum == NULL) {
if (ASN1_INTEGER_set(X509_get_serialNumber(self->x509), small_serial)) {
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
goto err;
}
} else {
@@ -144,11 +144,11 @@
BN_free(bignum);
bignum = NULL;
if (asn1_i == NULL) {
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
goto err;
}
if (!X509_set_serialNumber(self->x509, asn1_i)) {
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
goto err;
}
ASN1_INTEGER_free(asn1_i);
@@ -221,7 +221,7 @@
if (!X509_set_issuer_name(self->x509, issuer->x509_name))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -273,7 +273,7 @@
if (!X509_set_subject_name(self->x509, subject->x509_name))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -299,7 +299,7 @@
if ((pkey = X509_get_pubkey(self->x509)) == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -327,7 +327,7 @@
if (!X509_set_pubkey(self->x509, pkey->pkey))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -422,7 +422,7 @@
} else {
ASN1_TIME_to_generalizedtime(timestamp, >_timestamp);
if (gt_timestamp == NULL) {
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
} else {
py_timestamp = PyString_FromString((char *)gt_timestamp->data);
@@ -558,7 +558,7 @@
if (!X509_sign(self->x509, pkey->pkey, digest))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -629,7 +629,7 @@
if (!X509_digest(self->x509,digest,fp,&len))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
}
tmp = malloc(3*len+1);
memset(tmp, 0, 3*len+1);
@@ -679,7 +679,7 @@
if (!X509_add_ext(self->x509, ext->x509_extension, -1))
{
Py_DECREF(seq);
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
}
diff --git a/src/crypto/x509ext.c b/src/crypto/x509ext.c
index cd169d2..e7ab5e1 100644
--- a/src/crypto/x509ext.c
+++ b/src/crypto/x509ext.c
@@ -126,7 +126,7 @@
return self;
nconf_error:
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
critical_malloc_error:
Py_XDECREF(self);
@@ -204,7 +204,7 @@
if (!X509V3_EXT_print(bio, self->x509_extension, 0, 0))
{
BIO_free(bio);
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
diff --git a/src/crypto/x509name.c b/src/crypto/x509name.c
index 5d49430..6d08470 100644
--- a/src/crypto/x509name.c
+++ b/src/crypto/x509name.c
@@ -88,7 +88,7 @@
data = X509_NAME_ENTRY_get_data(entry);
if ((len = ASN1_STRING_to_UTF8((unsigned char **)utf8string, data)) < 0)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return -1;
}
@@ -129,7 +129,7 @@
(unsigned char *)utf8string,
-1, -1, 0))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return -1;
}
return 0;
@@ -236,7 +236,7 @@
if (X509_NAME_oneline(self->x509_name, tmpbuf, 512) == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
else
diff --git a/src/crypto/x509req.c b/src/crypto/x509req.c
index a1325e9..07bd44b 100644
--- a/src/crypto/x509req.c
+++ b/src/crypto/x509req.c
@@ -30,7 +30,7 @@
if ((name = X509_REQ_get_subject_name(self->x509_req)) == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
if ((pyname = crypto_X509Name_New(name, 0)) != NULL) {
@@ -58,7 +58,7 @@
if ((pkey = X509_REQ_get_pubkey(self->x509_req)) == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -86,7 +86,7 @@
if (!X509_REQ_set_pubkey(self->x509_req, pkey->pkey))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -131,7 +131,7 @@
if (!X509_REQ_sign(self->x509_req, pkey->pkey, digest))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -160,7 +160,7 @@
if ((answer = X509_REQ_verify(self->x509_req, key->pkey)) < 0)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -194,7 +194,7 @@
/* Make a STACK_OF(X509_EXTENSION) from sequence */
if ((exts = sk_X509_EXTENSION_new_null()) == NULL)
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
@@ -217,7 +217,7 @@
if (!X509_REQ_add_extensions(self->x509_req, exts))
{
sk_X509_EXTENSION_free(exts);
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}
diff --git a/src/crypto/x509store.c b/src/crypto/x509store.c
index 9f46029..16af3b0 100644
--- a/src/crypto/x509store.c
+++ b/src/crypto/x509store.c
@@ -27,7 +27,7 @@
if (!X509_STORE_add_cert(self->x509_store, cert->x509))
{
- exception_from_error_queue();
+ exception_from_error_queue(crypto_Error);
return NULL;
}