lwes 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ Version 0.3.0 (erik-s-chang)
2
+ * attempt memory allocation failure handling by invoking Ruby GC
3
+ * corner-case fixes for copying TypeDB and Emitter objects
4
+ * for folks without LWES libraries separately installed:
5
+ - backport ESF error handling fix (r344)
6
+ - backport empty events in ESFs fix (inherited fields only) (r307)
7
+
1
8
  Version 0.2.3 (erik-s-chang)
2
9
  * hopefully fix installation/build problems under OSX
3
10
 
data/ext/lwes/emitter.c CHANGED
@@ -7,6 +7,12 @@ static ID id_new;
7
7
  /* the underlying struct for LWES::Emitter */
8
8
  struct _rb_lwes_emitter {
9
9
  struct lwes_emitter *emitter;
10
+ LWES_CONST_SHORT_STRING address;
11
+ LWES_CONST_SHORT_STRING iface;
12
+ LWES_U_INT_32 port;
13
+ LWES_BOOLEAN emit_heartbeat;
14
+ LWES_INT_16 freq;
15
+ LWES_U_INT_32 ttl;
10
16
  };
11
17
 
12
18
  /* gets the _rb_lwes_emitter struct pointer from self */
@@ -26,7 +32,26 @@ static void rle_free(void *ptr)
26
32
 
27
33
  if (rle->emitter)
28
34
  lwes_emitter_destroy(rle->emitter);
29
- rle->emitter = NULL;
35
+ xfree(ptr);
36
+ }
37
+
38
+ static struct lwes_event *
39
+ lwesrb_event_create(struct lwes_event_type_db *db, VALUE name)
40
+ {
41
+ int gc_retry = 1;
42
+ const char *event_name = RSTRING_PTR(name);
43
+ struct lwes_event *event;
44
+
45
+ retry:
46
+ event = lwes_event_create(db, event_name);
47
+ if (!event) {
48
+ if (--gc_retry == 0) {
49
+ rb_gc();
50
+ goto retry;
51
+ }
52
+ rb_raise(rb_eRuntimeError, "failed to create lwes_event");
53
+ }
54
+ return event;
30
55
  }
31
56
 
32
57
  /* called by the GC when object is allocated */
@@ -49,18 +74,20 @@ static VALUE rle_alloc(VALUE klass)
49
74
  static VALUE event_hash_iter_i(VALUE kv, VALUE memo)
50
75
  {
51
76
  VALUE *tmp;
52
- VALUE v;
77
+ VALUE val;
53
78
  struct lwes_event *event = (struct lwes_event *)memo;
54
79
  LWES_CONST_SHORT_STRING name;
55
80
  int rv = 0;
81
+ int gc_retry = 1;
56
82
 
57
83
  assert(TYPE(kv) == T_ARRAY &&
58
84
  "hash iteration not giving key-value pairs");
59
85
  tmp = RARRAY_PTR(kv);
60
86
  name = RSTRING_PTR(rb_obj_as_string(tmp[0]));
87
+ val = tmp[1];
61
88
 
62
- v = tmp[1];
63
- switch (TYPE(v)) {
89
+ retry:
90
+ switch (TYPE(val)) {
64
91
  case T_TRUE:
65
92
  rv = lwes_event_set_BOOLEAN(event, name, TRUE);
66
93
  break;
@@ -68,20 +95,26 @@ static VALUE event_hash_iter_i(VALUE kv, VALUE memo)
68
95
  rv = lwes_event_set_BOOLEAN(event, name, FALSE);
69
96
  break;
70
97
  case T_ARRAY:
71
- rv = lwesrb_event_set_numeric(event, name, v);
98
+ rv = lwesrb_event_set_numeric(event, name, val);
72
99
  break;
73
100
  case T_STRING:
74
- rv = lwes_event_set_STRING(event, name, RSTRING_PTR(v));
101
+ rv = lwes_event_set_STRING(event, name, RSTRING_PTR(val));
75
102
  break;
76
103
  }
77
- if (rv > 0)
104
+ if (rv > 0) {
78
105
  return Qnil;
79
- if (rv == 0)
106
+ } else if (rv == 0) {
80
107
  rb_raise(rb_eArgError, "unhandled type %s=%s for event=%s",
81
- name, RSTRING_PTR(rb_inspect(v)), event->eventName);
82
- /* rv < 0 */
83
- rb_raise(rb_eRuntimeError, "failed to set %s=%s for event=%s",
84
- name, RSTRING_PTR(rb_inspect(v)), event->eventName);
108
+ name, RSTRING_PTR(rb_inspect(val)), event->eventName);
109
+ } else {
110
+ /* looking at the lwes source code, -3 is allocation errors */
111
+ if (rv == -3 && --gc_retry == 0) {
112
+ rb_gc();
113
+ goto retry;
114
+ }
115
+ rb_raise(rb_eRuntimeError, "failed to set %s=%s for event=%s",
116
+ name, RSTRING_PTR(rb_inspect(val)), event->eventName);
117
+ }
85
118
  return Qfalse;
86
119
  }
