[issue16572] Bad multi-inheritance support in some libs like threading or multiprocessing

2012-11-28 Thread Thomas Chiroux

New submission from Thomas Chiroux:

when using multi-inheritance and super() in __init__(), super() tries to run 
each constructor once.
For this to work correctly, it is needed to call super() in each constructor, 
including for Classes directly inherited from object.

The sample below does not execute correctly because threading.Thread 
constructor does not call super()
(and because Thread inherit from _Verbose, _Verbose should also call super() )

Sample:
from threading import Thread


class Foo(object):
def __init__(self):
super(Foo, self).__init__()
print('Foo constructor')
self.param1 = 'foo param1'


class Bar(Thread, Foo):
def __init__(self):
super(Bar, self).__init__()
print('Bar constructor')
self.another_param1 = "bar another_param1"

def run(self):
print("Running (%s - %s)" % (self.another_param1, self.param1))


if __name__ == '__main__':
threads = []
for i in range(1, 10):
thread = Bar()
threads.append(thread)
thread.start()

for thread in threads:
thread.join()


This sample work by simply inverting Thread and Foo :

(...)
class Bar(Foo, Thread):
(...)

The sample is about threading.Thread, but it's also the same for 
multiprocessing.Process, and maybe for other modules in stdlib.

attached is a proposed path for threading.Tread in 2.7

I've tested the issue and have the same behavior in 2.7 and in 3.3

--
components: Library (Lib)
files: diff_threading.py_2.7.patch
keywords: patch
messages: 176576
nosy: thomas.chiroux
priority: normal
severity: normal
status: open
title: Bad multi-inheritance support in some libs like threading or 
multiprocessing
type: behavior
versions: Python 2.7, Python 3.3
Added file: http://bugs.python.org/file28150/diff_threading.py_2.7.patch

___
Python tracker 
<http://bugs.python.org/issue16572>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16572] Bad multi-inheritance support in some libs like threading or multiprocessing

2012-11-28 Thread Thomas Chiroux

Thomas Chiroux added the comment:

updated diff file, unified format

--
Added file: http://bugs.python.org/file28151/diff_unified_threading.py_2.7.patch

___
Python tracker 
<http://bugs.python.org/issue16572>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16572] Bad multi-inheritance support in some libs like threading or multiprocessing

2012-11-28 Thread Thomas Chiroux

Thomas Chiroux added the comment:

That's right.
Lets consider this 'patch' was more for illustrating my example (like:  this 
kind of modification may work) than to add directly into python core module... 
(which i'm not capable of)

But I think the problem remains: do you agree that Classes should include a 
super() call in their __init__ ?
[btw indeed a super() call with kwargs: super(ClassName, 
self).__init__(**kwargs)]

--

___
Python tracker 
<http://bugs.python.org/issue16572>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23444] HCI Bluetooth socket bind error on an arm crosscompiler environment

2015-02-11 Thread Thomas Chiroux

New submission from Thomas Chiroux:

This bug bellow occurs only on my crosscompiled environment on arm (marvell 
armada 166): arm-pxa168-linux-gnueabi
It does not seems to be a cross-compile issue: python compiles without problem 
and all unittests pass on the target device.

description and first clues
---

The problem is easyly reproducted using this script:

#!/usr/bin/python
import socket
sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, 
socket.BTPROTO_HCI)
sock.bind((0,))

which raises the following exception when run on the target device:

Traceback (most recent call last):
  File "./test_bt.py", line 4, in 
 sock.bind((0,))
OSError: [Errno 22] Invalid argument

This does not give much clues, but strace does (i've filtered to display the
two significant parts of strace)

socket(PF_BLUETOOTH, SOCK_RAW|SOCK_CLOEXEC, 1) = 3
bind(3, {sa_family=AF_UNSPEC, 
sa_data="\0\0\360\35\251\266s\316(U\3\0\0\0"}, 6) = -1 EINVAL (Invalid argument)


