New issue 2232: Program will be terminated by Windows if i using Global object,
import_from_mixin, lltype.free at the same time
https://bitbucket.org/pypy/pypy/issues/2232/program-will-be-terminated-by-windows-if-i
ggg ggg:
I use RPython to compile the code below(not real code, just demonstration).
After executing the exe file, the program will be terminated by Windows.
```
#!python
class Global_Object(object):
def __init__(self):
self._default_colors = []
def add_default_color(self, default_color):
self._default_colors.append(default_color)
def destroy(self):
for default_color in self._default_colors:
default_color.destroy()
global_object = Global_Object()
class Sdl_Color_Mixin:
def initialize_sdl_color_mixin(self, r, g, b, a):
self._sdl_color = lltype.malloc(SDL_Color, flavor='raw')
rffi.setintfield(self._sdl_color, 'c_r', r)
rffi.setintfield(self._sdl_color, 'c_g', g)
rffi.setintfield(self._sdl_color, 'c_b', b)
rffi.setintfield(self._sdl_color, 'c_a', a)
def destroy_sdl_color_mixin(self):
lltype.free(self._sdl_color, flavor='raw') # the program is terminated
at this line
class Default_Color(object):
import_from_mixin(Sdl_Color_Mixin)
def __init__(self, r, g, b, a=255):
self.initialize_sdl_color_mixin(r, g, b, a)
global_object.add_default_color(self)
def destroy(self):
self.destroy_sdl_color_mixin()
RED = Default_Color(255, 0, 0)
global_object.destroy()
```
If i don't use import_from_mixin and copy all the code in the Sdl_Color_Mixin
to Default_Color like the code below, then everything is fine.
```
#!python
class Global_Object(object):
def __init__(self):
self._default_colors = []
def add_default_color(self, default_color):
self._default_colors.append(default_color)
def destroy(self):
for default_color in self._default_colors:
default_color.destroy()
global_object = Global_Object()
class Default_Color(object):
import_from_mixin(Sdl_Color_Mixin)
def __init__(self, r, g, b, a=255):
self.initialize_sdl_color_mixin(r, g, b, a)
global_object.add_default_color(self)
def destroy(self):
self.destroy_sdl_color_mixin()
def initialize_sdl_color_mixin(self, r, g, b, a):
self._sdl_color = lltype.malloc(SDL_Color, flavor='raw')
rffi.setintfield(self._sdl_color, 'c_r', r)
rffi.setintfield(self._sdl_color, 'c_g', g)
rffi.setintfield(self._sdl_color, 'c_b', b)
rffi.setintfield(self._sdl_color, 'c_a', a)
def destroy_sdl_color_mixin(self):
lltype.free(self._sdl_color, flavor='raw')
RED = Default_Color(255, 0, 0)
global_object.destroy()
```
This is strange. Since the program is terminated at lltype.free, the problem
should be around the pointer, but i am pretty sure that the pointer is valid
and i did not delete it twice. If the problem is the wrong usage of pointer, it
can not explain why i just move the code from Sdl_Color_Mixin to Default_Color
then the program will not be terminated either. The problem occurs only if the
target is a global object like RED. If i create a Default_Color object in the
main function, the program will not be terminated. I guess the
import_from_mixin has some side effect when using on global object.
_______________________________________________
pypy-issue mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-issue