PyObject * gdb_py_object_from_longest (LONGEST l) { #ifdef IS_PY3K if (sizeof (l) > sizeof (long)) return PyLong_FromLongLong (l); return PyLong_FromLong (l); #else #ifdef HAVE_LONG_LONG /* Defined by Python. */ /* If we have 'long long', and the value overflows a 'long', use a Python Long; otherwise use a Python Int. */ if (sizeof (l) > sizeof (long) && (l > PyInt_GetMax () || l < (- (LONGEST) PyInt_GetMax ()) - 1)) return PyLong_FromLongLong (l); #endif return PyInt_FromLong (l); #endif }
PyObject * syck_PyIntMaker( long num ) { if ( num > PyInt_GetMax() ) { return PyLong_FromLong( num ); } else { return PyInt_FromLong( num ); } }
/* XXX PyRange_New should be deprecated. It's not documented. It's not * used in the core. Its error-checking is akin to Swiss cheese: accepts * step == 0; accepts len < 0; ignores that (len - 1) * step may overflow; * raises a baffling "integer addition" exception if it thinks the last * item is "too big"; and doesn't compute whether "last item is too big" * correctly even if the multiplication doesn't overflow. */ PyObject * PyRange_New(long start, long len, long step, int reps) { rangeobject *obj; if (reps != 1) { PyErr_SetString(PyExc_ValueError, "PyRange_New's 'repetitions' argument must be 1"); return NULL; } obj = PyObject_New(rangeobject, &PyRange_Type); if (obj == NULL) return NULL; if (len == 0) { start = 0; len = 0; step = 1; } else { long last = start + (len - 1) * step; if ((step > 0) ? (last > (PyInt_GetMax() - step)) : (last < (-1 - PyInt_GetMax() - step))) { PyErr_SetString(PyExc_OverflowError, "integer addition"); Py_DECREF(obj); return NULL; } } obj->start = start; obj->len = len; obj->step = step; return (PyObject *) obj; }
static PyObject* do_mkvalue(const char** p_format, va_list* p_va, int flags) noexcept { for (;;) { switch (*(*p_format)++) { case '(': return do_mktuple(p_format, p_va, ')', countformat(*p_format, ')'), flags); case '[': return do_mklist(p_format, p_va, ']', countformat(*p_format, ']'), flags); case '{': return do_mkdict(p_format, p_va, '}', countformat(*p_format, '}'), flags); case 'b': case 'B': case 'h': case 'i': return PyInt_FromLong((long)va_arg(*p_va, int)); case 'H': return PyInt_FromLong((long)va_arg(*p_va, unsigned int)); case 'I': { unsigned int n; n = va_arg(*p_va, unsigned int); if (n > (unsigned long)PyInt_GetMax()) return PyLong_FromUnsignedLong((unsigned long)n); else return PyInt_FromLong(n); } case 'n': #if SIZEOF_SIZE_T != SIZEOF_LONG return PyInt_FromSsize_t(va_arg(*p_va, Py_ssize_t)); #endif /* Fall through from 'n' to 'l' if Py_ssize_t is long */ case 'l': return PyInt_FromLong(va_arg(*p_va, long)); case 'd': return PyFloat_FromDouble(va_arg(*p_va, double)); case 'N': case 'S': case 'O': if (**p_format == '&') { typedef PyObject* (*converter)(void*); converter func = va_arg(*p_va, converter); void* arg = va_arg(*p_va, void*); ++*p_format; return (*func)(arg); } else { PyObject* v; v = va_arg(*p_va, PyObject*); if (v != NULL) { if (*(*p_format - 1) != 'N') Py_INCREF(v); } else if (!PyErr_Occurred()) /* If a NULL was passed * because a call that should * have constructed a value * failed, that's OK, and we * pass the error on; but if * no error occurred it's not * clear that the caller knew * what she was doing. */ PyErr_SetString(PyExc_SystemError, "NULL object passed to Py_BuildValue"); return v; } case 's': case 'z': { PyObject* v; char* str = va_arg(*p_va, char*); Py_ssize_t n; if (**p_format == '#') { ++*p_format; if (flags & FLAG_SIZE_T) n = va_arg(*p_va, Py_ssize_t); else n = va_arg(*p_va, int); } else n = -1; if (str == NULL) { v = Py_None; Py_INCREF(v); } else { if (n < 0) { size_t m = strlen(str); if (m > PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "string too long for Python string"); return NULL; } n = (Py_ssize_t)m; } v = PyString_FromStringAndSize(str, n); } return v; }