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.

  #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)

    PyModule_AddIntMacro(m, CAN_EFF_FLAG);

    PyObject * PyLong_FromLong(long ival)

    #define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)


Python tracker <>
Python-bugs-list mailing list

Reply via email to