87
120
 
@@ -99,31 +132,50 @@ static VALUE _emit_hash(VALUE _tmp)
99
132
  return _event;
100
133
  }
101
134
 
102
- static int set_field(
135
+ static void
136
+ set_field(
103
137
  struct lwes_event *event,
104
138
  LWES_CONST_SHORT_STRING name,
105
139
  LWES_TYPE type,
106
140
  VALUE val)
107
141
  {
142
+ int gc_retry = 1;
143
+ int rv;
144
+
145
+ retry:
108
146
  switch (type) {
109
147
  case LWES_TYPE_BOOLEAN:
110
148
  if (val == Qfalse)
111
- return lwes_event_set_BOOLEAN(event, name, FALSE);
149
+ rv = lwes_event_set_BOOLEAN(event, name, FALSE);
112
150
  else if (val == Qtrue)
113
- return lwes_event_set_BOOLEAN(event, name, TRUE);
151
+ rv = lwes_event_set_BOOLEAN(event, name, TRUE);
114
152
  else
115
153
  rb_raise(rb_eTypeError, "non-boolean set for %s: %s",
116
154
  name, RSTRING_PTR(rb_inspect(val)));
155
+ break;
117
156
  case LWES_TYPE_STRING:
118
157
  if (TYPE(val) != T_STRING)
119
158
  rb_raise(rb_eTypeError, "non-String set for %s: %s",
120
159
  name, RSTRING_PTR(rb_inspect(val)));
121
- return lwes_event_set_STRING(event, name, RSTRING_PTR(val));
160
+ rv = lwes_event_set_STRING(event, name, RSTRING_PTR(val));
161
+ break;
122
162
  default:
123
- return lwesrb_event_set_num(event, name, type, val);
163
+ rv = lwesrb_event_set_num(event, name, type, val);
124
164
  }
165
+ if (rv > 0) {
166
+ return;
167
+ } else {
168
+ if (rv == -3 && --gc_retry == 0) {
169
+ rb_gc();
170
+ goto retry;
171
+ }
172
+ rb_raise(rb_eRuntimeError,
173
+ "failed to set %s=%s for event=%s (error: %d)",
174
+ name, RSTRING_PTR(rb_inspect(val)),
175
+ event->eventName, rv);
176
+ }
177
+
125
178
  assert(0 && "you should never get here (set_field)");
126
- return -1;
127
179
  }
128
180
 
129
181
  static VALUE _emit_struct(VALUE _argv)
@@ -144,7 +196,6 @@ static VALUE _emit_struct(VALUE _argv)
144
196
  /* inner: [ :field_sym, "field_name", type ] */
145
197
  VALUE *inner = RARRAY_PTR(*tmp);
146
198
  VALUE val = rb_struct_aref(_event, inner[0]);
147
- int rv;
148
199
  LWES_CONST_SHORT_STRING name;
149
200
  LWES_TYPE type;
150
201
 
@@ -153,14 +204,7 @@ static VALUE _emit_struct(VALUE _argv)
153
204
 
154
205
  name = RSTRING_PTR(inner[1]);
155
206
  type = NUM2INT(inner[2]);
156
- rv = set_field(event, name, type, val);
157
- if (rv > 0)
158
- continue;
159
-
160
- rb_raise(rb_eRuntimeError,
161
- "failed to set %s=%s for event=%s (error: %d)",
162
- name, RSTRING_PTR(rb_inspect(val)),
163
- event->eventName, rv);
207
+ set_field(event, name, type, val);
164
208
  }
165
209
 
166
210
  if (lwes_emitter_emit(_rle(self)->emitter, event) < 0)
@@ -182,10 +226,7 @@ static VALUE _destroy_event(VALUE _event)
182
226
  static VALUE emit_hash(VALUE self, VALUE name, VALUE _event)
