Skip to content

Commit b4a4d9a

Browse files
rnpridgeonedenhill
authored andcommitted
Intercept and set debug context before interceptor
1 parent 9111488 commit b4a4d9a

File tree

1 file changed

+23
-82
lines changed

1 file changed

+23
-82
lines changed

confluent_kafka/src/confluent_kafka.c

Lines changed: 23 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,6 @@ static int common_conf_set_special(PyObject *confdict, rd_kafka_conf_t *conf,
15061506
!= RD_KAFKA_CONF_OK) {
15071507
cfl_PyErr_Format(RD_KAFKA_RESP_ERR__INVALID_ARG,
15081508
"%s", errstr);
1509-
15101509
Py_DECREF(vs);
15111510
Py_XDECREF(vs8);
15121511
return 0;
@@ -1585,8 +1584,8 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
15851584
/*
15861585
* Set debug contexts first to capture all events including plugin loading
15871586
*/
1588-
if ((vo = PyDict_GetItemString(confdict, "debug")))
1589-
if (!common_conf_set_special(confdict, conf, "debug", vo))
1587+
if ((vo = PyDict_GetItemString(confdict, "debug")) &&
1588+
!common_conf_set_special(confdict, conf, "debug", vo))
15901589
goto outer_err;
15911590

15921591
/*
@@ -1598,40 +1597,18 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
15981597
* correct order.
15991598
*/
16001599
if ((vo = PyDict_GetItemString(confdict, "plugin.library.paths"))) {
1601-
const char *v;
1602-
char errstr[256];
1600+
/* Resolve plugin paths */
16031601
PyObject *resolved;
1604-
PyObject *vs = NULL, *vs8 = NULL;
16051602

1606-
/* Resolve plugin paths */
16071603
resolved = resolve_plugins(vo);
16081604
if (!resolved)
16091605
goto outer_err;
16101606

1611-
if (!common_conf_set_special(confdict, conf, "plugin.library.paths", vo)) {
1607+
if (!common_conf_set_special(confdict, conf,
1608+
"plugin.library.paths",
1609+
resolved)) {
16121610
Py_DECREF(resolved);
1613-
rd_kafka_conf_destroy(conf);
1614-
Py_DECREF(confdict);
1615-
1616-
return NULL;
1617-
}
1618-
1619-
Py_DECREF(resolved);
1620-
1621-
v = cfl_PyUnistr_AsUTF8(vs, &vs8);
1622-
1623-
if (rd_kafka_conf_set(conf, "plugin.library.paths", v, errstr, sizeof(errstr))
1624-
!= RD_KAFKA_CONF_OK) {
1625-
cfl_PyErr_Format(RD_KAFKA_RESP_ERR__INVALID_ARG,
1626-
"%s", errstr);
1627-
1628-
rd_kafka_conf_destroy(conf);
1629-
Py_DECREF(confdict);
1630-
1631-
Py_XDECREF(vs8);
1632-
Py_XDECREF(vs);
1633-
1634-
return NULL;
1611+
goto outer_err;
16351612
}
16361613
Py_DECREF(resolved);
16371614
}
@@ -1643,16 +1620,15 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
16431620
"set default topic configuration values in the global dict");
16441621
*/
16451622
if (PyDict_Update(confdict, vo) == -1) {
1646-
rd_kafka_conf_destroy(conf);
1647-
Py_DECREF(confdict);
1648-
return NULL;
1623+
goto outer_err;
16491624
}
16501625
PyDict_DelItemString(confdict, "default.topic.config");
16511626
}
16521627

16531628
/* Convert config dict to config key-value pairs. */
16541629
while (PyDict_Next(confdict, &pos, &ko, &vo)) {
1655-
PyObject *ks, *ks8;
1630+
PyObject *ks;
1631+
PyObject *ks8 = NULL;
16561632
PyObject *vs = NULL, *vs8 = NULL;
16571633
const char *k;
16581634
const char *v;
@@ -1663,10 +1639,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
16631639
PyErr_SetString(PyExc_TypeError,
16641640
"expected configuration property name "
16651641
"as type unicode string");
1666-
rd_kafka_conf_destroy(conf);
1667-
Py_DECREF(confdict);
1668-
1669-
return NULL;
1642+
goto inner_err;
16701643
}
16711644

