diff options
Diffstat (limited to 'c')
| -rw-r--r-- | c/_cffi_backend.c | 8 | ||||
| -rw-r--r-- | c/misc_win32.h | 22 | ||||
| -rw-r--r-- | c/test_c.py | 5 |
3 files changed, 32 insertions, 3 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c index cf8ac37..138e2fb 100644 --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -197,6 +197,8 @@ static void init_errno(void) { } # else # include "misc_thread.h" # endif +# define save_errno_only save_errno +# define restore_errno_only restore_errno #endif #ifdef HAVE_WCHAR_H @@ -3182,7 +3184,7 @@ static ffi_type *fb_fill_type(struct funcbuilder_s *fb, CTypeDescrObject *ct, else if (ct->ct_flags & (CT_POINTER|CT_ARRAY|CT_FUNCTIONPTR)) { return &ffi_type_pointer; } - else if (ct->ct_flags & CT_VOID) { + else if ((ct->ct_flags & CT_VOID) && is_result_type) { return &ffi_type_void; } @@ -4044,7 +4046,7 @@ static PyObject *b_buffer(PyObject *self, PyObject *args) static PyObject *b_get_errno(PyObject *self, PyObject *noarg) { int err; - restore_errno(); + restore_errno_only(); err = errno; errno = 0; return PyInt_FromLong(err); @@ -4056,7 +4058,7 @@ static PyObject *b_set_errno(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "i:set_errno", &i)) return NULL; errno = i; - save_errno(); + save_errno_only(); errno = 0; Py_INCREF(Py_None); return Py_None; diff --git a/c/misc_win32.h b/c/misc_win32.h index 718514d..115df7a 100644 --- a/c/misc_win32.h +++ b/c/misc_win32.h @@ -45,6 +45,18 @@ static void save_errno(void) /* else: cannot report the error */ } +static void save_errno_only(void) +{ + int current_err = errno; + struct cffi_errno_s *p; + + p = _geterrno_object(); + if (p != NULL) { + p->saved_errno = current_err; + } + /* else: cannot report the error */ +} + static void restore_errno(void) { struct cffi_errno_s *p; @@ -57,6 +69,16 @@ static void restore_errno(void) /* else: cannot report the error */ } +static void restore_errno_only(void) +{ + struct cffi_errno_s *p; + + p = _geterrno_object(); + if (p != NULL) { + errno = p->saved_errno; + } + /* else: cannot report the error */ +} /************************************************************/ /* Emulate dlopen()&co. from the Windows API */ diff --git a/c/test_c.py b/c/test_c.py index bd080ad..2faedd5 100644 --- a/c/test_c.py +++ b/c/test_c.py @@ -773,6 +773,11 @@ def test_function_void_result(): BFunc = new_function_type((BInt, BInt), BVoid, False) assert repr(BFunc) == "<ctype 'void(*)(int, int)'>" +def test_function_void_arg(): + BVoid = new_void_type() + BInt = new_primitive_type("int") + py.test.raises(TypeError, new_function_type, (BVoid,), BInt, False) + def test_call_function_0(): BSignedChar = new_primitive_type("signed char") BFunc0 = new_function_type((BSignedChar, BSignedChar), BSignedChar, False) |