183
227
  {
184
228
  VALUE tmp[3];
185
- struct lwes_event *event = lwes_event_create(NULL, RSTRING_PTR(name));
186
-
187
- if (!event)
188
- rb_raise(rb_eRuntimeError, "failed to create lwes_event");
229
+ struct lwes_event *event = lwesrb_event_create(NULL, name);
189
230
 
190
231
  tmp[0] = self;
191
232
  tmp[1] = _event;
@@ -219,9 +260,7 @@ static VALUE emit_struct(VALUE self, VALUE _event)
219
260
  "could not get class NAME or TYPE_LIST from: %s",
220
261
  RSTRING_PTR(rb_inspect(_event)));
221
262
 
222
- event = lwes_event_create(db, RSTRING_PTR(name));
223
- if (!event)
224
- rb_raise(rb_eRuntimeError, "failed to create lwes_event");
263
+ event = lwesrb_event_create(db, name);
225
264
 
226
265
  argv[0] = self;
227
266
  argv[1] = _event;
@@ -311,21 +350,61 @@ static VALUE emitter_emit(int argc, VALUE *argv, VALUE self)
311
350
  */
312
351
  static VALUE emitter_close(VALUE self)
313
352
  {
314
- rle_free(_rle(self));
353
+ struct _rb_lwes_emitter *rle = _rle(self);
354
+
355
+ if (rle->emitter)
356
+ lwes_emitter_destroy(rle->emitter);
357
+ rle->emitter = NULL;
315
358
 
316
359
  return Qnil;
317
360
  }
318
361
 
362
+ static void lwesrb_emitter_create(struct _rb_lwes_emitter *rle)
363
+ {
364
+ int gc_retry = 1;
365
+ retry:
366
+ if (rle->ttl == UINT32_MAX)
367
+ rle->emitter = lwes_emitter_create(
368
+ rle->address, rle->iface, rle->port,
369
+ rle->emit_heartbeat, rle->freq);
370
+ else
371
+ rle->emitter = lwes_emitter_create_with_ttl(
372
+ rle->address, rle->iface, rle->port,
373
+ rle->emit_heartbeat, rle->freq, rle->ttl);
374
+
375
+ if (!rle->emitter) {
376
+ if (--gc_retry == 0) {
377
+ rb_gc();
378
+ goto retry;
379
+ }
380
+ rb_raise(rb_eRuntimeError, "failed to create LWES emitter");
381
+ }
382
+ }
383
+
384
+ /* :nodoc: */
385
+ static VALUE init_copy(VALUE dest, VALUE obj)
386
+ {
387
+ struct _rb_lwes_emitter *dst = _rle(dest);
388
+ struct _rb_lwes_emitter *src = _rle(obj);
389
+
390
+ memcpy(dst, src, sizeof(*dst));
391
+ lwesrb_emitter_create(dst);
392
+
393
+ assert(dst->emitter && dst->emitter != src->emitter &&
394
+ "emitter not a copy");
395
+
396
+ return dest;
397
+ }
398
+
319
399
  /* should only used internally by #initialize */
320
400
  static VALUE _create(VALUE self, VALUE options)
