* [ANN] kcar 0.7.0 - bytestream to Rack response converter
@ 2020-02-21 2:32 5% Eric Wong
0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2020-02-21 2:32 UTC (permalink / raw)
To: kcar-public
kcar features an HTTP parser that will convert a bytestream into a
3-element array suitable for use as a Rack response. It is IO interface
agnostic, so it may be used with HTTP streams over Unix domain sockets,
regular files, FIFOs, StringIOs as well as traditional TCP sockets.
* homepage: https://yhbt.net/kcar/
* public inbox: kcar-public@yhbt.net
* git clone https://yhbt.net/kcar.git
* mailing list archives: https://yhbt.net/kcar-public/
Changes:
46 changes since 0.6.0 (2015-08-04):
README: fix reference to HTTP git viewer
doc: move site to HTTPS
pkg.mk: avoid network for "gem install"
gemspec: use SPDX compatible terms for the license(s)
archive/slrnpull.conf: add a note explaining the purpose
drop rb_str_set_len compatibility replacement
remove rb_str_modify workaround
TypedData C-API conversion
test_parser: add lone CR test
reduce parser size to 88 bytes on 64-bit
extconf: remove unneeded -fPIC CFLAGS
rely on String#-@ (str_uminus) to dedupe headers
update comment about freezing values
http: reject non-LWS CTL chars (0..31 + 127) in field values
doc: remove references to a server
update documentation for contributions, remove private address
doc: minor updates to describe classes, better
response: remove unnecessary constant alias
response: more documentation cleanups
favor require_relative to speed up loading
response: remove Ruby 1.8-compatibility check
fix signedness check on 32-bit systems
shorten and improve readability of assertion
HACKING: remove copy+pasted line about N
olddoc: include NNTP archive link
gemspec: remove olddoc dev dependency
README: add info about mailing list subscription
nodoc Kcar::VERSION
pkg.mk: support VALGRIND variable for unit tests
introduce new str_new_dd_freeze internal function
begin implementing request parsing
favor bitfields instead flags + macros
implement request parsing with tests
pkg.mk: enable warnings by default for tests
filter_body: rename variables to be like memcpy(3)
flesh out filter_body for request parsing
do not assume SERVER_PORT
do not set "HTTP/0.9" for pre-1.0 requests
always set non-negative Content-Length for requests
avoid String#-@ call on request parsing under Ruby 2.6
request: set env["FRAGMENT"] for WebDAV litmus test
extconf: fix rb_hash_aset deduplication test
use rb_gc_register_mark_object
website: use dark216 to save electricity
doc: update URLs to point to YHBT.net
doc: update git:// URLs to HTTPS
^ permalink raw reply [relevance 5%]
* [PATCH 01/11] introduce new str_new_dd_freeze internal function
@ 2018-12-01 13:31 6% ` Eric Wong
0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2018-12-01 13:31 UTC (permalink / raw)
To: kcar-public
This seems like it will be a common pattern to create
and immediately dedupe a string. In the future, we may
be able to save some memory by eliding temporary object
creation or releasing heap memory via rb_str_resize(..., 0)
---
ext/kcar/extconf.rb | 15 ++++++++++-----
ext/kcar/kcar.rl | 9 +++++++--
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/ext/kcar/extconf.rb b/ext/kcar/extconf.rb
index 89ac586..b65846a 100644
--- a/ext/kcar/extconf.rb
+++ b/ext/kcar/extconf.rb
@@ -6,15 +6,20 @@ dir_config("kcar")
have_macro("SIZEOF_OFF_T", "ruby.h") or check_sizeof("off_t", "sys/types.h")
have_macro("SIZEOF_LONG", "ruby.h") or check_sizeof("long", "sys/types.h")
-uminus_dedupe = false
+message('checking if String#-@ (str_uminus) dedupes... ')
begin
- # oddly, opt_str_freeze is not always effective:
- # https://bugs.ruby-lang.org/issues/13282
a = -(%w(t e s t).join)
b = -(%w(t e s t).join)
- uminus_dedupe = a.object_id == b.object_id
+ if a.equal?(b)
+ $CPPFLAGS += " -DSTR_UMINUS_DEDUPE=1 "
+ message("yes\n")
+ else
+ $CPPFLAGS += " -DSTR_UMINUS_DEDUPE=0 "
+ message("no, needs Ruby 2.5+\n")
+ end
rescue NoMethodError
+ $CPPFLAGS += " -DSTR_UMINUS_DEDUPE=0 "
+ message("no, String#-@ not available\n")
end
-$CFLAGS += " -DSTR_UMINUS_DEDUPE=#{uminus_dedupe ? 1 : 0}"
create_makefile("kcar_ext")
diff --git a/ext/kcar/kcar.rl b/ext/kcar/kcar.rl
index cbcfa97..79f65db 100644
--- a/ext/kcar/kcar.rl
+++ b/ext/kcar/kcar.rl
@@ -106,6 +106,11 @@ static VALUE str_dd_freeze(VALUE str)
return str;
}
+static VALUE str_new_dd_freeze(const char *ptr, long len)
+{
+ return str_dd_freeze(rb_str_new(ptr, len));
+}
+
static VALUE stripped_str_new(const char *str, long len)
{
long end;
@@ -161,7 +166,7 @@ status_phrase(struct http_parser *hp, VALUE hdr, const char *ptr, size_t len)
{
long nr;
- hp->status = str_dd_freeze(rb_str_new(ptr, len));
+ hp->status = str_new_dd_freeze(ptr, len);
/* RSTRING_PTR is null terminated, ptr is not */
nr = strtol(RSTRING_PTR(hp->status), NULL, 10);
@@ -238,7 +243,7 @@ static void write_value(VALUE hdr, struct http_parser *hp,
vlen = LEN(mark, p);
VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE);
VALIDATE_MAX_LENGTH(flen, FIELD_NAME);
- f = str_dd_freeze(rb_str_new(fptr, (long)flen));
+ f = str_new_dd_freeze(fptr, (long)flen);
v = stripped_str_new(vptr, (long)vlen);
/* needs more tests for error-checking here */
^ permalink raw reply related [relevance 6%]
* [PATCH 1/7] introduce new str_new_dd_freeze internal function
2017-04-19 22:30 6% [PATCH 0/7] request parsing bits Eric Wong
@ 2017-04-19 22:30 7% ` Eric Wong
0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2017-04-19 22:30 UTC (permalink / raw)
To: kcar-public
This seems like it will be a common pattern to create
and immediately dedupe a string. In the future, we may
be able to save some memory by eliding temporary object
creation or releasing heap memory via rb_str_resize(..., 0)
---
ext/kcar/kcar.rl | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/ext/kcar/kcar.rl b/ext/kcar/kcar.rl
index cbcfa97..79f65db 100644
--- a/ext/kcar/kcar.rl
+++ b/ext/kcar/kcar.rl
@@ -106,6 +106,11 @@ static VALUE str_dd_freeze(VALUE str)
return str;
}
+static VALUE str_new_dd_freeze(const char *ptr, long len)
+{
+ return str_dd_freeze(rb_str_new(ptr, len));
+}
+
static VALUE stripped_str_new(const char *str, long len)
{
long end;
@@ -161,7 +166,7 @@ status_phrase(struct http_parser *hp, VALUE hdr, const char *ptr, size_t len)
{
long nr;
- hp->status = str_dd_freeze(rb_str_new(ptr, len));
+ hp->status = str_new_dd_freeze(ptr, len);
/* RSTRING_PTR is null terminated, ptr is not */
nr = strtol(RSTRING_PTR(hp->status), NULL, 10);
@@ -238,7 +243,7 @@ static void write_value(VALUE hdr, struct http_parser *hp,
vlen = LEN(mark, p);
VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE);
VALIDATE_MAX_LENGTH(flen, FIELD_NAME);
- f = str_dd_freeze(rb_str_new(fptr, (long)flen));
+ f = str_new_dd_freeze(fptr, (long)flen);
v = stripped_str_new(vptr, (long)vlen);
/* needs more tests for error-checking here */
--
EW
^ permalink raw reply related [relevance 7%]
* [PATCH 0/7] request parsing bits
@ 2017-04-19 22:30 6% Eric Wong
2017-04-19 22:30 7% ` [PATCH 1/7] introduce new str_new_dd_freeze internal function Eric Wong
0 siblings, 1 reply; 4+ results
From: Eric Wong @ 2017-04-19 22:30 UTC (permalink / raw)
To: kcar-public
There can be more optimizations done(*), but I might push
out a prerelease in a bit and start running it on on real
code for a bit.
7 patches:
introduce new str_new_dd_freeze internal function
begin implementing request parsing
favor bitfields instead flags + macros
implement request parsing with tests
pkg.mk: enable warnings by default for tests
filter_body: rename variables to be like memcpy(3)
flesh out filter_body for request parsing
ext/kcar/kcar.rl | 583 +++++++++++++++++---
ext/kcar/kcar_http_common.rl | 36 +-
pkg.mk | 2 +-
test/test_parser.rb | 1 +
test/test_request_parser.rb | 1219 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 1748 insertions(+), 93 deletions(-)
(*) and they'll be ported to that other-parser-that-shall-not-be-named
^ permalink raw reply [relevance 6%]
Results 1-4 of 4 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2017-04-19 22:30 6% [PATCH 0/7] request parsing bits Eric Wong
2017-04-19 22:30 7% ` [PATCH 1/7] introduce new str_new_dd_freeze internal function Eric Wong
2018-12-01 13:31 [PATCH v2] request parsing bits Eric Wong
2018-12-01 13:31 6% ` [PATCH 01/11] introduce new str_new_dd_freeze internal function Eric Wong
2020-02-21 2:32 5% [ANN] kcar 0.7.0 - bytestream to Rack response converter Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/kcar.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).