[ctypes-commit] ctypes/source cfield.c,1.74.2.14,1.74.2.15
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-12-14 22:05:50
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2250 Modified Files: Tag: branch_1_0 cfield.c Log Message: Implemented c_double with different endian. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.14 retrieving revision 1.74.2.15 diff -C2 -d -r1.74.2.14 -r1.74.2.15 *** cfield.c 14 Dec 2005 22:00:57 -0000 1.74.2.14 --- cfield.c 14 Dec 2005 22:05:41 -0000 1.74.2.15 *************** *** 893,896 **** --- 893,928 ---- static PyObject * + d_set_sw(void *ptr, PyObject *value, unsigned size) + { + double x; + + x = PyFloat_AsDouble(value); + if (x == -1 && PyErr_Occurred()) { + PyErr_Format(PyExc_TypeError, + " float expected instead of %s instance", + value->ob_type->tp_name); + return NULL; + } + #ifdef IS_BIG_ENDIAN + if (_PyFloat_Pack8(x, (unsigned char *)ptr, 1)) + return NULL; + #else + if (_PyFloat_Pack8(x, (unsigned char *)ptr, 0)) + return NULL; + #endif + _RET(value); + } + + static PyObject * + d_get_sw(void *ptr, unsigned size) + { + #ifdef IS_BIG_ENDIAN + return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 1)); + #else + return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 0)); + #endif + } + + static PyObject * f_set(void *ptr, PyObject *value, unsigned size) { *************** *** 1372,1376 **** { 'B', B_set, B_get, &ffi_type_uchar}, { 'c', c_set, c_get, &ffi_type_schar}, ! { 'd', d_set, d_get, &ffi_type_double/*, d_set_sw, d_get_sw*/}, { 'f', f_set, f_get, &ffi_type_float, f_set_sw, f_get_sw}, { 'h', h_set, h_get, &ffi_type_sshort, h_set_sw, h_get_sw}, --- 1404,1408 ---- { 'B', B_set, B_get, &ffi_type_uchar}, { 'c', c_set, c_get, &ffi_type_schar}, ! { 'd', d_set, d_get, &ffi_type_double, d_set_sw, d_get_sw}, { 'f', f_set, f_get, &ffi_type_float, f_set_sw, f_get_sw}, { 'h', h_set, h_get, &ffi_type_sshort, h_set_sw, h_get_sw}, |