321
401
  {
322
402
  struct _rb_lwes_emitter *rle = _rle(self);
323
403
  VALUE address, iface, port, heartbeat, ttl;
324
- LWES_CONST_SHORT_STRING _address, _iface;
325
- LWES_U_INT_32 _port; /* odd, uint16 would be enough here */
326
- LWES_BOOLEAN _emit_heartbeat = FALSE;
327
- LWES_INT_16 _freq = 0;
328
- LWES_U_INT_32 _ttl = UINT32_MAX; /* nobody sets a ttl this long, right? */
404
+
405
+ rle->emit_heartbeat = FALSE;
406
+ rle->freq = 0;
407
+ rle->ttl = UINT32_MAX; /* nobody sets a ttl this long, right? */
329
408
 
330
409
  if (rle->emitter)
331
410
  rb_raise(rb_eRuntimeError, "already created lwes_emitter");
@@ -335,15 +414,15 @@ static VALUE _create(VALUE self, VALUE options)
335
414
  address = rb_hash_aref(options, ID2SYM(rb_intern("address")));
336
415
  if (TYPE(address) != T_STRING)
337
416
  rb_raise(rb_eTypeError, ":address must be a string");
338
- _address = RSTRING_PTR(address);
417
+ rle->address = RSTRING_PTR(address);
339
418
 
340
419
  iface = rb_hash_aref(options, ID2SYM(rb_intern("iface")));
341
420
  switch (TYPE(iface)) {
342
421
  case T_NIL:
343
- _iface = NULL;
422
+ rle->iface = NULL;
344
423
  break;
345
424
  case T_STRING:
346
- _iface = RSTRING_PTR(iface);
425
+ rle->iface = RSTRING_PTR(iface);
347
426
  break;
348
427
  default:
349
428
  rb_raise(rb_eTypeError, ":iface must be a String or nil");
@@ -352,15 +431,15 @@ static VALUE _create(VALUE self, VALUE options)
352
431
  port = rb_hash_aref(options, ID2SYM(rb_intern("port")));
353
432
  if (TYPE(port) != T_FIXNUM)
354
433
  rb_raise(rb_eTypeError, ":port must be a Fixnum");
355
- _port = NUM2UINT(port);
434
+ rle->port = NUM2UINT(port);
356
435
 
357
436
  heartbeat = rb_hash_aref(options, ID2SYM(rb_intern("heartbeat")));
358
437
  if (TYPE(heartbeat) == T_FIXNUM) {
359
438
  int tmp = NUM2INT(heartbeat);
360
439
  if (tmp > INT16_MAX)
361
440
  rb_raise(rb_eArgError,":heartbeat > INT16_MAX seconds");
362
- _emit_heartbeat = TRUE;
363
- _freq = (LWES_INT_16)tmp;
441
+ rle->emit_heartbeat = TRUE;
442
+ rle->freq = (LWES_INT_16)tmp;
364
443
  } else if (NIL_P(heartbeat)) { /* do nothing, use defaults */
365
444
  } else
366
445
  rb_raise(rb_eTypeError, ":heartbeat must be a Fixnum or nil");
@@ -370,20 +449,12 @@ static VALUE _create(VALUE self, VALUE options)
370
449
  unsigned LONG_LONG tmp = NUM2ULL(ttl);
371
450
  if (tmp >= UINT32_MAX)
372
451
  rb_raise(rb_eArgError, ":ttl >= UINT32_MAX seconds");
373
- _ttl = (LWES_U_INT_32)tmp;
452
+ rle->ttl = (LWES_U_INT_32)tmp;
374
453
  } else if (NIL_P(ttl)) { /* do nothing, no ttl */
375
454
  } else
376
455
  rb_raise(rb_eTypeError, ":ttl must be a Fixnum or nil");
377
456
 
378
- if (_ttl == UINT32_MAX)
379
- rle->emitter = lwes_emitter_create(
380
- _address, _iface, _port, _emit_heartbeat, _freq);
381
- else
382
- rle->emitter = lwes_emitter_create_with_ttl(
383
- _address, _iface, _port, _emit_heartbeat, _freq, _ttl);
384
-
385
- if (!rle->emitter)
386
- rb_raise(rb_eRuntimeError, "failed to create LWES emitter");
457
+ lwesrb_emitter_create(rle);
387
458
 
388
459
  return self;
389
460
  }
@@ -398,6 +469,7 @@ void lwesrb_init_emitter(void)
398
469
  rb_define_method(cLWES_Emitter, "emit", emitter_emit, -1);
399
470
  rb_define_method(cLWES_Emitter, "_create", _create, 1);
400
471
  rb_define_method(cLWES_Emitter, "close", emitter_close, 0);
472
+ rb_define_method(cLWES_Emitter, "initialize_copy", init_copy, 1);
401
473
  rb_define_alloc_func(cLWES_Emitter, rle_alloc);
402
474
  LWESRB_MKID(TYPE_DB);
403
475
  LWESRB_MKID(TYPE_LIST);
data/ext/lwes/extconf.rb CHANGED
@@ -6,6 +6,7 @@ dir_config('lwes')
6
6
  pwd = File.expand_path(File.dirname(__FILE__))
7
7
  v = '0.22.3'
8
8
  dir = "lwes-#{v}"
9
+ diff = "#{pwd}/#{dir}.diff"
9
10
  inst = "#{pwd}/.inst"
10
11
  tgz = "#{dir}.tar.gz"
11
12
  url = "http://sourceforge.net/projects/lwes/files/lwes-c/#{v}/#{tgz}/download"
@@ -37,6 +38,7 @@ unless have_library('lwes') && have_header('lwes.h')
37
38
  FileUtils.rm_rf(dir)
38
39
  system('tar', 'zxf', tgz) or abort "tar failed with #{$?}"
39
40
  Dir.chdir(dir) do
