Kyle Altendorf added the comment: A little macro funny business gets a function the ability to know if the type passed to its wrapping macro is signed or not.
http://ideone.com/NZYs7u <snippet> // http://stackoverflow.com/questions/7469915 #define IS_UNSIGNED(v) (v >= 0 && ~v >= 0) #define F(v) f(IS_UNSIGNED(v), v, v) void f (bool is_unsigned, intmax_t s, uintmax_t u) Looking in `Objects/longobject.c` suggests that perhaps the two functions that could be chosen from would be `PyLong_From[Unsigned]LongLong()` to avoid truncation. Is there some reason not to use these? I don't know the habits of CPython developers to know if there's a significant optimization going on here. Just to throw it out there, in the case of macros, `PyLong_FromString()` might even be usable... Included for quick reference: int PyModule_AddIntConstant(PyObject *m, const char *name, long value) https://hg.python.org/cpython/file/tip/Python/modsupport.c#l566 PyModule_AddIntMacro(m, CAN_EFF_FLAG); https://hg.python.org/cpython/file/tip/Modules/socketmodule.c#l7098 PyObject * PyLong_FromLong(long ival) https://hg.python.org/cpython/file/tip/Objects/longobject.c#l231 #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c) https://hg.python.org/cpython/file/tip/Include/modsupport.h#l80 ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28215> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com