[#28337] constant look up order in CVS HEAD — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

15 messages 2006/02/18
[#28338] Re: constant look up order in CVS HEAD — Tanaka Akira <akr@...17n.org> 2006/02/19

In article <1140229116.805371.31930.nullmailer@x31.priv.netlab.jp>,

[#28341] Re: constant look up order in CVS HEAD — GOTOU Yuuzou <gotoyuzo@...> 2006/02/19

In message <87lkw8xfay.fsf@m17n.org>,

[#28342] Re: constant look up order in CVS HEAD — Yukihiro Matsumoto <matz@...> 2006/02/19

まつもと ゆきひろです

[ruby-dev:28378] Re: bcc32 memory manager

From: "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
Date: 2006-02-23 08:03:19 UTC
List: ruby-dev #28378
山本です。

>malloc / free の代わりに HeapAlloc / HeapFree を使うというのはど
>うでしょう?(拡張ライブラリ共々ごそっと交換となりますが)

うーん、そうですね、差し替えると calloc とか、strdup とか、(この二つは
ruby が置き換えているので大丈夫ですが)free で解放する必要のある
メモリを返す関数があった場合、漏れがあると怖いので避けていたのですが、
usebormm.lib がない場合にそうするというのはありかもしれません。

# 私はモチベーションが上がらない・・・(汗)

ちょっと試してみたのですが、単に下のようにしただけだと bcc32 では
落ちますね・・・・ win32 だと動くんですけど。

Index: io.c
===================================================================
RCS file: /src/ruby/io.c,v
retrieving revision 1.246.2.97
diff -u -w -b -p -r1.246.2.97 io.c
--- io.c	14 Feb 2006 02:23:33 -0000	1.246.2.97
+++ io.c	23 Feb 2006 07:55:20 -0000
@@ -2899,7 +2899,7 @@ pipe_open(pstr, pname, mode)
     int modef = rb_io_mode_flags(mode);
     OpenFile *fptr;
 
-#if defined(DJGPP) || defined(__human68k__) || defined(__VMS)
+#if defined(DJGPP) || defined(__human68k__) || defined(__VMS) || defined(__BORLANDC__)
     FILE *f;
 
     if (!pname) pname = StringValuePtr(pstr);
Index: win32.c
===================================================================
RCS file: /src/ruby/win32/win32.c,v
retrieving revision 1.103.2.43
diff -u -w -b -p -r1.103.2.43 win32.c
--- win32.c	14 Feb 2006 05:03:16 -0000	1.103.2.43
+++ win32.c	23 Feb 2006 07:56:27 -0000
@@ -3429,6 +3429,11 @@ rb_w32_fclose(FILE *fp)
     if (fflush(fp)) return -1;
     if (!is_socket(sock)) {
 	UnlockFile((HANDLE)sock, 0, 0, LK_LEN, LK_LEN);
+#ifdef __BORLANDC__
+	if (GetFileType((HANDLE)sock) == FILE_TYPE_PIPE) {
+	    return pclose(fp);
+	}
+#endif
 	return fclose(fp);
     }
     _set_osfhnd(fd, (SOCKET)INVALID_HANDLE_VALUE);
@@ -3672,3 +3677,29 @@ rb_w32_fsopen(const char *path, const ch
     return f;
 }
 #endif
+
+
+void *
+rb_w32_malloc(size_t n)
+{
+    return HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, n);
+}
+
+void *
+rb_w32_calloc(size_t i, size_t n)
+{
+    return HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, i * n);
+}
+
+void *
+rb_w32_realloc(void *p, size_t n)
+{
+    return HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, p, n);
+}
+
+void
+rb_w32_free(void *p)
+{
+    HeapFree(GetProcessHeap(), 0, p);
+}
+
Index: win32.h
===================================================================
RCS file: /src/ruby/win32/win32.h,v
retrieving revision 1.46.2.16
diff -u -w -b -p -r1.46.2.16 win32.h
--- win32.h	22 Nov 2005 16:26:39 -0000	1.46.2.16
+++ win32.h	23 Feb 2006 07:55:46 -0000
@@ -128,6 +128,8 @@ extern DWORD rb_w32_osid(void);
 #define write(h, b, l)		_write(h, b, l)
 #define _open			_sopen
 #define sopen			_sopen
+#define popen			_popen
+#define pclose			_pclose
 #undef fopen
 #define fopen(p, m)		rb_w32_fopen(p, m)
 #undef fdopen
@@ -151,6 +153,15 @@ extern DWORD rb_w32_osid(void);
 #undef unlink
 #define unlink(p)		rb_w32_unlink(p)
 
+#undef malloc
+#define malloc(n)		rb_w32_malloc(n)
+#undef calloc
+#define calloc(i, n)		rb_w32_calloc(i, n)
+#undef free
+#define free(p)			rb_w32_free(p)
+#undef realloc
+#define realloc(p, n)		rb_w32_realloc(p, n)
+
 #ifdef __MINGW32__
 struct timezone {
   int tz_minuteswest;
@@ -222,6 +233,11 @@ extern FILE *rb_w32_fdopen(int, const ch
 extern FILE *rb_w32_fsopen(const char *, const char *, int);
 #endif
 
+extern void *rb_w32_malloc(size_t);
+extern void *rb_w32_calloc(size_t, size_t);
+extern void *rb_w32_realloc(void *, size_t);
+extern void  rb_w32_free(void *);
+
 #include <float.h>
 #if !defined __MINGW32__ || defined __NO_ISOCEXT
 #ifndef isnan


In This Thread