comparison src/lstream.c @ 3263:d674024a8674

[xemacs-hg @ 2006-02-27 16:29:00 by crestani] - Introduce a fancy asynchronous finalization strategy on C level. - Merge the code conditioned on MC_ALLOC into the code conditioned on NEW_GC. - Remove the possibility to free objects manually outside garbage collections when the new collector is enabled.
author crestani
date Mon, 27 Feb 2006 16:29:29 +0000
parents b7f26b2f78bd
children 16112448d484 e0db3c197671
comparison
equal deleted inserted replaced
3262:79d41cfd8e6b 3263:d674024a8674
178 case LSTREAM_UNLIMITED: 178 case LSTREAM_UNLIMITED:
179 lstr->buffering_size = INT_MAX; break; 179 lstr->buffering_size = INT_MAX; break;
180 } 180 }
181 } 181 }
182 182
183 #ifndef MC_ALLOC 183 #ifndef NEW_GC
184 static const Lstream_implementation *lstream_types[32]; 184 static const Lstream_implementation *lstream_types[32];
185 static Lisp_Object Vlstream_free_list[32]; 185 static Lisp_Object Vlstream_free_list[32];
186 static int lstream_type_count; 186 static int lstream_type_count;
187 #endif /* not MC_ALLOC */ 187 #endif /* not NEW_GC */
188 188
189 /* Allocate and return a new Lstream. This function is not really 189 /* Allocate and return a new Lstream. This function is not really
190 meant to be called directly; rather, each stream type should 190 meant to be called directly; rather, each stream type should
191 provide its own stream creation function, which creates the stream 191 provide its own stream creation function, which creates the stream
192 and does any other necessary creation stuff (e.g. opening a 192 and does any other necessary creation stuff (e.g. opening a
194 194
195 Lstream * 195 Lstream *
196 Lstream_new (const Lstream_implementation *imp, const char *mode) 196 Lstream_new (const Lstream_implementation *imp, const char *mode)
197 { 197 {
198 Lstream *p; 198 Lstream *p;
199 #ifdef MC_ALLOC 199 #ifdef NEW_GC
200 p = XLSTREAM (wrap_pointer_1 200 p = XLSTREAM (wrap_pointer_1
201 (alloc_lrecord (aligned_sizeof_lstream (imp->size), 201 (alloc_lrecord (aligned_sizeof_lstream (imp->size),
202 &lrecord_lstream))); 202 &lrecord_lstream)));
203 #else /* not MC_ALLOC */ 203 #else /* not NEW_GC */
204 int i; 204 int i;
205 205
206 for (i = 0; i < lstream_type_count; i++) 206 for (i = 0; i < lstream_type_count; i++)
207 { 207 {
208 if (lstream_types[i] == imp) 208 if (lstream_types[i] == imp)
218 &lrecord_lstream); 218 &lrecord_lstream);
219 lstream_type_count++; 219 lstream_type_count++;
220 } 220 }
221 221
222 p = XLSTREAM (alloc_managed_lcrecord (Vlstream_free_list[i])); 222 p = XLSTREAM (alloc_managed_lcrecord (Vlstream_free_list[i]));
223 #endif /* not MC_ALLOC */ 223 #endif /* not NEW_GC */
224 /* Zero it out, except the header. */ 224 /* Zero it out, except the header. */
225 memset ((char *) p + sizeof (p->header), '\0', 225 memset ((char *) p + sizeof (p->header), '\0',
226 aligned_sizeof_lstream (imp->size) - sizeof (p->header)); 226 aligned_sizeof_lstream (imp->size) - sizeof (p->header));
227 p->imp = imp; 227 p->imp = imp;
228 Lstream_set_buffering (p, LSTREAM_BLOCK_BUFFERED, 0); 228 Lstream_set_buffering (p, LSTREAM_BLOCK_BUFFERED, 0);
294 will be aborted. See free_managed_lcrecord(). */ 294 will be aborted. See free_managed_lcrecord(). */
295 295
296 void 296 void
297 Lstream_delete (Lstream *lstr) 297 Lstream_delete (Lstream *lstr)
298 { 298 {
299 #ifndef MC_ALLOC 299 #ifndef NEW_GC
300 int i; 300 int i;
301 #endif /* not MC_ALLOC */ 301 #endif /* not NEW_GC */
302 Lisp_Object val = wrap_lstream (lstr); 302 Lisp_Object val = wrap_lstream (lstr);
303 303
304 #ifdef MC_ALLOC 304 #ifdef NEW_GC
305 free_lrecord (val); 305 free_lrecord (val);
306 #else /* not MC_ALLOC */ 306 #else /* not NEW_GC */
307 for (i = 0; i < lstream_type_count; i++) 307 for (i = 0; i < lstream_type_count; i++)
308 { 308 {
309 if (lstream_types[i] == lstr->imp) 309 if (lstream_types[i] == lstr->imp)
310 { 310 {
311 free_managed_lcrecord (Vlstream_free_list[i], val); 311 free_managed_lcrecord (Vlstream_free_list[i], val);
312 return; 312 return;
313 } 313 }
314 } 314 }
315 315
316 ABORT (); 316 ABORT ();
317 #endif /* not MC_ALLOC */ 317 #endif /* not NEW_GC */
318 } 318 }
319 319
320 #define Lstream_internal_error(reason, lstr) \ 320 #define Lstream_internal_error(reason, lstr) \
321 signal_error (Qinternal_error, reason, wrap_lstream (lstr)) 321 signal_error (Qinternal_error, reason, wrap_lstream (lstr))
322 322
1863 LSTREAM_HAS_METHOD (lisp_buffer, writer); 1863 LSTREAM_HAS_METHOD (lisp_buffer, writer);
1864 LSTREAM_HAS_METHOD (lisp_buffer, rewinder); 1864 LSTREAM_HAS_METHOD (lisp_buffer, rewinder);
1865 LSTREAM_HAS_METHOD (lisp_buffer, marker); 1865 LSTREAM_HAS_METHOD (lisp_buffer, marker);
1866 } 1866 }
1867 1867
1868 #ifndef MC_ALLOC 1868 #ifndef NEW_GC
1869 void 1869 void
1870 reinit_vars_of_lstream (void) 1870 reinit_vars_of_lstream (void)
1871 { 1871 {
1872 int i; 1872 int i;
1873 1873
1875 { 1875 {
1876 Vlstream_free_list[i] = Qnil; 1876 Vlstream_free_list[i] = Qnil;
1877 staticpro_nodump (&Vlstream_free_list[i]); 1877 staticpro_nodump (&Vlstream_free_list[i]);
1878 } 1878 }
1879 } 1879 }
1880 #endif /* not MC_ALLOC */ 1880 #endif /* not NEW_GC */
1881 1881
1882 void 1882 void
1883 vars_of_lstream (void) 1883 vars_of_lstream (void)
1884 { 1884 {
1885 INIT_LRECORD_IMPLEMENTATION (lstream); 1885 INIT_LRECORD_IMPLEMENTATION (lstream);