@@ -1271,8 +1271,13 @@ context_general(getdns_ContextObject *self, PyObject *args, PyObject *keywds)
12711271 }
12721272 if (userarg )
12731273 strncpy (blob -> userarg , userarg , BUFSIZ - 1 );
1274+ #if PY_MAJOR_VERSION >= 3
1275+ if (PyUnicode_Check (callback )) {
1276+ if ((callback_func = get_callback ("__main__" , PyBytes_AsString (PyUnicode_AsEncodedString (PyObject_Str (callback ), "ascii" , NULL )))) == (PyObject * )NULL ) {
1277+ #else
12741278 if (PyString_Check (callback )) {
12751279 if ((callback_func = get_callback ("__main__" , PyString_AsString (callback ))) == (PyObject * )NULL ) {
1280+ #endif
12761281 PyObject * err_type , * err_value , * err_traceback ;
12771282 PyErr_Fetch (& err_type , & err_value , & err_traceback );
12781283 PyErr_Restore (err_type , err_value , err_traceback );
@@ -1369,8 +1374,13 @@ context_address(getdns_ContextObject *self, PyObject *args, PyObject *keywds)
13691374 } else {
13701375 blob -> userarg [0 ] = 0 ;
13711376 }
1372- if (PyString_Check (callback )) {
1377+ #if PY_MAJOR_VERSION >= 3
1378+ if (PyUnicode_Check (callback )) {
1379+ if ((callback_func = get_callback ("__main__" , PyBytes_AsString (PyUnicode_AsEncodedString (PyObject_Str (callback ), "ascii" , NULL )))) == (PyObject * )NULL ) {
1380+ #else
1381+ if (PyString_Check (callback )) {
13731382 if ((callback_func = get_callback ("__main__" , PyString_AsString (callback ))) == (PyObject * )NULL ) {
1383+ #endif
13741384 PyObject * err_type , * err_value , * err_traceback ;
13751385 PyErr_Fetch (& err_type , & err_value , & err_traceback );
13761386 PyErr_Restore (err_type , err_value , err_traceback );
@@ -1472,8 +1482,13 @@ context_hostname(getdns_ContextObject *self, PyObject *args, PyObject *keywds)
14721482 } else {
14731483 blob -> userarg [0 ] = 0 ;
14741484 }
1485+ #if PY_MAJOR_VERSION >= 3
1486+ if (PyUnicode_Check (callback )) {
1487+ if ((callback_func = get_callback ("__main__" , PyBytes_AsString (PyUnicode_AsEncodedString (PyObject_Str (callback ), "ascii" , NULL )))) == (PyObject * )NULL ) {
1488+ #else
14751489 if (PyString_Check (callback )) {
14761490 if ((callback_func = get_callback ("__main__" , PyString_AsString (callback ))) == (PyObject * )NULL ) {
1491+ #endif
14771492 PyObject * err_type , * err_value , * err_traceback ;
14781493 PyErr_Fetch (& err_type , & err_value , & err_traceback );
14791494 PyErr_Restore (err_type , err_value , err_traceback );
@@ -1568,8 +1583,13 @@ context_service(getdns_ContextObject *self, PyObject *args, PyObject *keywds)
15681583 } else {
15691584 blob -> userarg [0 ] = 0 ;
15701585 }
1586+ #if PY_MAJOR_VERSION >= 3
1587+ if (PyUnicode_Check (callback )) {
1588+ if ((callback_func = get_callback ("__main__" , PyBytes_AsString (PyUnicode_AsEncodedString (PyObject_Str (callback ), "ascii" , NULL )))) == (PyObject * )NULL ) {
1589+ #else
15711590 if (PyString_Check (callback )) {
15721591 if ((callback_func = get_callback ("__main__" , PyString_AsString (callback ))) == (PyObject * )NULL ) {
1592+ #endif
15731593 PyObject * err_type , * err_value , * err_traceback ;
15741594 PyErr_Fetch (& err_type , & err_value , & err_traceback );
15751595 PyErr_Restore (err_type , err_value , err_traceback );
0 commit comments