From: Eric Wong <e@80x24.org>
To: <mwrap-public@80x24.org>
Subject: [PATCH] make Ruby headers less intrusive
Date: Sun, 8 Jan 2023 23:43:21 +0000 [thread overview]
Message-ID: <20230108234321.16994-1-e@80x24.org> (raw)
By including them at the bottom. This will be done for Perl
headers in the future, too, since they break assert().
---
ext/mwrap/httpd.h | 8 ----
ext/mwrap/mwrap_core.h | 104 +++++++++++++++++++++--------------------
2 files changed, 53 insertions(+), 59 deletions(-)
diff --git a/ext/mwrap/httpd.h b/ext/mwrap/httpd.h
index da7ff6d..03aef9f 100644
--- a/ext/mwrap/httpd.h
+++ b/ext/mwrap/httpd.h
@@ -43,14 +43,6 @@
#define TYPE_CSV "text/csv"
#define TYPE_PLAIN "text/plain"
-/*
- * C ruby defines snprintf to ruby_snprintf, we can't have that in
- * non-ruby processes spawned by C ruby
- */
-#if MWRAP_RUBY && defined(snprintf)
-# undef snprintf
-#endif
-
enum mw_qev {
MW_QEV_IGNORE = 0,
MW_QEV_RD = POLLIN,
diff --git a/ext/mwrap/mwrap_core.h b/ext/mwrap/mwrap_core.h
index 721e5d3..48669d5 100644
--- a/ext/mwrap/mwrap_core.h
+++ b/ext/mwrap/mwrap_core.h
@@ -46,13 +46,6 @@
# include "ppport.h"
#endif
-#if MWRAP_RUBY
-# undef _GNU_SOURCE /* ruby.h redefines it */
-# include <ruby.h> /* defines HAVE_RUBY_RACTOR_H on 3.0+ */
-# include <ruby/thread.h>
-# include <ruby/io.h>
-#endif
-
/*
* XXH3 (truncated to 32-bits) seems to provide a ~2% speedup.
* XXH32 doesn't show improvements over jhash despite rculfhash
@@ -90,44 +83,11 @@ static size_t *root_locating; /* determines if PL_curcop is our thread */
#endif /* MWRAP_PERL */
#if MWRAP_RUBY
-const char *rb_source_location_cstr(int *line); /* requires 2.6.0dev or later */
-
-# ifdef HAVE_RUBY_RACTOR_H /* Ruby 3.0+ */
-extern MWRAP_TSD void * __attribute__((weak)) ruby_current_ec;
-# else /* Ruby 2.6-2.7 */
-extern void * __attribute__((weak)) ruby_current_execution_context_ptr;
-# define ruby_current_ec ruby_current_execution_context_ptr
-# endif /* HAVE_RUBY_RACTOR_H */
-
-extern void * __attribute__((weak)) ruby_current_vm_ptr; /* for rb_gc_count */
-extern size_t __attribute__((weak)) rb_gc_count(void);
-int __attribute__((weak)) ruby_thread_has_gvl_p(void);
-
-/*
- * rb_source_location_cstr relies on GET_EC(), and it's possible
- * to have a native thread but no EC during the early and late
- * (teardown) phases of the Ruby process
- */
-static int has_ec_p(void)
-{
- return ruby_thread_has_gvl_p && ruby_thread_has_gvl_p() &&
- ruby_current_vm_ptr && ruby_current_ec;
-}
-
-static void set_generation(size_t *gen, size_t size)
-{
- if (rb_gc_count) {
- uatomic_add_return(&total_bytes_inc, size);
- if (has_ec_p())
- *gen = rb_gc_count();
- } else {
- *gen = uatomic_add_return(&total_bytes_inc, size);
- }
-}
-# define SET_GENERATION(gen, size) set_generation(gen, size)
+static void mw_ruby_set_generation(size_t *, size_t);
+# define SET_GENERATION(gen, size) mw_ruby_set_generation(gen, size)
#endif /* MWRAP_RUBY */
-#ifndef SET_GENERATION
+#ifndef SET_GENERATION /* C-only builds w/o Perl|Ruby */
# define SET_GENERATION(gen, size) \
*gen = uatomic_add_return(&total_bytes_inc, size)
#endif /* !SET_GENERATION */
@@ -438,14 +398,7 @@ static const char *mw_perl_src_file_cstr(unsigned *lineno)
#endif /* MWRAP_PERL */
#if MWRAP_RUBY
-static const char *mw_ruby_src_file_cstr(unsigned *lineno)
-{
- if (!has_ec_p()) return NULL;
- int line;
- const char *fn = rb_source_location_cstr(&line);
- *lineno = line < 0 ? UINT_MAX : (unsigned)line;
- return fn;
-}
+static const char *mw_ruby_src_file_cstr(unsigned *lineno);
# define SRC_FILE_CSTR(lineno) mw_ruby_src_file_cstr(lineno)
#endif /* MWRAP_RUBY */
@@ -1088,3 +1041,52 @@ __attribute__((constructor)) static void mwrap_ctor(void)
}
--locating;
}
+
+#if MWRAP_RUBY
+# undef _GNU_SOURCE /* ruby.h redefines it */
+# include <ruby.h> /* defines HAVE_RUBY_RACTOR_H on 3.0+ */
+# include <ruby/thread.h>
+# include <ruby/io.h>
+# ifdef HAVE_RUBY_RACTOR_H /* Ruby 3.0+ */
+extern MWRAP_TSD void * __attribute__((weak)) ruby_current_ec;
+# else /* Ruby 2.6-2.7 */
+extern void * __attribute__((weak)) ruby_current_execution_context_ptr;
+# define ruby_current_ec ruby_current_execution_context_ptr
+# endif /* HAVE_RUBY_RACTOR_H */
+
+extern void * __attribute__((weak)) ruby_current_vm_ptr; /* for rb_gc_count */
+extern size_t __attribute__((weak)) rb_gc_count(void);
+int __attribute__((weak)) ruby_thread_has_gvl_p(void);
+
+const char *rb_source_location_cstr(int *line); /* requires 2.6.0dev or later */
+/*
+ * rb_source_location_cstr relies on GET_EC(), and it's possible
+ * to have a native thread but no EC during the early and late
+ * (teardown) phases of the Ruby process
+ */
+static int has_ec_p(void)
+{
+ return ruby_thread_has_gvl_p && ruby_thread_has_gvl_p() &&
+ ruby_current_vm_ptr && ruby_current_ec;
+}
+
+static void mw_ruby_set_generation(size_t *gen, size_t size)
+{
+ if (rb_gc_count) {
+ uatomic_add_return(&total_bytes_inc, size);
+ if (has_ec_p())
+ *gen = rb_gc_count();
+ } else {
+ *gen = uatomic_add_return(&total_bytes_inc, size);
+ }
+}
+
+static const char *mw_ruby_src_file_cstr(unsigned *lineno)
+{
+ if (!has_ec_p()) return NULL;
+ int line;
+ const char *fn = rb_source_location_cstr(&line);
+ *lineno = line < 0 ? UINT_MAX : (unsigned)line;
+ return fn;
+}
+#endif /* !MWRAP_RUBY */
reply other threads:[~2023-01-08 23:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://80x24.org/mwrap/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230108234321.16994-1-e@80x24.org \
--to=e@80x24.org \
--cc=mwrap-public@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap.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).