mwrap user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] make Ruby headers less intrusive
@ 2023-01-08 23:43 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-01-08 23:43 UTC (permalink / raw)
  To: mwrap-public

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 */

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-08 23:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-08 23:43 [PATCH] make Ruby headers less intrusive Eric Wong

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).