clogger 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/GIT-VERSION-GEN CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v0.3.2.GIT
4
+ DEF_VER=v0.4.0.GIT
5
5
 
6
6
  LF='
7
7
  '
data/GNUmakefile CHANGED
@@ -46,7 +46,7 @@ NEWS: GIT-VERSION-FILE .manifest
46
46
  $(RAKE) -s news_rdoc > $@+
47
47
  mv $@+ $@
48
48
 
49
- SINCE = 0.0.7
49
+ SINCE = 0.3.2
50
50
  ChangeLog: log_range = $(shell test -n "$(SINCE)" && echo v$(SINCE)..)
51
51
  ChangeLog: GIT-VERSION-FILE
52
52
  @echo "ChangeLog from $(GIT_URL) ($(SINCE)..$(GIT_VERSION))" > $@+
@@ -105,7 +105,6 @@ static VALUE g_rack_errors;
105
105
  static VALUE g_rack_input;
106
106
  static VALUE g_rack_multithread;
107
107
  static VALUE g_dash;
108
- static VALUE g_empty;
109
108
  static VALUE g_space;
110
109
  static VALUE g_question_mark;
111
110
  static VALUE g_rack_request_cookie_hash;
@@ -120,7 +119,7 @@ static void init_buffers(struct clogger *c)
120
119
  static inline int need_escape(unsigned c)
121
120
  {
122
121
  assert(c <= 0xff);
123
- return !!(c == '\'' || c == '"' || (c >= 0 && c <= 0x1f));
122
+ return !!(c == '\'' || c == '"' || c <= 0x1f);
124
123
  }
125
124
 
126
125
  /* we are encoding-agnostic, clients can send us all sorts of junk */
@@ -144,7 +143,7 @@ static VALUE byte_xs_str(VALUE from)
144
143
  if (new_len == len)
145
144
  return from;
146
145
 
147
- rv = rb_str_new(0, new_len);
146
+ rv = rb_str_new(NULL, new_len);
148
147
  new_ptr = (unsigned char *)RSTRING_PTR(rv);
149
148
  ptr = (unsigned char *)RSTRING_PTR(from);
