<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v = 
"urn:schemas-microsoft-com:vml" xmlns:o = 
"urn:schemas-microsoft-com:office:office" xmlns:w = 
"urn:schemas-microsoft-com:office:word" xmlns:m = 
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3268" name=GENERATOR><!--[if !mso]>
<STYLE>v\:* {
        BEHAVIOR: url(#default#VML)
}
o\:* {
        BEHAVIOR: url(#default#VML)
}
w\:* {
        BEHAVIOR: url(#default#VML)
}
.shape {
        BEHAVIOR: url(#default#VML)
}
</STYLE>
<![endif]-->
<STYLE>@font-face {
        font-family: Calibri;
}
@font-face {
        font-family: Tahoma;
}
@font-face {
        font-family: Consolas;
}
@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 72.0pt 72.0pt 72.0pt; }
P.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman","serif"
}
LI.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman","serif"
}
DIV.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman","serif"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
P.MsoPlainText {
        FONT-SIZE: 10.5pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: Consolas; mso-style-priority: 99; mso-style-link: "Plain Text Char"
}
LI.MsoPlainText {
        FONT-SIZE: 10.5pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: Consolas; mso-style-priority: 99; mso-style-link: "Plain Text Char"
}
DIV.MsoPlainText {
        FONT-SIZE: 10.5pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: Consolas; mso-style-priority: 99; mso-style-link: "Plain Text Char"
}
SPAN.gmailquote {
        mso-style-name: gmail_quote
}
SPAN.EmailStyle18 {
        COLOR: #1f497d; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-reply
}
SPAN.PlainTextChar {
        FONT-FAMILY: Consolas; mso-style-priority: 99; mso-style-link: "Plain Text"; mso-style-name: "Plain Text Char"
}
.MsoChpDefault {
        FONT-SIZE: 10pt; mso-style-type: export-only
}
DIV.Section1 {
        page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV dir=ltr align=left><SPAN class=624484514-12032008><FONT face=Arial 
color=#0000ff size=2>The short answer is that you don't need 
to:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=624484514-12032008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=624484514-12032008><FONT face=Arial 
color=#0000ff size=2>Anything that has a 'handle' attribute that is an 
int should be fine to pass into the function, and your typemap will be fine 
(with some additional checking)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=624484514-12032008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=624484514-12032008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=624484514-12032008><FONT face=Arial 
color=#0000ff size=2>If you really insist on absolute type safety, however, 
you'll need an instance of the Pin class to compare to. Actually, all you need 
is an instance of the Pin Type -- you can use PyObject_TypeCheck (if I 
recall).</FONT></SPAN></DIV>
<DIV><SPAN class=624484514-12032008><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=624484514-12032008><FONT face=Arial color=#0000ff 
size=2>Chances are, the name 'Pin' is already in your locals or globals, so 
you find the object, grab its type, and then check the type.</FONT></SPAN></DIV>
<DIV><SPAN class=624484514-12032008><FONT face=Arial color=#0000ff 
size=2>Personally, I wouldn't bother.</FONT></SPAN></DIV>
<DIV><SPAN class=624484514-12032008><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=624484514-12032008><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=624484514-12032008><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=624484514-12032008><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><BR></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Cooper, Andrew [mailto:ACooper@cimtek.com] 
<BR><B>Sent:</B> Tuesday, March 11, 2008 7:34 PM<BR><B>To:</B> 
python-list@python.org<BR><B>Subject:</B> RE: Obtaining the PyObject * of a 
class<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=Section1>
<P class=MsoPlainText>The part I’m having problem with is as 
follows:<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>I want to replace the ‘strcmp’ below with a call to 
PyObject_IsInstance(o, pinClassPyObject)<o:p></o:p></P>
<P class=MsoPlainText>But I don’t know how to get the PyObject* for the Pin 
class that is defined in the %pythoncode section<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>Here is a cut down version of the interface 
file<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>%module example<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>typedef long pin;<o:p></o:p></P>
<P class=MsoPlainText>typedef unsigned short ushort;<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>ushort wkDefinePin(char *, char *, pin 
*OUTPUT);<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>%pythoncode<o:p></o:p></P>
<P class=MsoPlainText>{<o:p></o:p></P>
<P class=MsoPlainText>  class Pin(object):<o:p></o:p></P>
<P class=MsoPlainText>    def __init__(self, name, 
tic):<o:p></o:p></P>
<P class=MsoPlainText>      self.handle = 
wkDefinePin(name,tic)[1]<o:p></o:p></P>
<P class=MsoPlainText>      
return     <o:p></o:p></P>
<P class=MsoPlainText>}         
<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>%typemap(in) (pin tp)<o:p></o:p></P>
<P class=MsoPlainText>{<o:p></o:p></P>
<P class=MsoPlainText>  //<o:p></o:p></P>
<P class=MsoPlainText>  // TODO: really need to change this to IsInstance 
type code<o:p></o:p></P>
<P class=MsoPlainText>  //<o:p></o:p></P>
<P class=MsoPlainText>  if(strcmp($input->ob_type->tp_name,"Pin") == 
0)<o:p></o:p></P>
<P class=MsoPlainText>  {<o:p></o:p></P>
<P class=MsoPlainText>    $1 = 
PyInt_AsLong(PyObject_GetAttrString($input,"handle"));<o:p></o:p></P>
<P class=MsoPlainText>  }<o:p></o:p></P>
<P class=MsoPlainText>  else<o:p></o:p></P>
<P class=MsoPlainText>  {<o:p></o:p></P>
<P class=MsoPlainText>    PyErr_SetString(PyExc_TypeError,"arg 
must be type Pin");<o:p></o:p></P>
<P class=MsoPlainText>    return NULL;<o:p></o:p></P>
<P class=MsoPlainText>  }<o:p></o:p></P>
<P class=MsoPlainText>}<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>%typemap(in) (int nCnt_tp, pin *tp)<o:p></o:p></P>
<P class=MsoPlainText>{<o:p></o:p></P>
<P class=MsoPlainText>  /* Check if is a list */<o:p></o:p></P>
<P class=MsoPlainText>  if (PyList_Check($input))<o:p></o:p></P>
<P class=MsoPlainText>  {<o:p></o:p></P>
<P class=MsoPlainText>    int i;<o:p></o:p></P>
<P class=MsoPlainText>    $1 = 
PyList_Size($input);<o:p></o:p></P>
<P class=MsoPlainText>    $2 = (pin *) malloc(($1) * 
sizeof(pin));<o:p></o:p></P>
<P class=MsoPlainText>    for (i = 0; i < $1; i++) 
<o:p></o:p></P>
<P class=MsoPlainText>    {<o:p></o:p></P>
<P class=MsoPlainText>      //<o:p></o:p></P>
<P class=MsoPlainText>      // TODO: really need to 
change this to IsInstance type code<o:p></o:p></P>
<P class=MsoPlainText>      //<o:p></o:p></P>
<P class=MsoPlainText>      PyObject *o = 
PyList_GetItem($input,i);<o:p></o:p></P>
<P class=MsoPlainText>      if 
(strcmp(o->ob_type->tp_name, "Pin") == 0)<o:p></o:p></P>
<P class=MsoPlainText>      {<o:p></o:p></P>
<P class=MsoPlainText>        $2[i] = 
PyInt_AsLong(PyObject_GetAttrString(o,"handle"));<o:p></o:p></P>
<P class=MsoPlainText>      }<o:p></o:p></P>
<P class=MsoPlainText>      else <o:p></o:p></P>
<P class=MsoPlainText>      {<o:p></o:p></P>
<P class=MsoPlainText>        
PyErr_SetString(PyExc_TypeError,"list must contain Pins");<o:p></o:p></P>
<P class=MsoPlainText>        
free($2);<o:p></o:p></P>
<P class=MsoPlainText>        return 
NULL;<o:p></o:p></P>
<P class=MsoPlainText>      }<o:p></o:p></P>
<P class=MsoPlainText>    }<o:p></o:p></P>
<P class=MsoPlainText>    $2[i] = 0;<o:p></o:p></P>
<P class=MsoPlainText>  }<o:p></o:p></P>
<P class=MsoPlainText>  else<o:p></o:p></P>
<P class=MsoPlainText>  {<o:p></o:p></P>
<P class=MsoPlainText>    PyErr_SetString(PyExc_TypeError,"not a 
list");<o:p></o:p></P>
<P class=MsoPlainText>    return NULL;<o:p></o:p></P>
<P class=MsoPlainText>  }<o:p></o:p></P>
<P class=MsoPlainText>}<o:p></o:p></P>
<P class=MsoPlainText><o:p> </o:p></P>
<P class=MsoPlainText>-- <o:p></o:p></P>
<P class=MsoNormal><A 
href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</A><SPAN 
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'"><o:p> </o:p></SPAN></P>
<DIV>
<DIV 
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 3pt; BORDER-BOTTOM: medium none">
<P class=MsoNormal><B><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">From:</SPAN></B><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'"> 
python-list-bounces+acooper=cimtek.com@python.org 
[mailto:python-list-bounces+acooper=cimtek.com@python.org] <B>On Behalf Of 
</B>Bronner, Gregory<BR><B>Sent:</B> 11 March 2008 20:52<BR><B>To:</B> Michael 
Wieher; python-list@python.org; accooper@cimtek.com<BR><B>Subject:</B> RE: 
Obtaining the PyObject * of a class<o:p></o:p></SPAN></P></DIV></DIV>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'">I'd 
strongly disagree.</SPAN><o:p></o:p></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'">SWIG is 
very useful for wrapping large scale projects in a non-interfering manner. If 
you have to generate bindings for 1000+ classes, it is by far the easiest way to 
do things.</SPAN><o:p></o:p></P>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'">It isn't 
clear what you are doing that requires the PyObject*, or which one you'd 
like.</SPAN><o:p></o:p></P>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal><SPAN 
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'">In 
general, the output one is found in $result, and $input is input PyObject for 
that typemap.</SPAN><o:p></o:p></P>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal> <o:p></o:p></P>
<P class=MsoNormal><o:p> </o:p></P>
<DIV class=MsoNormal style="TEXT-ALIGN: center" align=center>
<HR align=center width="100%" SIZE=2>
</DIV>
<P class=MsoNormal style="MARGIN-BOTTOM: 12pt"><B><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">From:</SPAN></B><SPAN 
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'"> Michael Wieher 
[mailto:michael.wieher@gmail.com] <BR><B>Sent:</B> Tuesday, March 11, 2008 3:09 
PM<BR><B>To:</B> python-list@python.org<BR><B>Subject:</B> Re: Obtaining the 
PyObject * of a class</SPAN><o:p></o:p></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 12pt">2 things:<BR><BR>1st. there is a 
python mailing list for people interested in C++ extension type stuff<BR>2nd. 
SWIG is useless and overly complicated, its much easier to just generate your 
own C++ code by hand, less confusion, and much more clarity.  I find no 
value in using anything else.<BR>People complain about the "boilerplate" code, 
but honestly, copy & paste, change three characters, and you're done.  
And you know exactly what is happening, how when and why.<o:p></o:p></P>
<DIV>
<P class=MsoNormal><SPAN class=gmailquote>2008/3/11, Chris Mellon <<A 
href="mailto:arkanes@gmail.com">arkanes@gmail.com</A>>:</SPAN> 
<o:p></o:p></P>
<P class=MsoNormal>On Tue, Mar 11, 2008 at 12:13 PM, Terry Reedy <<A 
href="mailto:tjreedy@udel.edu">tjreedy@udel.edu</A>> 
wrote:<BR>><BR>>  "Cooper, Andrew" <<A 
href="mailto:ACooper@cimtek.com">ACooper@cimtek.com</A>> wrote in 
message<BR>>  news:C03234BF0E2A8C419C4C307D0914EB730251D3A9@MAILSERVER.cimtek.on.ca...<BR>><BR>> 
| Are there any Python C API experts/SWIG experts out there that can 
help<BR>>  | me with this issue please.<BR>><BR>> | I',m 
currently using SWIG to generate a python interface to a C 
DLL.<BR>><BR>>  Some people have switched to using ctypes for 
this, and many other SWIG<BR>>  users have stopped reading 
clp.  But I hope someone answers who can.<BR>><BR><BR><BR>Using 
Pyrex or Cython is likely to be much easier than using SWIG for 
this.<BR><BR>--<BR><A 
href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</A><o:p></o:p></P></DIV>
<P class=MsoNormal><o:p> </o:p></P>
<P class=MsoNormal>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - - - - - - - - - - - This message is intended only for the personal and 
confidential use of the designated recipient(s) named above. If you are not the 
intended recipient of this message you are hereby notified that any review, 
dissemination, distribution or copying of this message is strictly prohibited. 
This communication is for information purposes only and should not be regarded 
as an offer to sell or as a solicitation of an offer to buy any financial 
product, an official confirmation of any transaction, or as an official 
statement of Lehman Brothers. Email transmission cannot be guaranteed to be 
secure or error-free. Therefore, we do not represent that this information is 
complete or accurate and it should not be relied upon as such. All information 
is subject to change without notice. -------- IRS Circular 230 Disclosure: 
Please be advised that any discussion of U.S. tax matters contained within this 
communication (including any attachments) is not intended or written to be used 
and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or 
(ii) promoting, marketing or recommending to another party any transaction or 
matter addressed herein. <o:p></o:p></P></DIV></BODY></HTML>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.

--------
IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein.