1 %module ruby_manual_proxy
2 
3 
4 %typemap(in, numinputs=0) SWIGTYPE ** ($*1_ltype temp) "$1 = &temp;";
5 
6 %typemap(argout) SWIGTYPE **OUTPARAM {
7   $result = SWIG_Ruby_AppendOutput($result, SWIG_NewPointerObj(*$1, $*1_descriptor, 0));
8 }
9 
10 %apply SWIGTYPE **OUTPARAM {
11   svn_fs_t **
12 };
13 
14 %typemap(check) svn_fs_t * {
15   if (!$1) {
16     svn_swig_rb_raise_svn_fs_already_close();
17   }
18 }
19 
20 %{
21 typedef struct svn_fs_t {
22   char path[256];
23 } svn_fs_t;
24 
svn_fs_create(svn_fs_t ** fs_p,const char * path)25 void svn_fs_create(svn_fs_t **fs_p, const char *path) {
26   svn_fs_t *fs = (svn_fs_t *)malloc(sizeof(svn_fs_t));
27   strncpy(fs->path, path, 256);
28   *fs_p = fs;
29 }
svn_fs_path(svn_fs_t * fs)30 const char *svn_fs_path(svn_fs_t *fs) {
31   return fs->path;
32 }
33 %}
34 
35 typedef struct svn_fs_t svn_fs_t;
36 void svn_fs_create(svn_fs_t **fs_p, const char *path);
37 const char *svn_fs_path(svn_fs_t *fs);
38 
39 %{
svn_swig_rb_raise_svn_fs_already_close(void)40 static void svn_swig_rb_raise_svn_fs_already_close(void) {
41   rb_raise(rb_eIOError, "already closed");
42 }
43 
svn_fs_swig_rb_close(VALUE self)44 static VALUE svn_fs_swig_rb_close(VALUE self) {
45   if (!DATA_PTR(self)) {
46     svn_swig_rb_raise_svn_fs_already_close();
47   }
48 
49   DATA_PTR(self) = NULL;
50 
51   return Qnil;
52 }
53 
svn_fs_swig_rb_closed(VALUE self)54 static VALUE svn_fs_swig_rb_closed(VALUE self) {
55   return DATA_PTR(self) ? Qfalse : Qtrue;
56 }
57 %}
58 
59 %insert("init") %{
60   {
61     VALUE cSvnfs;
62     cSvnfs = rb_const_get(_mSWIG, rb_intern("TYPE_p_svn_fs_t"));
63     rb_define_method(cSvnfs, "close",
64                      VALUEFUNC(svn_fs_swig_rb_close), 0);
65   }
66 %}
67