150
149
  for (; --len >= 0; ptr++) {
@@ -214,15 +213,16 @@ static VALUE obj_enable_sync(VALUE obj)
214
213
  static void write_full(int fd, const void *buf, size_t count)
215
214
  {
216
215
  ssize_t r;
216
+ unsigned long ubuf = (unsigned long)buf;
217
217
 
218
218
  while (count > 0) {
219
- r = write(fd, buf, count);
219
+ r = write(fd, (void *)ubuf, count);
220
220
 
221
- if (r == count) { /* overwhelmingly likely */
221
+ if ((size_t)r == count) { /* overwhelmingly likely */
222
222
  return;
223
223
  } else if (r > 0) {
224
224
  count -= r;
225
- buf += r;
225
+ ubuf += r;
226
226
  } else {
227
227
  if (errno == EINTR || errno == EAGAIN)
228
228
  continue; /* poor souls on NFS and like: */
@@ -237,15 +237,15 @@ static void write_full(int fd, const void *buf, size_t count)
237
237
  * allow us to use write_full() iff we detect a blocking file
238
238
  * descriptor that wouldn't play nicely with Ruby threading/fibers
239
239
  */
240
- static int raw_fd(VALUE fileno)
240
+ static int raw_fd(VALUE my_fileno)
241
241
  {
242
242
  #if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
243
243
  int fd;
244
244
  int flags;
245
245
 
246
- if (NIL_P(fileno))
246
+ if (NIL_P(my_fileno))
247
247
  return -1;
248
- fd = NUM2INT(fileno);
248
+ fd = NUM2INT(my_fileno);
249
249
 
250
250
  flags = fcntl(fd, F_GETFL);
251
251
  if (flags < 0)
@@ -284,7 +284,7 @@ static void append_status(struct clogger *c)
284
284
  }
285
285
  }
286
286
 
287
- nr = NUM2INT(status);
287
+ nr = FIX2INT(status);
288
288
  if (nr >= 100 && nr <= 999) {
289
289
  nr = snprintf(buf, sizeof(buf), "%03d", nr);
290
290
  assert(nr == 3);
@@ -318,7 +318,7 @@ static void append_body_bytes_sent(struct clogger *c)
318
318
  const char *fmt = sizeof(off_t) == sizeof(long) ? "%ld" : "%lld";
319
319
  int nr = snprintf(buf, sizeof(buf), fmt, c->body_bytes_sent);
320
320
 
321
- assert(nr > 0 && nr < sizeof(buf));
321
+ assert(nr > 0 && nr < (int)sizeof(buf));
322
322
  rb_str_buf_cat(c->log_buf, buf, nr);
323
323
  }
324
324
 
@@ -327,11 +327,11 @@ static void append_tv(struct clogger *c, const VALUE *op, struct timeval *tv)
327
327
  char buf[sizeof(".000000") + ((sizeof(tv->tv_sec) * 8) / 3)];
328
328
  int nr;
329
329
  char *fmt = RSTRING_PTR(op[1]);
330
- int div = NUM2INT(op[2]);
330
+ int ndiv = NUM2INT(op[2]);
331
331
 
332
332
  nr = snprintf(buf, sizeof(buf), fmt,
333
- (int)tv->tv_sec, (int)(tv->tv_usec / div));
334
- assert(nr > 0 && nr < sizeof(buf));
333
+ (int)tv->tv_sec, (int)(tv->tv_usec / ndiv));
334
+ assert(nr > 0 && nr < (int)sizeof(buf));
335
335
  rb_str_buf_cat(c->log_buf, buf, nr);
336
336
  }
337
337
 
@@ -430,7 +430,7 @@ static void append_pid(struct clogger *c)
430
430
  char buf[(sizeof(pid_t) * 8) / 3 + 1];
431
431
  int nr = snprintf(buf, sizeof(buf), "%d", (int)getpid());
432
432
 
433
- assert(nr > 0 && nr < sizeof(buf));
433
+ assert(nr > 0 && nr < (int)sizeof(buf));
434
434
  rb_str_buf_cat(c->log_buf, buf, nr);
435
435
  }
436
436
 
@@ -472,7 +472,7 @@ static void append_response(struct clogger *c, VALUE key)
472
472
  {
473
473
  VALUE v;
474
474
 
475
- assert(rb_obj_class(c->headers) == cHeaderHash);
475
+ assert(rb_obj_is_kind_of(c->headers, cHeaderHash) && "not HeaderHash");
476
476
 
477
477
  v = rb_funcall(c->headers, sq_brace_id, 1, key);
478
478
  v = NIL_P(v) ? g_dash : byte_xs(v);
@@ -522,7 +522,7 @@ static VALUE cwrite(struct clogger *c)
522
522
 
523
523
  for (; --i >= 0; ary++) {
524
524
  const VALUE *op = RARRAY_PTR(*ary);
525
- enum clogger_opcode opcode = NUM2INT(op[0]);
525
+ enum clogger_opcode opcode = FIX2INT(op[0]);
526
526
 
527
527
  switch (opcode) {
528
528
  case CL_OP_LITERAL:
@@ -535,7 +535,7 @@ static VALUE cwrite(struct clogger *c)
535
535
  append_response(c, op[1]);
536
536
  break;
537
537
  case CL_OP_SPECIAL:
538
- special_var(c, NUM2INT(op[1]));
538
+ special_var(c, FIX2INT(op[1]));
539
539
  break;
540
540
  case CL_OP_EVAL:
541
541
  append_eval(c, op[1]);
@@ -592,8 +592,9 @@ static VALUE clogger_init(int argc, VALUE *argv, VALUE self)
592
592
 
593
593
  c->logger = rb_hash_aref(o, ID2SYM(rb_intern("logger")));
594
594
  if (!NIL_P(c->logger)) {
595
- rb_rescue(obj_enable_sync, c->logger, 0, 0);
596
- c->fd = raw_fd(rb_rescue(obj_fileno, c->logger, 0, 0));
595
+ rb_rescue(obj_enable_sync, c->logger, NULL, 0);
596
+ tmp = rb_rescue(obj_fileno, c->logger, NULL, 0);
597
+ c->fd = raw_fd(tmp);
597
598
  }
598
599
 
599
600
  tmp = rb_hash_aref(o, ID2SYM(rb_intern("format")));
@@ -703,17 +704,20 @@ static VALUE ccall(struct clogger *c, VALUE env)
703
704
  c->body = tmp[2];
704
705
 
705
706
  rv = rb_ary_new4(3, tmp);
706
- if (c->need_resp && cHeaderHash != rb_obj_class(c->headers)) {
707
+ if (c->need_resp &&
708
+ ! rb_obj_is_kind_of(tmp[1], cHeaderHash)) {
707
709
  c->headers = rb_funcall(cHeaderHash, new_id, 1, tmp[1]);
708
710
  rb_ary_store(rv, 1, c->headers);
709
711
  }
710
712
  } else {
711
- c->status = INT2NUM(500);
713
+ volatile VALUE tmp = rb_inspect(rv);
714
+
715
+ c->status = INT2FIX(500);
712
716
  c->headers = c->body = rb_ary_new();
713
717
  cwrite(c);
714
718
  rb_raise(rb_eTypeError,
715
719
  "app response not a 3 element Array: %s",
716
- RSTRING_PTR(rb_inspect(rv)));
720
+ RSTRING_PTR(tmp));
717
721
  }
718
722
 
719
723
  return rv;
@@ -775,21 +779,10 @@ static VALUE clogger_init_copy(VALUE clone, VALUE orig)
775
779
 
776
780
  #define CONST_GLOBAL_STR(val) CONST_GLOBAL_STR2(val, #val)
777
781
 
778
- static void init_rack_utils_header_hash(void)
779
- {
780
- VALUE mRack, mUtils;
781
- #if 0
782
- extra double quotes below are to disable rdoc (and so is avoiding comments)
783
- let me know if there is a better way...
784
- #endif
785
- rb_require("rack");
786
- mRack = rb_define_module("Rack""");
787
- mUtils = rb_define_module_under(mRack, "Utils""");
788
- cHeaderHash = rb_define_class_under(mUtils, "HeaderHash""", rb_cHash);
789
- }
790
-
791
782
  void Init_clogger_ext(void)
792
783
  {
784
+ VALUE tmp;
785
+
793
786
  ltlt_id = rb_intern("<<");
794
787
  call_id = rb_intern("call");
795
788
  each_id = rb_intern("each");
@@ -821,9 +814,11 @@ void Init_clogger_ext(void)
821
814
  CONST_GLOBAL_STR2(rack_input, "rack.input");
822
815
  CONST_GLOBAL_STR2(rack_multithread, "rack.multithread");
823
816
  CONST_GLOBAL_STR2(dash, "-");
824
- CONST_GLOBAL_STR2(empty, "");
825
817
  CONST_GLOBAL_STR2(space, " ");
826
818
  CONST_GLOBAL_STR2(question_mark, "?");
827
819
  CONST_GLOBAL_STR2(rack_request_cookie_hash, "rack.request.cookie_hash");
828
- init_rack_utils_header_hash();
820
+
821
+ tmp = rb_const_get(rb_cObject, rb_intern("Rack"));
822
+ tmp = rb_const_get(tmp, rb_intern("Utils"));
823
+ cHeaderHash = rb_const_get(tmp, rb_intern("HeaderHash"));
829
824
  }
data/lib/clogger.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # -*- encoding: binary -*-
2
+ autoload :Rack, 'rack'
3
+
2
4
  class Clogger
3
- VERSION = '0.3.2'
5
+ VERSION = '0.4.0'
4
6
 
5
7
  OP_LITERAL = 0
6
8
  OP_REQUEST = 1
data/lib/clogger/pure.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  # -*- encoding: binary -*-
2
2
  # :stopdoc:
3
3
 
4
- require 'rack'
5
-
6
4
  # Not at all optimized for performance, this was written based on
7
5
  # the original C extension code so it's not very Ruby-ish...
8
6
  class Clogger
9
7
 
10
8
  def initialize(app, opts = {})
9
+ # trigger autoload to avoid thread-safety issues later on
10
+ Rack::Utils::HeaderHash.new({})
11
+
11
12
  @app = app
12
13
  @logger = opts[:logger]
13
14
  (@logger.sync = true) rescue nil
data/test/test_clogger.rb CHANGED
@@ -587,6 +587,24 @@ class TestClogger < Test::Unit::TestCase
587
587
  assert ! cl.reentrant?
588
588
  end
589
589
 
590
+ def test_invalid_status
591
+ s = []
592
+ body = []
593
+ app = lambda { |env| [ env["force.status"], [ %w(a b) ], body ] }
594
+ o = { :logger => s, :format => "$status" }
595
+ cl = Clogger.new(app, o)
596
+ status, headers, body = cl.call(@req.merge("force.status" => -1))
597
+ assert_equal -1, status
598
+ assert_equal "-\n", s.last
599
+ status, headers, body = cl.call(@req.merge("force.status" => 1000))
600
+ assert_equal 1000, status
601
+ assert_equal "-\n", s.last
602
+ u64_max = 0xffffffffffffffff
603
+ status, headers, body = cl.call(@req.merge("force.status" => u64_max))
604
+ assert_equal u64_max, status
605
+ assert_equal "-\n", s.last
606
+ end
607
+
590
608
  # so we don't care about the portability of this test
591
609
  # if it doesn't leak on Linux, it won't leak anywhere else
592
610
  # unless your C compiler or platform is otherwise broken
@@ -603,6 +621,6 @@ class TestClogger < Test::Unit::TestCase
603
621
  diff = after - before
604
622
  assert(diff < 10000, "memory grew more than 10M: #{diff}")
605
623
  end
606
- end if RUBY_PLATFORM =~ /linux/ && test(?r, LINUX_PROC_PID_STATUS)
624
+ end if RUBY_PLATFORM =~ /linux/ && File.readable?(LINUX_PROC_PID_STATUS)
607
625
 
608
626
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloggers
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-13 00:00:00 +00:00
12
+ date: 2010-04-21 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency