[ruby-oci8-commit] [302] branches/ruby-oci8-1.0: * ext/oci8/handle.c, ext/oci8/oci8.h, ext/ oci8/svcctx.c: add
nobody at rubyforge.org
nobody at rubyforge.org
Tue Dec 30 06:13:47 EST 2008
Revision: 302
Author: kubo
Date: 2008-12-30 06:13:46 -0500 (Tue, 30 Dec 2008)
Log Message:
-----------
* ext/oci8/handle.c, ext/oci8/oci8.h, ext/oci8/svcctx.c: add
OCISvcCtx.pid, which returns id of the process where the
OCISvcCtx is created.
* lib/oci8.rb.in: add check code to ensure that the process id
is not changed.
Modified Paths:
--------------
branches/ruby-oci8-1.0/ChangeLog
branches/ruby-oci8-1.0/ext/oci8/handle.c
branches/ruby-oci8-1.0/ext/oci8/oci8.h
branches/ruby-oci8-1.0/ext/oci8/svcctx.c
branches/ruby-oci8-1.0/lib/oci8.rb.in
Modified: branches/ruby-oci8-1.0/ChangeLog
===================================================================
--- branches/ruby-oci8-1.0/ChangeLog 2008-12-30 09:03:05 UTC (rev 301)
+++ branches/ruby-oci8-1.0/ChangeLog 2008-12-30 11:13:46 UTC (rev 302)
@@ -1,4 +1,11 @@
2008-12-30 KUBO Takehiro <kubo at jiubao.org>
+ * ext/oci8/handle.c, ext/oci8/oci8.h, ext/oci8/svcctx.c: add
+ OCISvcCtx.pid, which returns id of the process where the
+ OCISvcCtx is created.
+ * lib/oci8.rb.in: add check code to ensure that the process id
+ is not changed.
+
+2008-12-30 KUBO Takehiro <kubo at jiubao.org>
* ext/oci8/const.c, ext/oci8/handle.c: suppress compilation warnings.
(contributed by Daniel Berger)
Modified: branches/ruby-oci8-1.0/ext/oci8/handle.c
===================================================================
--- branches/ruby-oci8-1.0/ext/oci8/handle.c 2008-12-30 09:03:05 UTC (rev 301)
+++ branches/ruby-oci8-1.0/ext/oci8/handle.c 2008-12-30 11:13:46 UTC (rev 302)
@@ -10,7 +10,17 @@
=end
*/
#include "oci8.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* getpid() */
+#endif
+#ifdef WIN32
+#ifndef getpid
+extern rb_pid_t rb_w32_getpid(void);
+#define getpid() rb_w32_getpid()
+#endif
+#endif
+
static void oci8_handle_do_free(oci8_handle_t *h)
{
unsigned int i;
@@ -149,6 +159,7 @@
break;
case OCI_HTYPE_SVCCTX:
obj = Data_Make_Struct(cOCISvcCtx, oci8_handle_t, oci8_handle_mark, oci8_handle_cleanup, h);
+ h->u.svcctx.pid = getpid();
break;
case OCI_HTYPE_STMT:
obj = Data_Make_Struct(cOCIStmt, oci8_handle_t, oci8_handle_mark, oci8_handle_cleanup, h);
Modified: branches/ruby-oci8-1.0/ext/oci8/oci8.h
===================================================================
--- branches/ruby-oci8-1.0/ext/oci8/oci8.h 2008-12-30 09:03:05 UTC (rev 301)
+++ branches/ruby-oci8-1.0/ext/oci8/oci8.h 2008-12-30 11:13:46 UTC (rev 302)
@@ -10,6 +10,14 @@
#include "rubyio.h"
#include "intern.h"
+#ifndef rb_pid_t
+#ifdef WIN32
+#define rb_pid_t int
+#else
+#define rb_pid_t pid_t
+#endif
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
@@ -134,6 +142,9 @@
int char_width;
} lob_locator;
#endif
+ struct {
+ rb_pid_t pid;
+ } svcctx;
} u;
};
typedef struct oci8_handle oci8_handle_t;
Modified: branches/ruby-oci8-1.0/ext/oci8/svcctx.c
===================================================================
--- branches/ruby-oci8-1.0/ext/oci8/svcctx.c 2008-12-30 09:03:05 UTC (rev 301)
+++ branches/ruby-oci8-1.0/ext/oci8/svcctx.c 2008-12-30 11:13:46 UTC (rev 302)
@@ -180,6 +180,14 @@
return self;
}
+static VALUE oci8_pid(VALUE self)
+{
+ oci8_handle_t *h;
+
+ Get_Handle(self, h); /* 0 */
+ return INT2FIX(h->u.svcctx.pid);
+}
+
void Init_oci8_svcctx(void)
{
rb_define_method(cOCISvcCtx, "logoff", oci8_svcctx_logoff, 0);
@@ -196,6 +204,7 @@
rb_define_method(cOCISvcCtx, "reset", oci8_reset, 0);
#endif
rb_define_method(cOCISvcCtx, "close_all_files", oci8_close_all_files, 0);
+ rb_define_method(cOCISvcCtx, "pid", oci8_pid, 0);
}
/*
Modified: branches/ruby-oci8-1.0/lib/oci8.rb.in
===================================================================
--- branches/ruby-oci8-1.0/lib/oci8.rb.in 2008-12-30 09:03:05 UTC (rev 301)
+++ branches/ruby-oci8-1.0/lib/oci8.rb.in 2008-12-30 11:13:46 UTC (rev 302)
@@ -679,6 +679,9 @@
end
def initialize(env, svc, ctx, stmt = nil)
+ if Process.pid != svc.pid
+ raise "The connection cannot be reused in the forked process."
+ end
@env = env
@svc = svc
@ctx = ctx
More information about the ruby-oci8-commit
mailing list