@@ -169,14 +169,6 @@ def compile_ext(name):
169
169
)
170
170
'''
171
171
172
- # language=C
173
- C_SOURCE_HEADER = '''
174
- #include <Python.h>
175
-
176
- PyObject *global_stash1;
177
- PyObject *global_stash2;
178
- '''
179
-
180
172
181
173
def write_all (filename , text ):
182
174
with open (filename , 'w+' ) as f :
@@ -212,6 +204,14 @@ def tp_decl(self, name_prefix):
212
204
213
205
NO_GROUP = 'top'
214
206
207
+ # language=C
208
+ C_SOURCE_HEADER = '''
209
+ #include <Python.h>
210
+
211
+ PyObject *global_stash1;
212
+ PyObject *global_stash2;
213
+ '''
214
+
215
215
SLOTS = [
216
216
Slot ('tp_as_number' , 'nb_bool' , 'int $name$(PyObject* self)' , ['1' , '0' , None ]),
217
217
Slot ('tp_as_sequence' , 'sq_length' , 'Py_ssize_t $name$(PyObject* self)' , ['0' , '1' , '42' , None ]),
@@ -235,13 +235,14 @@ def tp_decl(self, name_prefix):
235
235
global_stash1 = value;
236
236
return 0;
237
237
''' ]),
238
- Slot (NO_GROUP , 'tp_setattr' , 'int $name$(PyObject* self, char *name, PyObject *value)' , ['0' , None ,
239
- '''
240
- Py_IncRef(value);
241
- Py_XDECREF(global_stash1);
242
- global_stash1 = value;
243
- return 0;
244
- ''' ]),
238
+ # Disabled due to incompatibilities with Carlo Verre hack in some very specific corner cases
239
+ # Slot(NO_GROUP, 'tp_setattr', 'int $name$(PyObject* self, char *name, PyObject *value)', ['0', None,
240
+ # '''
241
+ # Py_IncRef(value);
242
+ # Py_XDECREF(global_stash1);
243
+ # global_stash1 = value;
244
+ # return 0;
245
+ # ''']),
245
246
Slot (NO_GROUP , 'tp_descr_get' , 'PyObject* $name$(PyObject* self, PyObject* key, PyObject* type)' , ['Py_RETURN_NONE' , 'Py_NewRef(key)' , None ,
246
247
'''
247
248
if (global_stash2 == NULL) Py_RETURN_NONE;
@@ -257,26 +258,33 @@ def tp_decl(self, name_prefix):
257
258
''' ])
258
259
]
259
260
261
+ PY_GLOBALS = '''
262
+ global_dict1 = dict()
263
+ global_descr_val = None
264
+ '''
260
265
261
266
MAGIC = {
262
267
'__bool__(self)' : ['True' , 'False' , None ],
263
268
'__len__(self)' : ['0' , '1' , '42' , None ],
264
- '__getattribute__(self,name)' : ['name' , '42' , 'self._dict[name]' , None ],
265
- '__getattr__(self,name)' : ['name+"abc"' , 'False' , 'self._dict[name]' , None ],
266
- '__get__(self,obj,objtype=None)' : ['obj' , 'True' , 'self.descr_value' , None ],
267
- '__set__(self,obj,value)' : ['self.descr_value = value\n return None' , None ],
269
+ '__getattribute__(self,name)' : ['name' , '42' , 'global_dict1[name]' , None ],
270
+ '__getattr__(self,name)' : ['name+"abc"' , 'False' , 'global_dict1[name]' , None ],
271
+ '__get__(self,obj,objtype=None)' : ['obj' , 'True' , 'global_descr_val' , None ],
272
+ '__set__(self,obj,value)' : [None ,
273
+ '''
274
+ global global_descr_val
275
+ global_descr_val = value
276
+ return None
277
+ ''' ],
268
278
'__setattr__(self,name,value)' : [None ,
269
279
'''
270
- if not self._dict:
271
- self._dict = dict()
272
- self._dict[name] = value
280
+ global global_dict1 # not using self._dict, because attr lookup can be something funky...
281
+ global_dict1[name] = value
273
282
return None
274
283
''' ],
275
284
'__delattr__(self,name,value)' : [None ,
276
285
'''
277
- if not self._dict:
278
- self._dict = dict()
279
- del self._dict[name]
286
+ global global_dict1
287
+ del global_dict1[name]
280
288
return None
281
289
''' ],
282
290
}
@@ -446,7 +454,7 @@ def choose_random(l):
446
454
classes = []
447
455
test_module_name = f"test{ test_case_idx } "
448
456
c_source = C_SOURCE_HEADER
449
- py_source = SLOTS_TESTER
457
+ py_source = SLOTS_TESTER + PY_GLOBALS
450
458
native_classes = []
451
459
for i in range (classes_count ):
452
460
base = choose_random (classes ) if classes else 'object'
0 commit comments