16721645
k = cfl_PyUnistr_AsUTF8(ks, &ks8);
@@ -1675,13 +1648,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
16751648
PyErr_SetString(PyExc_TypeError,
16761649
"expected error_cb property "
16771650
"as a callable function");
1678-
rd_kafka_conf_destroy(conf);
1679-
Py_DECREF(confdict);
1680-
1681-
Py_XDECREF(ks8);
1682-
Py_DECREF(ks);
1683-
1684-
return NULL;
1651+
goto inner_err;
16851652
}
16861653
if (h->error_cb) {
16871654
Py_DECREF(h->error_cb);
@@ -1699,13 +1666,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
16991666
PyErr_SetString(PyExc_ValueError,
17001667
"expected throttle_cb property "
17011668
"as a callable function");
1702-
rd_kafka_conf_destroy(conf);
1703-
Py_DECREF(confdict);
1704-
1705-
Py_XDECREF(ks8);
1706-
Py_DECREF(ks);
1707-
1708-
return NULL;
1669+
goto inner_err;
17091670
}
17101671
if (h->throttle_cb) {
17111672
Py_DECREF(h->throttle_cb);
@@ -1723,13 +1684,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17231684
PyErr_SetString(PyExc_TypeError,
17241685
"expected stats_cb property "
17251686
"as a callable function");
1726-
rd_kafka_conf_destroy(conf);
1727-
Py_DECREF(confdict);
1728-
1729-
Py_XDECREF(ks8);
1730-
Py_DECREF(ks);
1731-
1732-
return NULL;
1687+
goto inner_err;
17331688
}
17341689

17351690
if (h->stats_cb) {
@@ -1765,13 +1720,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17651720
r = consumer_conf_set_special(h, conf, k, vo);
17661721
if (r == -1) {
17671722
/* Error */
1768-
Py_XDECREF(ks8);
1769-
Py_DECREF(ks);
1770-
rd_kafka_conf_destroy(conf);
1771-
Py_DECREF(confdict);
1772-
1773-
return NULL;
1774-
1723+
goto inner_err;
17751724
} else if (r == 1) {
17761725
/* Handled */
17771726
continue;
@@ -1789,13 +1738,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
17891738
"expected configuration "
17901739
"property value as type "
17911740
"unicode string");
1792-
rd_kafka_conf_destroy(conf);
1793-
Py_DECREF(confdict);
1794-
1795-
Py_XDECREF(ks8);
1796-
Py_DECREF(ks);
1797-
1798-
return NULL;
1741+
goto inner_err;
17991742
}
18001743
v = cfl_PyUnistr_AsUTF8(vs, &vs8);
18011744
}
@@ -1804,15 +1747,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
18041747
RD_KAFKA_CONF_OK) {
18051748
cfl_PyErr_Format(RD_KAFKA_RESP_ERR__INVALID_ARG,
18061749
"%s", errstr);
1807-
rd_kafka_conf_destroy(conf);
1808-
Py_DECREF(confdict);
1809-
1810-
Py_XDECREF(vs8);
1811-
Py_XDECREF(vs);
1812-
Py_XDECREF(ks8);
1813-
Py_DECREF(ks);
1814-
1815-
return NULL;
1750+
goto inner_err;
18161751
}
18171752

18181753
Py_XDECREF(vs8);
@@ -1863,6 +1798,12 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
18631798
h->initiated = 1;
18641799

18651800
return conf;
1801+
1802+
outer_err:
1803+
Py_DECREF(confdict);
1804+
rd_kafka_conf_destroy(conf);
1805+
1806+
return NULL;
18661807
}
18671808

18681809

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy