New submission from Kyle Altendorf:

I am cross compiling Python 3.5.2 for use on a 32-bit ARM processor with Linux. 
 I use socket.CAN_EFF_FLAG and noticed that it is negative on the target 
despite being positive on my host (64-bit Intel Linux).

  Host:

altendky@tp:~$ uname -a
Linux tp 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 
x86_64 x86_64 GNU/Linux
altendky@tp:~$ python3 --version
Python 3.5.2
altendky@tp:~$ python3 -c 'import socket; print(socket.CAN_EFF_FLAG)'
2147483648

  ^^ Is expected


  Target:

root@rosi ~$ uname -a
Linux rosi 3.0.101-rt130-opusa3-2.1.0-2 #1 PREEMPT Tue Apr 12 13:49:26 CEST 
2016 armv6l GNU/Linux
root@rosi ~$ /opt/epc/bin/python3 --version
Python 3.5.2
root@rosi ~$ /opt/epc/bin/python3 -c 'import socket; print(socket.CAN_EFF_FLAG)'
-2147483648

  ^^ Is not expected to be negative


  Only CAN_EFF_FLAG reference in my source used to cross build Python:

Modules/socketmodule.c:    PyModule_AddIntMacro(m, CAN_EFF_FLAG);


  Definition in cross compiler include:

altendky@tp:/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/arm-fsl-linux-gnueabi/multi-libs/default/usr/include$
 grep -r CAN_EFF_FLAG
linux/can.h:#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */


  For reference, here it is on the host system (looks the same to me):

altendky@tp:/usr/include$ grep -r CAN_EFF_FLAG
linux/can.h:#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */


  But perhaps this `long` type for the value is the issue?  If signed and only 
4-bytes as is the case on my target then this will misinterpret the 0x80000000U 
literal resulting in the above observed -2147483648.

PyModule_AddIntConstant(PyObject *m, const char *name, long value)

  On my target system, printf("%d", sizeof(long)) yields 4.

  For now I just work around it in my application by reassigning it to be it's 
absolute value.

socket.CAN_EFF_FLAG = abs(socket.CAN_EFF_FLAG)

----------
messages: 277036
nosy: altendky
priority: normal
severity: normal
status: open
title: PyModule_AddIntConstant() wraps >=2^32 values when long is 4 bytes
type: behavior
versions: Python 3.5

_______________________________________
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

Reply via email to