[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

De-referencing a SWIG pointer object in Ruby

Asked by tpbyrne in Ruby Scripting Language, Scripting Languages, C Programming Language, C++ Programming Language

Tags: SWIG, Ruby

Experts,

I used SWIG to generate a Ruby extension. SWIG creates a Ruby data object with getter/setter functions for the C structures in the header file of the wrapped DLL.

For structure fields which are defined as  "unsigned __int8 sCIMSerialNumber[8];", ruby returns a pointer object when the field is accessed e.g.

puts object.sCIMSerialNumber -> #<SWIG::TYPE_p_unsigned___int8:0x2ddd040>

My question is simply; how can I de-reference this to obtain the value or to update the value?
 
Regards,
Tom.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
SWIGINTERN VALUE
_wrap_SCIMStatus_sCIMSerialNumber_set(int argc, VALUE *argv, VALUE self) {
  struct SCIMStatus *arg1 = (struct SCIMStatus *) 0 ;
  unsigned __int8 *arg2 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  void *argp2 = 0 ;
  int res2 = 0 ;
  
  if ((argc < 1) || (argc > 1)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
  }
  res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_SCIMStatus, 0 |  0 );
  if (!SWIG_IsOK(res1)) {
    SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct SCIMStatus *","sCIMSerialNumber", 1, self )); 
  }
  arg1 = (struct SCIMStatus *)(argp1);
  res2 = SWIG_ConvertPtr(argv[0], &argp2,SWIGTYPE_p_unsigned___int8, 0 |  0 );
  if (!SWIG_IsOK(res2)) {
    SWIG_exception_fail(SWIG_ArgError(res2), Ruby_Format_TypeError( "", "unsigned __int8 [8]","sCIMSerialNumber", 2, argv[0] )); 
  } 
  arg2 = (unsigned __int8 *)(argp2);
  {
    if (arg2) {
      size_t ii = 0;
      for (; ii < (size_t)8; ++ii) arg1->sCIMSerialNumber[ii] = arg2[ii];
    } else {
      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""sCIMSerialNumber""' of type '""unsigned __int8 [8]""'");
    }
  }
  return Qnil;
fail:
  return Qnil;
}
 
SWIGINTERN VALUE
_wrap_SCIMStatus_sCIMSerialNumber_get(int argc, VALUE *argv, VALUE self) {
  struct SCIMStatus *arg1 = (struct SCIMStatus *) 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  unsigned __int8 *result = 0 ;
  VALUE vresult = Qnil;
  
  if ((argc < 0) || (argc > 0)) {
    rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
  }
  res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p_SCIMStatus, 0 |  0 );
  if (!SWIG_IsOK(res1)) {
    SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "struct SCIMStatus *","sCIMSerialNumber", 1, self )); 
  }
  arg1 = (struct SCIMStatus *)(argp1);
  result = (unsigned __int8 *)(unsigned __int8 *) ((arg1)->sCIMSerialNumber);
  vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_unsigned___int8, 0 |  0 );
  return vresult;
fail:
  return Qnil;
}
[+][-]09/10/09 01:10 AM, ID: 25298164Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09/12/09 05:59 AM, ID: 25316363Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09/12/09 06:40 AM, ID: 25316498Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/20/09 09:24 AM, ID: 25377760Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625