41
+ system("patch", "-p1", "-i", diff) or abort "patch failed: #{$?}"
40
42
  args = %w(--disable-shared
41
43
  --disable-hardcore
42
44
  --with-pic
@@ -0,0 +1,287 @@
1
+ backport of several things from lwes trunk
2
+
3
+ * ESF error handling (r344)
4
+ * empty events in ESFs (inherited fields only) (r307)
5
+
6
+ https://lwes.svn.sourceforge.net/svnroot/lwes/lwes/trunk
7
+
8
+ diff -rup a/src/lwes_esf_parser_y.y b/src/lwes_esf_parser_y.y
9
+ --- a/src/lwes_esf_parser_y.y
10
+ +++ b/src/lwes_esf_parser_y.y
11
+ @@ -63,8 +63,10 @@ eventname: EVENTWORD {
12
+
13
+ ;
14
+
15
+ -attributelist: attribute
16
+ - | attributelist attribute
17
+ +attributelist:
18
+ + /* empty */
19
+ + | attribute
20
+ + | attributelist attribute
21
+ ;
22
+
23
+ attribute: type attributename ';'
24
+ @@ -221,6 +223,7 @@ lwes_parse_esf
25
+ else
26
+ {
27
+ fprintf (stderr,"ERROR: No such file : \"%s\"\n",filename);
28
+ + state.errors++;
29
+ }
30
+
31
+ if (state.errors)
32
+ diff -rup a/src/lwes_event_type_db.c b/src/lwes_event_type_db.c
33
+ --- a/src/lwes_event_type_db.c
34
+ +++ b/src/lwes_event_type_db.c
35
+ @@ -36,7 +36,11 @@ lwes_event_type_db_create
36
+ db->events = lwes_hash_create ();
37
+ if (db->events != NULL)
38
+ {
39
+ - lwes_parse_esf (db, db->esf_filename);
40
+ + if (lwes_parse_esf (db, db->esf_filename) != 0)
41
+ + {
42
+ + free (db);
43
+ + db = NULL;
44
+ + }
45
+ }
46
+ else
47
+ {
48
+ diff -rup a/src/lwes_esf_parser_y.c b/src/lwes_esf_parser_y.c
49
+ --- a/src/lwes_esf_parser_y.c
50
+ +++ b/src/lwes_esf_parser_y.c
51
+ @@ -387,7 +387,7 @@ union yyalloc
52
+ /* YYNNTS -- Number of nonterminals. */
53
+ #define YYNNTS 8
54
+ /* YYNRULES -- Number of rules. */
55
+ -#define YYNRULES 23
56
+ +#define YYNRULES 24
57
+ /* YYNRULES -- Number of states. */
58
+ #define YYNSTATES 32
59
+
60
+ @@ -435,9 +435,9 @@ static const yytype_uint8 yytranslate[] =
61
+ YYRHS. */
62
+ static const yytype_uint8 yyprhs[] =
63
+ {
64
+ - 0, 0, 3, 5, 8, 13, 16, 19, 21, 23,
65
+ - 26, 30, 35, 40, 42, 44, 46, 48, 50, 52,
66
+ - 54, 56, 58, 60
67
+ + 0, 0, 3, 5, 8, 13, 16, 19, 21, 22,
68
+ + 24, 27, 31, 36, 41, 43, 45, 47, 49, 51,
69
+ + 53, 55, 57, 59, 61
70
+ };
71
+
72
+ /* YYRHS -- A `-1'-separated list of the rules' RHS. */
73
+ @@ -445,19 +445,19 @@ static const yytype_int8 yyrhs[] =
74
+ {
75
+ 18, 0, -1, 19, -1, 18, 19, -1, 20, 14,
76
+ 21, 15, -1, 1, 16, -1, 1, 15, -1, 12,
77
+ - -1, 22, -1, 21, 22, -1, 24, 23, 16, -1,
78
+ - 24, 23, 1, 16, -1, 24, 23, 1, 15, -1,
79
+ - 13, -1, 3, -1, 4, -1, 5, -1, 6, -1,
80
+ - 10, -1, 11, -1, 7, -1, 8, -1, 9, -1,
81
+ - 13, -1
82
+ + -1, -1, 22, -1, 21, 22, -1, 24, 23, 16,
83
+ + -1, 24, 23, 1, 16, -1, 24, 23, 1, 15,
84
+ + -1, 13, -1, 3, -1, 4, -1, 5, -1, 6,
85
+ + -1, 10, -1, 11, -1, 7, -1, 8, -1, 9,
86
+ + -1, 13, -1
87
+ };
88
+
89
+ /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
90
+ static const yytype_uint8 yyrline[] =
91
+ {
92
+ - 0, 35, 35, 36, 39, 47, 48, 51, 66, 67,
93
+ - 70, 71, 72, 75, 93, 104, 115, 125, 135, 145,
94
+ - 155, 165, 175, 185
95
+ + 0, 35, 35, 36, 39, 47, 48, 51, 66, 68,
96
+ + 69, 72, 73, 74, 77, 95, 106, 117, 127, 137,
97
+ + 147, 157, 167, 177, 187
98
+ };
99
+ #endif
100
+
101
+ @@ -488,16 +488,16 @@ static const yytype_uint16 yytoknum[] =
102
+ static const yytype_uint8 yyr1[] =
103
+ {
104
+ 0, 17, 18, 18, 19, 19, 19, 20, 21, 21,
105
+ - 22, 22, 22, 23, 24, 24, 24, 24, 24, 24,
106
+ - 24, 24, 24, 24
107
+ + 21, 22, 22, 22, 23, 24, 24, 24, 24, 24,
108
+ + 24, 24, 24, 24, 24
109
+ };
110
+
111
+ /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
112
+ static const yytype_uint8 yyr2[] =
113
+ {
114
+ - 0, 2, 1, 2, 4, 2, 2, 1, 1, 2,
115
+ - 3, 4, 4, 1, 1, 1, 1, 1, 1, 1,
116
+ - 1, 1, 1, 1
117
+ + 0, 2, 1, 2, 4, 2, 2, 1, 0, 1,
118
+ + 2, 3, 4, 4, 1, 1, 1, 1, 1, 1,
119
+ + 1, 1, 1, 1, 1
120
+ };
121
+
122
+ /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
123
+ @@ -506,9 +506,9 @@ static const yytype_uint8 yyr2[] =
124
+ static const yytype_uint8 yydefact[] =
125
+ {
126
+ 0, 0, 7, 0, 2, 0, 6, 5, 1, 3,
127
+ - 0, 14, 15, 16, 17, 20, 21, 22, 18, 19,
128
+ - 23, 0, 8, 0, 4, 9, 13, 0, 0, 10,
129
+ - 12, 11
130
+ + 8, 15, 16, 17, 18, 21, 22, 23, 19, 20,
131
+ + 24, 0, 9, 0, 4, 10, 14, 0, 0, 11,
132
+ + 13, 12
133
+ };
134
+
135
+ /* YYDEFGOTO[NTERM-NUM]. */
136
+ @@ -1414,18 +1414,18 @@ yyreduce:
137
+ }
138
+ break;
139
+
140
+ - case 11:
141
+ -#line 71 "lwes_esf_parser_y.y"
142
+ + case 12:
143
+ +#line 73 "lwes_esf_parser_y.y"
144
+ { lweserror("Did you forget a ';'?"); }
145
+ break;
146
+
147
+ - case 12:
148
+ -#line 72 "lwes_esf_parser_y.y"
149
+ + case 13:
150
+ +#line 74 "lwes_esf_parser_y.y"
151
+ { lweserror("Did you forget a semi-colon?"); }
152
+ break;
153
+
154
+ - case 13:
155
+ -#line 75 "lwes_esf_parser_y.y"
156
+ + case 14:
157
+ +#line 77 "lwes_esf_parser_y.y"
158
+ {
159
+ if (((struct lwes_parser_state *) param)->lastType != NULL)
160
+ {
161
+ @@ -1444,8 +1444,8 @@ yyreduce:
162
+ }
163
+ break;
164
+
165
+ - case 14:
166
+ -#line 93 "lwes_esf_parser_y.y"
167
+ + case 15:
168
+ +#line 95 "lwes_esf_parser_y.y"
169
+ {
170
+ /* allocate a string, and copy the type value into it */
171
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
172
+ @@ -1459,8 +1459,8 @@ yyreduce:
173
+ }
174
+ break;
175
+
176
+ - case 15:
177
+ -#line 104 "lwes_esf_parser_y.y"
178
+ + case 16:
179
+ +#line 106 "lwes_esf_parser_y.y"
180
+ {
181
+ /* allocate a string, and copy the type value into it */
182
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
183
+ @@ -1474,8 +1474,8 @@ yyreduce:
184
+ }
185
+ break;
186
+
187
+ - case 16:
188
+ -#line 115 "lwes_esf_parser_y.y"
189
+ + case 17:
190
+ +#line 117 "lwes_esf_parser_y.y"
191
+ {
192
+ /* allocate a string, and copy the type value into it */
193
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
194
+ @@ -1488,8 +1488,8 @@ yyreduce:
195
+ }
196
+ break;
197
+
198
+ - case 17:
199
+ -#line 125 "lwes_esf_parser_y.y"
200
+ + case 18:
201
+ +#line 127 "lwes_esf_parser_y.y"
202
+ {
203
+ /* allocate a string, and copy the type value into it */
204
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
205
+ @@ -1502,8 +1502,8 @@ yyreduce:
206
+ }
207
+ break;
208
+
209
+ - case 18:
210
+ -#line 135 "lwes_esf_parser_y.y"
211
+ + case 19:
212
+ +#line 137 "lwes_esf_parser_y.y"
213
+ {
214
+ /* allocate a string, and copy the type value into it */
215
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
216
+ @@ -1516,8 +1516,8 @@ yyreduce:
217
+ }
218
+ break;
219
+
220
+ - case 19:
221
+ -#line 145 "lwes_esf_parser_y.y"
222
+ + case 20:
223
+ +#line 147 "lwes_esf_parser_y.y"
224
+ {
225
+ /* allocate a string, and copy the type value into it */
226
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
227
+ @@ -1530,8 +1530,8 @@ yyreduce:
228
+ }
229
+ break;
230
+
231
+ - case 20:
232
+ -#line 155 "lwes_esf_parser_y.y"
233
+ + case 21:
234
+ +#line 157 "lwes_esf_parser_y.y"
235
+ {
236
+ /* allocate a string, and copy the type value into it */
237
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
238
+ @@ -1544,8 +1544,8 @@ yyreduce:
239
+ }
240
+ break;
241
+
242
+ - case 21:
243
+ -#line 165 "lwes_esf_parser_y.y"
244
+ + case 22:
245
+ +#line 167 "lwes_esf_parser_y.y"
246
+ {
247
+ /* allocate a string, and copy the type value into it */
248
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
249
+ @@ -1558,8 +1558,8 @@ yyreduce:
250
+ }
251
+ break;
252
+
253
+ - case 22:
254
+ -#line 175 "lwes_esf_parser_y.y"
255
+ + case 23:
256
+ +#line 177 "lwes_esf_parser_y.y"
257
+ {
258
+ /* allocate a string, and copy the type value into it */
259
+ ((struct lwes_parser_state *) param)->lastType = strdup(lweslval);
260
+ @@ -1572,8 +1572,8 @@ yyreduce:
261
+ }
262
+ break;
263
+
264
+ - case 23:
265
+ -#line 185 "lwes_esf_parser_y.y"
266
+ + case 24:
267
+ +#line 187 "lwes_esf_parser_y.y"
268
+ { char buffer[256];
269
+ sprintf(buffer,"unknown type '%s'",lweslval);
270
+ lweserror(buffer);
271
+ @@ -1797,7 +1797,7 @@ yyreturn:
272
+ }
273
+
274
+
275
+ -#line 192 "lwes_esf_parser_y.y"
276
+ +#line 194 "lwes_esf_parser_y.y"
277
+
278
+
279
+ extern FILE *lwesin;
280
+ @@ -1830,6 +1830,7 @@ lwes_parse_esf
281
+ else
282
+ {
283
+ fprintf (stderr,"ERROR: No such file : \"%s\"\n",filename);
284
+ + state.errors++;
285
+ }
286
+
287
+ if (state.errors)
data/ext/lwes/type_db.c CHANGED
@@ -12,7 +12,7 @@ static void tdb_free(void *ptr)
12
12
 
13
13
  if (tdb->db)
14
14
  lwes_event_type_db_destroy(tdb->db);
15
- tdb->db = NULL;
15
+ xfree(ptr);
16
16
  }
17
17
 
18
18
  static VALUE tdb_alloc(VALUE klass)
@@ -25,6 +25,7 @@ static VALUE tdb_alloc(VALUE klass)
25
25
  static VALUE tdb_init(VALUE self, VALUE path)
26
26
  {
27
27
  struct _tdb *tdb;
28
+ int gc_retry = 1;
28
29
 
29
30
  if (TYPE(path) != T_STRING)
30
31
  rb_raise(rb_eArgError, "path must be a string");
@@ -32,12 +33,17 @@ static VALUE tdb_init(VALUE self, VALUE path)
32
33
  Data_Get_Struct(self, struct _tdb, tdb);
33
34
  if (tdb->db)
34
35
  rb_raise(rb_eRuntimeError, "ESF already initialized");
35
-
36
+ retry:
36
37
  tdb->db = lwes_event_type_db_create(RSTRING_PTR(path));
37
- if (!tdb->db)
38
+ if (!tdb->db) {
39
+ if (--gc_retry == 0) {
40
+ rb_gc();
41
+ goto retry;
42
+ }
38
43
  rb_raise(rb_eRuntimeError,
39
44
  "failed to create type DB for LWES file %s",
40
45
  RSTRING_PTR(path));
46
+ }
41
47
 
42
48
  return Qnil;
43
49
  }
data/lib/lwes/type_db.rb CHANGED
@@ -21,5 +21,15 @@ module LWES
21
21
  end
22
22
  end
23
23
 
24
+ # :stopdoc:
25
+ # avoid GC mis-free-ing nuked objects
26
+ def dup
27
+ self
28
+ end
29
+
30
+ def clone
31
+ self
32
+ end
33
+
24
34
  end
25
35
  end
data/lib/lwes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module LWES
2
- # version of our library, currently 0.2.3
3
- VERSION = "0.2.3"
2
+ # version of our library, currently 0.3.0
3
+ VERSION = "0.3.0"
4
4
 
5
5
  autoload :TypeDB, "lwes/type_db"
6
6
  autoload :Struct, "lwes/struct"
data/lwes.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{lwes}
3
- s.version = "0.2.3"
3
+ s.version = "0.3.0"
4
4
  s.date = Time.now
5
5
  s.authors = ["Erik S. Chang", "Frank Maritato"]
6
6
  s.email = %q{lwes-devel@lists.sourceforge.net}
@@ -23,6 +23,7 @@ examples/demo.rb
23
23
  examples/my_events.esf
24
24
  ext/lwes/emitter.c
25
25
  ext/lwes/extconf.rb
26
+ ext/lwes/lwes-0.22.3.diff
26
27
  ext/lwes/lwes.c
27
28
  ext/lwes/lwes_ruby.h
28
29
  ext/lwes/numeric.c
@@ -42,5 +43,6 @@ test/unit/test_emitter.rb
42
43
  test/unit/test_struct.rb
43
44
  test/unit/test_type_db.rb
44
45
  )
46
+ s.rubyforge_project = 'lwes'
45
47
  s.test_files = s.files.grep(%r{\Atest/unit/test_})
46
48
  end
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../test_helper"
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/../test_helper"
2
2
 
3
3
  class InvalidStruct1 < Struct.new(:invalid)
4
4
  TYPE_DB = []
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../test_helper"
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/../test_helper"
2
2
  require 'ipaddr'
3
3
 
4
4
  class TestEmitter < Test::Unit::TestCase
@@ -20,6 +20,20 @@ class TestEmitter < Test::Unit::TestCase
20
20
  assert_instance_of LWES::Emitter, LWES::Emitter.new(@options)
21
21
  end
22
22
 
23
+ def test_dup
24
+ orig = LWES::Emitter.new(@options)
25
+ duped = orig.dup
26
+ assert_instance_of LWES::Emitter, duped
27
+ assert duped.object_id != orig.object_id
28
+ end
29
+
30
+ def test_clone
31
+ orig = LWES::Emitter.new(@options)
32
+ cloned = orig.clone
33
+ assert_instance_of LWES::Emitter, cloned
34
+ assert cloned.object_id != orig.object_id
35
+ end
36
+
23
37
  def test_initialize_with_heartbeat
24
38
  heartbeat = @options.merge(:heartbeat => 30)
25
39
  assert_instance_of LWES::Emitter, LWES::Emitter.new(heartbeat)
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../test_helper"
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/../test_helper"
2
2
 
3
3
  module Dummy
4
4
  end
@@ -1,4 +1,4 @@
1
- require "#{File.dirname(__FILE__)}/../test_helper"
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/../test_helper"
2
2
  require 'tempfile'
3
3
 
4
4
  module Abcde
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lwes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik S. Chang
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-02 00:00:00 +00:00
13
+ date: 2010-04-15 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -36,6 +36,7 @@ files:
36
36
  - examples/my_events.esf
37
37
  - ext/lwes/emitter.c
38
38
  - ext/lwes/extconf.rb
39
+ - ext/lwes/lwes-0.22.3.diff
39
40
  - ext/lwes/lwes.c
40
41
  - ext/lwes/lwes_ruby.h
41
42
  - ext/lwes/numeric.c
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  version:
78
79
  requirements: []
79
80
 
80
- rubyforge_project:
81
+ rubyforge_project: lwes
81
82
  rubygems_version: 1.3.5
82
83
  signing_key:
83
84
  specification_version: 3