(on a working environment, including arm, like a raspberry pi, strace gives the 
following result (and no traceback of course):

socket(PF_BLUETOOTH, SOCK_RAW|SOCK_CLOEXEC, 1) = 3
bind(3, {sa_family=AF_BLUETOOTH, 
sa_data="\0\0\0\0\0\0X\352\243\266\0\24\265\266"}, 6) = 0

So, on the armada166, between the socket creation and the bind we lost the 
socket family (AF_UNSPEC instead of AF_BLUETOOTH).

And That's why bind returns invalid argument.

socketmodule and PyArg_ParseTuple
-

Now let's look at Modules/socketmodule.c:

After some digging, i've found that the problem is in getsockaddrarg, in the 
AF_BLUETOOTH / BTPROTO_HCI case
and more precisely on this line:

https://hg.python.org/cpython/file/ab2c023a9432/Modules/socketmodule.c#l1449

reproducted here:

if (!PyArg_ParseTuple(args, "i", &_BT_HCI_MEMB(addr, dev))) {

When we execute the PyArg_ParseTuple, the addr->hci_family is crunched (by 
zeros with my previous python sample).

At this same place, i've done the following test:

char buffer[8];
memset(buffer, 0x55, 8);
if (!PyArg_ParseTuple(args, "i", buffer) {
PyErr_SetString(PyExc_OSError, "getsockaddrarg: "
"wrong format");
return 0;
}
printf("CL: %d %d %d %d %d %d %d %d\n", buffer[0], buffer[1], buffer[2], 
buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
 
memset(buffer, 0xAA, 8);
if (!PyArg_ParseTuple(args, "i", buffer+1) {
PyErr_SetString(PyExc_OSError, "getsockaddrarg: "
"wrong format");
return 0;
}
printf("CL+1: %d %d %d %d %d %d %d %d\n", buffer[0], buffer[1], buffer[2], 
buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
 
  
memset(buffer, 0xBB, 8);
if (!PyArg_ParseTuple(args, "i", buffer+2) {
PyErr_SetString(PyExc_OSError, "getsockaddrarg: "
"wrong format");
return 0;
}
printf("CL+2: %d %d %d %d %d %d %d %d\n", buffer[0], buffer[1], buffer[2], 
buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);
   
memset(buffer, 0xcc, 8);
if (!PyArg_ParseTuple(args, "i", buffer+3) {
PyErr_SetString(PyExc_OSError, "getsockaddrarg: "
"wrong format");
return 0;
}
printf("CL+3: %d %d %d %d %d %d %d %d\n", buffer[0], buffer[1], buffer[2], 
buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]);

and the result is:

CL: 0 0 0 0 85 85 85 85
CL+1: 0 0 0 0 170 170 170 170
CL+2: 0 0 0 0 187 187 187 187
CL+3: 0 0 0 0 204 204 204 204

(WTF ??)

in a working environnement (tested on raspberry B+ / python 3.4.2 locally 
compiled) result is what we should expect:

CL: 0 0 0 0 85 85 85 85
CL+1: 170 0 0 0 0 170 170 170
CL+2: 187 187 0 0 0 0 187 187
CL+3: 204 204 204 0 0 0 0 204

So on my box if PyArg_ParseTuple write on &addr->hci_dev if write 4 bytes from 
&addr->hci_family which is 2 bytes BEFORE &addr->hci_dev

At this time I can not understand how it's possible.

Remarks and patch
-

Now I have several remarks and a working patch.

* remark/question 1: why does PyArg_ParseTuple parse an int when addr->hci_dev 
is an unsigned short ?
even in normal situation, when it works, writing on &addr->hci_dev overflow on 
the next two bytes which are btw addr->channel (more on that later)
 
* remark/question 2: i've tried to dig more deeply inside PyArg_ParseTuple and 
found another odd thing, but I did not try to change it without knowing what I 
do:

in Python/getargs.c, in convertsimple, int parsing result is not casted before 
returned:

here: https://hg.

[issue23444] HCI Bluetooth socket bind error on an arm crosscompiled environment

2015-02-11 Thread Thomas Chiroux

Changes by Thomas Chiroux :


--
title: HCI Bluetooth socket bind error on an arm crosscompiler environment -> 
HCI Bluetooth socket bind error on an arm crosscompiled environment

___
Python tracker 
<http://bugs.python.org/issue23444>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com