[issue35366] Monkey Patching class derived from ctypes.Union doesn't work

2018-12-02 Thread Vijay


Vijay  added the comment:

Wanted to post a possible workaround until this is fixed. One can simply wrap a 
union anonymously inside a structure. Like so:

struct my_struct_s {
  union my_union_u {

  };
};

This temporarily solved the problem in my case.

--

___
Python tracker 

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



[issue35366] Monkey Patching class derived from ctypes.Union doesn't work

2018-11-30 Thread Martijn Pieters


Martijn Pieters  added the comment:

This is a repeat of old-tracker issue 1700288, see 
https://github.com/python/cpython/commit/08ccf202e606a08f4ef85df9a9c0d07e1ba1#diff-998bfefaefe2ab83d5f523e18f158fa4,
 which fixed this for StructType_setattro but failed to do the same for 
UnionType_setattro

--
nosy: +mjpieters

___
Python tracker 

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



[issue35366] Monkey Patching class derived from ctypes.Union doesn't work

2018-11-30 Thread Vijay


New submission from Vijay :

I am trying to "monkey patch" a class derived from Python ctypes "Union", but I 
am unable to do so - getting weird errors and sometimes seg-faults. The same 
thing works quite well when deriving from ctypes "Structure".

I have narrowed this to down to the simplest possible test case which I am 
posting below. I am using Python 3.6.4. I am wondering if I am doing something 
wrong (or is there a problem with the ctypes "Union" implementation?). 

The example python code is attached with this issue.

Please see the output below (for the attached code in Python 3.6.4).

Using Structure:

Print Type #1: [ 10, 20 ]
Original : 
Patched : 
Patched (dict) : 
Print Type #2: ( 10, 20 )
Using Union:

Print Type #1: [ 20, 20 ]
Original : 
Patched : 
Patched (dict) : 
Traceback (most recent call last):
  File "ctypes_bug.py", line 54, in 
print(a)
TypeError: 'managedbuffer' object is not callable

Clearly, I am able to "patch" __str__ when the corresponding Python object was 
derived from "Structure", but I am unable to "patch" __str__ when the 
corresponding Python object was derived from "Union".

Interestingly, MyUnion.__dict__[__str__] and MyUnion.__str__ shows different 
results - which is weird as well.

Is there something I am doing wrong here, or is there an issue with 
ctypes.Union? I highly appreciate any help or insight!

--
components: ctypes
files: ctypes_bug.py
messages: 330817
nosy: rvijayc
priority: normal
severity: normal
status: open
title: Monkey Patching class derived from ctypes.Union doesn't work
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file47961/ctypes_bug.py

___
Python tracker 

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