This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author altendky
Recipients altendky, christian.heimes, vstinner
Date 2016-09-20.18:31:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474396284.55.0.365698552648.issue28215@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2016-09-20 18:31:24altendkysetrecipients: + altendky, vstinner, christian.heimes
2016-09-20 18:31:24altendkysetmessageid: <1474396284.55.0.365698552648.issue28215@psf.upfronthosting.co.za>
2016-09-20 18:31:24altendkylinkissue28215 messages
2016-09-20 18:31:24altendkycreate