home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Languages / python / PyObjC-0.47-MIHS / pyobjc-0.47-src / Modules / ObjCObject.m < prev    next >
Encoding:
Text File  |  1996-11-13  |  20.2 KB  |  840 lines

  1. /* Copyright (c) 1996 by Lele Gaifax.  All Rights Reserved
  2.  *
  3.  * This software may be used and distributed freely for any purpose
  4.  * provided that this notice is included unchanged on any and all
  5.  * copies. The author does not warrant or guarantee this software in
  6.  * any way.
  7.  *
  8.  * This file is part of the PyObjC package.
  9.  *
  10.  * $RCSfile: ObjCObject.m,v $
  11.  * $Revision: 1.1.1.1 $
  12.  * $Date: 1996/11/14 01:50:23 $
  13.  *
  14.  * Created Mon Oct 28 12:32:11 1996.
  15.  */
  16.  
  17. #include "ObjC.h"
  18. #include "objc_support.h"
  19.  
  20. #ifndef WITH_FOUNDATION
  21. #define RESPONDS(obj,NXsel,OSsel)    [obj respondsTo:@selector (NXsel)]
  22. #define PERFORM1(obj,NXsel,OSsel,v1) [obj NXsel v1]
  23. #else
  24. #define RESPONDS(obj,NXsel,OSsel)    [obj respondsToSelector:@selector (OSsel)]
  25. #define PERFORM1(obj,NXsel,OSsel,v1) [obj OSsel v1]
  26. #endif
  27.  
  28. #define IS_MAPPING(obj) ((RESPONDS(obj, count, count) ||        \
  29.                RESPONDS(obj, length, length)) &&        \
  30.               RESPONDS(obj, valueForKey:, objectForKey:))
  31. #define IS_SEQUENCE(obj) ((RESPONDS(obj, count, count) ||        \
  32.                RESPONDS(obj, length, length)) &&        \
  33.               RESPONDS(obj, objectAt:, objectAtIndex:))
  34.  
  35.  
  36. ObjCObject *
  37. ObjCObject_new (id obj)
  38. {
  39.   ObjCObject *self;
  40.  
  41.   if (IS_MAPPING (obj))
  42.     self = PyObject_NEW (ObjCObject, &ObjCMappingObject_Type);
  43.   else if (IS_SEQUENCE (obj))
  44.     self = PyObject_NEW (ObjCObject, &ObjCSequenceObject_Type);
  45.   else
  46.     self = PyObject_NEW (ObjCObject, &ObjCObject_Type);
  47.        
  48.   if (self == NULL)
  49.     return NULL;
  50.  
  51. #ifdef WITH_FOUNDATION
  52.   [obj retain];
  53. #else
  54.   // XXX [obj retain];
  55. #endif
  56.   
  57.   self->oc_object = obj;
  58.   self->methods = PyDict_New();
  59.   
  60.   return self;
  61. }
  62.  
  63. static void
  64. ObjCObject_dealloc (ObjCObject *self)
  65. {
  66. #ifdef WITH_FOUNDATION
  67.   [self->oc_object release];
  68. #else
  69.   // XXX [self->oc_object release];
  70. #endif
  71.  
  72.   Py_DECREF (self->methods);
  73.   PyMem_DEL (self);
  74. }
  75.  
  76. static PyObject *
  77. ObjCObject_repr (ObjCObject *self)
  78. {
  79.   char buffer[512];
  80.   char *p;
  81.  
  82.   if (self->oc_object == nil)
  83.     p = "<Objective-C nil>";
  84.   else
  85.     {
  86.       sprintf(buffer, "<Objective-C `%s' %s at %lx>",
  87.           NAMEOF(self->oc_object),
  88.           (ISCLASS (self->oc_object) ? "class" : "instance"),
  89.           (long) self->oc_object);
  90.       p = buffer;
  91.     }
  92.   return PyString_FromString (p);
  93. }
  94.  
  95. static char ObjCObject_is_instance_doc[] =
  96. FUNDOC("Check whether the receiving object is an Objective-C instance or class.",
  97.        ".is_instance()",
  98.        "none",
  99.        "True if it's an instance, False otherwise");
  100. static PyObject *
  101. ObjCObject_is_instance (ObjCObject *self, PyObject *args)
  102. {
  103.   if (PyArg_ParseTuple (args, ""))
  104.     {
  105.       PyObject *yn;
  106.  
  107.       if (ISCLASS(self->oc_object))
  108.     yn = Py_False;
  109.       else
  110.     yn = Py_True;
  111.  
  112.       Py_INCREF (yn);
  113.       return yn;
  114.     }
  115.  
  116.   return NULL;
  117. }
  118.  
  119. static char ObjCObject_is_class_doc[] =
  120. FUNDOC("Check whether the receiving object is an Objective-C instance or class.",
  121.        ".is_class()",
  122.        "none",
  123.        "True if it's a class, False otherwise");
  124. static PyObject *
  125. ObjCObject_is_class (ObjCObject *self, PyObject *args)
  126. {
  127.   if (PyArg_ParseTuple (args, ""))
  128.     {
  129.       PyObject *yn;
  130.  
  131.       if (ISCLASS(self->oc_object))
  132.     yn = Py_True;
  133.       else
  134.     yn = Py_False;
  135.  
  136.       Py_INCREF (yn);
  137.       return yn;
  138.     }
  139.  
  140.   return NULL;
  141. }
  142.  
  143. static char ObjCObject_get_class_doc[] =
  144. FUNDOC("Get the superclass of the receiving Objective-C object.",
  145.        ".Class()",
  146.        "none",
  147.        "An ObjCObject wrapping the Objective-C class");
  148.  
  149. static PyObject *
  150. ObjCObject_get_class (ObjCObject *self, PyObject *args)
  151. {
  152.   if (PyArg_ParseTuple (args, ""))
  153.     {
  154.       id class = [self->oc_object class];
  155.  
  156.       return (PyObject *) ObjCObject_new (class);
  157.     }
  158.   return NULL;
  159. }
  160.  
  161. static PyMethodDef ObjCObject_methods[] =
  162. {
  163.   { "isInstance",    (PyCFunction) ObjCObject_is_instance,    METH_VARARGS, ObjCObject_is_instance_doc },
  164.   { "isClass",        (PyCFunction) ObjCObject_is_class,    METH_VARARGS, ObjCObject_is_class_doc },
  165.  
  166.   { "Class",        (PyCFunction) ObjCObject_get_class,    METH_VARARGS, ObjCObject_get_class_doc },
  167.   { 0, 0, 0, 0 }
  168. };
  169.  
  170. extern PyMethodDef ObjCSequenceObject_methods[];
  171. extern PyMethodDef ObjCMappingObject_methods[];
  172.  
  173. static PyObject *
  174. ObjCObject_getattr (ObjCObject *self, char *name)
  175. {
  176.   PyObject *method;
  177.   
  178.   method = Py_FindMethod (ObjCObject_methods, (PyObject *) self, name);
  179.   if (method)
  180.     return method;
  181.  
  182.   if (ObjCSequenceObject_Check (self))
  183.     method = Py_FindMethod (ObjCSequenceObject_methods, (PyObject *) self, name);
  184.   else if (ObjCMappingObject_Check (self))
  185.     method = Py_FindMethod (ObjCMappingObject_methods, (PyObject *) self, name);
  186.  
  187.   if (method)
  188.     return method;
  189.   else
  190.     {
  191.       char meth_name[strlen (name)+1];
  192.       
  193.       PyErr_Clear();
  194. #if PYTHONIFICATION_METHOD != WITH_BOTH
  195.       depythonify_objc_message (name, meth_name);
  196.       method = PyDict_GetItemString (self->methods, meth_name);
  197.       
  198.       if (! method)
  199.     {
  200.       method = (PyObject *) ObjCMethod_new_with_name (self, meth_name);
  201.       
  202.       if (method)
  203.         {
  204.           PyErr_Clear();
  205.           PyDict_SetItemString (self->methods, meth_name, method);
  206.         }
  207.     }
  208.       else
  209.     Py_INCREF (method);
  210.       
  211.       return method;
  212. #else
  213.       depythonify_objc_message (name, meth_name, PYTHONIFICATION_FIRST_TRY);
  214.       method = PyDict_GetItemString (self->methods, meth_name);
  215.       
  216.       if (! method)
  217.     {
  218.       method = (PyObject *) ObjCMethod_new_with_name (self, meth_name);
  219.       
  220.       if (method)
  221.         {
  222.           PyErr_Clear();
  223.           PyDict_SetItemString (self->methods, meth_name, method);
  224.           return method;
  225.         }
  226.     }
  227.       else
  228.     {
  229.       Py_INCREF (method);
  230.       return method;
  231.     }
  232.       
  233. #if PYTHONIFICATION_FIRST_TRY == WITH_DOUBLE_UNDERSCORE
  234.       depythonify_objc_message (name, meth_name, WITH_SINGLE_UNDERSCORE);
  235. #else
  236.       depythonify_objc_message (name, meth_name, WITH_DOUBLE_UNDERSCORE);
  237. #endif
  238.       method = PyDict_GetItemString (self->methods, meth_name);
  239.       
  240.       if (! method)
  241.     {
  242.       method = (PyObject *) ObjCMethod_new_with_name (self, meth_name);
  243.       
  244.       if (method)
  245.         {
  246.           PyErr_Clear();
  247.           PyDict_SetItemString (self->methods, meth_name, method);
  248.           
  249.           if (Py_VerboseFlag)
  250.         {
  251.           char faster_name[200];
  252.           
  253.           fprintf (stderr, "PyObjC Warning: method `%s' matches `%s',\n\t", name, meth_name);
  254.           
  255.           pythonify_objc_message (meth_name, faster_name, PYTHONIFICATION_FIRST_TRY);
  256.           
  257.           fprintf (stderr, "but `%s' would be faster.\n", faster_name);
  258.         }
  259.         }
  260.     }
  261.       else
  262.     Py_INCREF (method);
  263.       
  264.       return method;
  265.       
  266. #endif /* PYTHONIFICATION_METHOD != WITH_BOTH */
  267.     }
  268.  
  269.   PyErr_SetString (PyExc_AttributeError, name);
  270.   return NULL;
  271. }
  272.  
  273. static PyObject *
  274. ObjCObject_call (ObjCObject *self, PyObject *args, PyObject *kw)
  275. {
  276.   if (ISCLASS(self->oc_object))
  277.     {
  278.       if (kw)
  279.     {
  280. #define INITMSG "init"
  281.       PyObject *initselname = PyDict_GetItemString (kw, INITMSG);
  282.       char *selname;
  283.       SEL sel;
  284.       
  285.       if (initselname && PyString_Check (initselname))
  286.         {
  287.           selname = PyString_AS_STRING ((PyStringObject *) initselname);
  288.         }
  289.       else
  290.         {
  291.           int nargs = PyTuple_Size (args);
  292.           register char *selarg;
  293.  
  294.           PyErr_Clear();
  295.           
  296.           selname = alloca (sizeof (INITMSG) + nargs);
  297.           strcpy (selname, INITMSG);
  298.           selarg = selname + sizeof (INITMSG) - 1;
  299.           while (nargs--)
  300.         *selarg++ = ':';
  301.           *selarg = '\0';
  302.         }
  303.  
  304.       sel = SELUID(selname);
  305.  
  306.       if (sel && [self->oc_object instancesRespondTo:sel])
  307.         {
  308.           ObjCObject *instance = ObjCObject_new ([self->oc_object alloc]);
  309.           ObjCMethod *initsel = ObjCMethod_new_with_name (instance,
  310.                                   PyString_AsString (initselname));
  311.           PyObject *result;
  312.           
  313.           result = execute_and_pythonify_objc_method (initsel, args);
  314.           
  315.           Py_DECREF (instance);
  316.           Py_DECREF (initsel);
  317.           
  318.           return result;
  319.         }
  320.       else
  321.         {
  322. #define ERRORMSG " does not recognize "
  323.           const char *whoiam = NAMEOF(self->oc_object);
  324.           char buffer[strlen (whoiam) + sizeof ERRORMSG + 1 + strlen (selname) + 1];
  325.           
  326.           strcpy (buffer, whoiam);
  327.           strcat (buffer, ERRORMSG);
  328.           strcat (buffer, (ISCLASS(self->oc_object) ? "+" : "-"));
  329.           strcat (buffer, selname);
  330.           PyErr_SetString (ObjC_Error, buffer);
  331. #undef ERRORMSG
  332.           return NULL;
  333.         }
  334.     }
  335.       else
  336.     if (PyArg_ParseTuple (args, ""))
  337.       {
  338.         id instance = [self->oc_object new];
  339.         
  340.         return (PyObject *) ObjCObject_new (instance);
  341.       }
  342.     }
  343.   else
  344.     PyErr_SetString (ObjC_Error, "call syntax allowed only for classes");
  345.  
  346.   return NULL;
  347. }
  348.  
  349. // SEQUENCING
  350.  
  351. #ifndef WITH_FOUNDATION
  352. #import <objc/List.h>        // for -objectAt:
  353. #else
  354. #include <Foundation/NSArray.h>    // for -objectAtIndex:
  355. #endif
  356.  
  357. #define RETURN_WRAP(result) do {            \
  358.   id wrap = result;                    \
  359.                             \
  360.   if (wrap)                        \
  361.     {                            \
  362.       PyObject *ret;                    \
  363.                                   \
  364.       if ([wrap isKindOf:[OC_PythonObject class]])    \
  365.     {                        \
  366.       ret = [wrap object];                \
  367.       Py_INCREF (ret);                \
  368.     }                        \
  369.       else                        \
  370.     ret = (PyObject *) ObjCObject_new (wrap);    \
  371.                                   \
  372.       return ret;                    \
  373.     }                            \
  374.   else                            \
  375.     return NULL;                    \
  376. } while(0)
  377.  
  378. static PyObject *
  379. WRAP (id result)
  380. {
  381.   RETURN_WRAP (result);
  382. }
  383.  
  384. static int
  385. ObjCObject_sq_length (ObjCObject *self)
  386. {
  387.   if ([self->oc_object respondsTo:@selector (count)])
  388.     return [self->oc_object count];
  389.   else if ([self->oc_object respondsTo:@selector (length)])
  390.     return [self->oc_object length];
  391.   else
  392.     {
  393.       PyErr_SetString (PyExc_TypeError, "len() of unsized object");
  394.       return -1;
  395.     }
  396. }
  397.  
  398. static PyObject *
  399. ObjCObject_sq_concat (ObjCObject *self, PyObject *other)
  400. {
  401.   if (!ObjCSequenceObject_Check (other) &&
  402.       !PySequence_Check (other))
  403.     {
  404.       PyErr_BadArgument();
  405.       return NULL;
  406.     }
  407.   else
  408.     {
  409.       int mysize = ObjCObject_sq_length (self);
  410.       int size;
  411.       int i;
  412.       PyListObject *np;
  413.  
  414.       if (ObjCSequenceObject_Check (other))
  415.     size = mysize + ObjCObject_sq_length ((ObjCObject *) other);
  416.       else
  417.     size = mysize + PySequence_Length (other);
  418.       np = (PyListObject *) PyList_New (size);
  419.       
  420.       if (np == NULL)
  421.     {
  422.       return NULL;
  423.     }
  424.  
  425.       for (i = 0; i < mysize; i++)
  426.     {
  427.       PyObject *v = WRAP(PERFORM1(self->oc_object, objectAt:, objectAtIndex:, i));
  428.  
  429.       np->ob_item[i] = v;
  430.     }
  431.  
  432.       if (ObjCSequenceObject_Check (other))
  433.     {
  434.       for (; i < size; i++)
  435.         {
  436.           PyObject *v = WRAP(PERFORM1(((ObjCObject *) other)->oc_object, objectAt:, objectAtIndex:, i-mysize));
  437.  
  438.           np->ob_item[i] = v;
  439.         }
  440.     }
  441.       else
  442.     {
  443.       for (; i < size; i++)
  444.         {
  445.           PyObject *v = ((PyListObject *) other)->ob_item[i-mysize];
  446.           
  447.           Py_INCREF(v);
  448.           np->ob_item[i] = v;
  449.         }
  450.     }
  451.       
  452.       return (PyObject *) np;
  453.     }
  454. }
  455.  
  456. static PyObject *
  457. ObjCObject_sq_repeat (ObjCObject *self, int n)
  458. {
  459.   int size, mysize = ObjCObject_sq_length (self);
  460.   PyListObject *np;
  461.   PyObject **p;
  462.   
  463.   size = mysize*n;
  464.   np = (PyListObject *) PyList_New (size);
  465.   
  466.   if (np == NULL)
  467.     {
  468.       return NULL;
  469.     }
  470.  
  471.   p = np->ob_item;
  472.   while (n--)
  473.     {
  474.       int i;
  475.  
  476.       for (i=0; i<mysize; i++)
  477.     {
  478.       *p = WRAP(PERFORM1(self->oc_object, objectAt:, objectAtIndex:, i));
  479.       p++;
  480.     }
  481.     }
  482.  
  483.   return (PyObject *) np;
  484. }
  485.  
  486. static PyObject *
  487. ObjCObject_sq_item (ObjCObject *self, int n)
  488. {
  489.   if (n < ObjCObject_sq_length (self))
  490.     RETURN_WRAP(PERFORM1(self->oc_object, objectAt:, objectAtIndex:, n));
  491.  
  492.   PyErr_SetString (PyExc_IndexError, "sequence index out of range");
  493.   return NULL;
  494. }
  495.  
  496. static PyObject *
  497. ObjCObject_sq_slice (ObjCObject *self, int ilow, int ihigh)
  498. {
  499.   PyListObject *np;
  500.   int i, mysize = ObjCObject_sq_length (self);
  501.   
  502.   if (ilow < 0)
  503.     ilow = 0;
  504.   else if (ilow > mysize)
  505.     ilow = mysize;
  506.  
  507.   if (ihigh < 0)
  508.     ihigh = 0;
  509.   if (ihigh < ilow)
  510.     ihigh = ilow;
  511.   else if (ihigh > mysize)
  512.     ihigh = mysize;
  513.  
  514.   np = (PyListObject *) PyList_New (ihigh - ilow);
  515.   if (np == NULL)
  516.     return NULL;
  517.  
  518.   for (i=ilow; i<ihigh; i++)
  519.     {
  520.       PyObject *v = WRAP(PERFORM1(self->oc_object, objectAt:, objectAtIndex:, i));
  521.       
  522.       np->ob_item[i-ilow] = v;
  523.     }
  524.  
  525.   return (PyObject *) np;
  526. }
  527.  
  528. static int
  529. ObjCObject_sq_ass_item (ObjCObject *self, int i, PyObject *v)
  530. {
  531.   if (i < 0 || i >= ObjCObject_sq_length (self))
  532.     {
  533.       PyErr_SetString (PyExc_IndexError, "sequence assignment index out of range");
  534.       return -1;
  535.     }
  536.  
  537.   if (v == NULL)
  538.     {
  539.       if (RESPONDS (self->oc_object, removeObjectAt:, removeObjectAtIndex:))
  540.     {
  541. #ifndef WITH_FOUNDATION
  542.       id old = [self->oc_object removeObjectAt:i];
  543.  
  544.       [old free];
  545. #else
  546.       [self->oc_object removeObjectAtIndex:i];
  547. #endif
  548.     }
  549.       else
  550.     {
  551.       PyErr_SetString (PyExc_TypeError, "cannot remove objects from sequence");
  552.       return -1;
  553.     }
  554.     }
  555.   else
  556.     {
  557.       if (RESPONDS (self->oc_object, replaceObjectAt:with:, replaceObjectAtIndex:withObject:))
  558.     {
  559.       id new = [OC_PythonObject newWithObject:v];
  560.       
  561. #ifndef WITH_FOUNDATION
  562.       id old = [self->oc_object replaceObjectAt:i with:new];
  563.  
  564.       [old free];
  565. #else
  566.       [self->oc_object replaceObjectAtIndex:i withObject:new];
  567. #endif
  568.     }
  569.       else
  570.     {
  571.       PyErr_SetString (PyExc_TypeError, "cannot replace objects in sequence");
  572.       return -1;
  573.     }
  574.     }
  575.  
  576.   return 0;
  577. }
  578.  
  579. static int
  580. ObjCObject_sq_ass_slice (ObjCObject *self, int ilow, int ihigh, PyObject *v)
  581. {
  582.   PyErr_SetString (PyExc_SystemError, "ObjCObject_sq_ass_slice not implemented yet");
  583.   return -1;
  584. }
  585.  
  586. static PySequenceMethods ObjCObject_as_sequence =
  587. {
  588.   (inquiry) ObjCObject_sq_length,
  589.   (binaryfunc) ObjCObject_sq_concat,
  590.   (intargfunc) ObjCObject_sq_repeat,
  591.   (intargfunc) ObjCObject_sq_item,
  592.   (intintargfunc) ObjCObject_sq_slice,
  593.   (intobjargproc) ObjCObject_sq_ass_item,
  594.   (intintobjargproc) ObjCObject_sq_ass_slice
  595. };
  596.  
  597. static PyObject *
  598. ObjCSequenceObject_append (ObjCObject *self, PyObject *args)
  599. {
  600.   PyErr_SetString (PyExc_SystemError, "ObjCSequenceObject_append not implemented yet");
  601.   return NULL;
  602. }
  603.  
  604. static PyObject *
  605. ObjCSequenceObject_index (ObjCObject *self, PyObject *args)
  606. {
  607.   PyErr_SetString (PyExc_SystemError, "ObjCSequenceObject_index not implemented yet");
  608.   return NULL;
  609. }
  610.  
  611. static PyObject *
  612. ObjCSequenceObject_insert (ObjCObject *self, PyObject *args)
  613. {
  614.   PyErr_SetString (PyExc_SystemError, "ObjCSequenceObject_insert not implemented yet");
  615.   return NULL;
  616. }
  617.  
  618. static PyObject *
  619. ObjCSequenceObject_sort (ObjCObject *self, PyObject *args)
  620. {
  621.   PyErr_SetString (PyExc_SystemError, "ObjCSequenceObject_sort not implemented yet");
  622.   return NULL;
  623. }
  624.  
  625. static PyObject *
  626. ObjCSequenceObject_remove (ObjCObject *self, PyObject *args)
  627. {
  628.   PyErr_SetString (PyExc_SystemError, "ObjCSequenceObject_remove not implemented yet");
  629.   return NULL;
  630. }
  631.  
  632. static PyObject *
  633. ObjCSequenceObject_reverse (ObjCObject *self, PyObject *args)
  634. {
  635.   PyErr_SetString (PyExc_SystemError, "ObjCSequenceObject_reverse not implemented yet");
  636.   return NULL;
  637. }
  638.  
  639. static PyMethodDef ObjCSequenceObject_methods[] =
  640. {
  641.   { "append",    (PyCFunction) ObjCSequenceObject_append,    METH_VARARGS,    NULL },
  642.   // { "count",    (PyCFunction) ObjCSequenceObject_count,        METH_VARARGS,    NULL },
  643.   { "index",    (PyCFunction) ObjCSequenceObject_index,        METH_VARARGS,    NULL },
  644.   { "insert",    (PyCFunction) ObjCSequenceObject_insert,    METH_VARARGS,    NULL },
  645.   { "sort",    (PyCFunction) ObjCSequenceObject_sort,        METH_VARARGS,    NULL },
  646.   { "remove",    (PyCFunction) ObjCSequenceObject_remove,    METH_VARARGS,    NULL },
  647.   { "reverse",    (PyCFunction) ObjCSequenceObject_reverse,    METH_VARARGS,    NULL },
  648.   { 0, 0, 0, 0 }
  649. };
  650.  
  651. // MAPPING
  652.  
  653. #ifndef WITH_FOUNDATION
  654. #import <objc/HashTable.h>    // for valueForKey:
  655. #else
  656. #include <Foundation/NSDictionary.h> // for objectForKey:
  657. #endif
  658.  
  659. static PyObject *
  660. ObjCObject_mp_subscript (ObjCObject *self, PyObject *key)
  661. {
  662.   id value;
  663.   
  664.   if (ObjCObject_Check (key))
  665.     value = PERFORM1(self->oc_object, valueForKey:, objectForKey:,
  666.              ((ObjCObject *) key)->oc_object);
  667.   else
  668.     {
  669.       id ockey = [OC_PythonObject newWithObject:key];
  670.   
  671.       value = PERFORM1(self->oc_object, valueForKey:, objectForKey:, ockey);
  672.  
  673. #ifndef WITH_FOUNDATION
  674.       [ockey free];
  675. #endif
  676.     }             
  677.   
  678.   if (!value)
  679.     {
  680.       PyErr_SetObject (PyExc_KeyError, key);
  681.       return NULL;
  682.     }
  683.   
  684.   RETURN_WRAP(value);
  685. }
  686.  
  687. static PyObject *
  688. ObjCObject_mp_ass_subscript (ObjCObject *self, PyObject *key, PyObject *value)
  689. {
  690.   PyErr_SetString (PyExc_SystemError, "ObjCObject_mp_ass_subscript not implemented yet");
  691.   return NULL;
  692. }
  693.  
  694. static PyMappingMethods ObjCObject_as_mapping =
  695. {
  696.   (inquiry) ObjCObject_sq_length,
  697.   (binaryfunc) ObjCObject_mp_subscript,
  698.   (objobjargproc) ObjCObject_mp_ass_subscript
  699. };
  700.  
  701. static PyObject *
  702. ObjCMappingObject_has_key (ObjCObject *self, PyObject *key)
  703. {
  704.   PyErr_SetString (PyExc_SystemError, "ObjCMappingObject_has_key not implemented yet");
  705.   return NULL;
  706. }
  707.  
  708. static PyObject *
  709. ObjCMappingObject_items (ObjCObject *self, PyObject *args)
  710. {
  711.   PyErr_SetString (PyExc_SystemError, "ObjCMappingObject_items not implemented yet");
  712.   return NULL;
  713. }
  714.  
  715. static PyObject *
  716. ObjCMappingObject_keys (ObjCObject *self, PyObject *args)
  717. {
  718.   PyErr_SetString (PyExc_SystemError, "ObjCMappingObject_keys not implemented yet");
  719.   return NULL;
  720. }
  721.  
  722. static PyObject *
  723. ObjCMappingObject_values (ObjCObject *self, PyObject *args)
  724. {
  725.   PyErr_SetString (PyExc_SystemError, "ObjCMappingObject_values not implemented yet");
  726.   return NULL;
  727. }
  728.  
  729. static PyMethodDef ObjCMappingObject_methods[] =
  730. {
  731.   { "has_key",        (PyCFunction) ObjCMappingObject_has_key,    METH_VARARGS,    NULL },
  732.   { "items",        (PyCFunction) ObjCMappingObject_items,        METH_VARARGS,    NULL },
  733.   { "keys",        (PyCFunction) ObjCMappingObject_keys,        METH_VARARGS,    NULL },
  734.   { "values",        (PyCFunction) ObjCMappingObject_values,        METH_VARARGS,    NULL },  
  735.   { 0, 0, 0, 0 }
  736. };
  737.  
  738. static long
  739. ObjCObject_hash (ObjCObject *self)
  740. {
  741.   return [(ROOT_OBJECT *) self->oc_object hash];
  742. }
  743.  
  744. PyTypeObject ObjCObject_Type =
  745. {
  746.   PyObject_HEAD_INIT (&PyType_Type)
  747.   0,                          /*ob_size*/
  748.   "ObjCObject",                      /*tp_name*/
  749.   sizeof (ObjCObject),                  /*tp_basicsize*/
  750.   0,                          /*tp_itemsize*/
  751.   
  752.   /* methods */
  753.   (destructor) ObjCObject_dealloc,          /*tp_dealloc*/
  754.   (printfunc) 0,                  /*tp_print*/
  755.   (getattrfunc) ObjCObject_getattr,          /*tp_getattr*/
  756.   (setattrfunc) 0,                  /*tp_setattr*/
  757.   (cmpfunc) 0,                      /*tp_compare*/
  758.   (reprfunc) ObjCObject_repr,              /*tp_repr*/
  759.   0,                          /*tp_as_number*/
  760.   0,                          /*tp_as_sequence*/
  761.   0,                          /*tp_as_mapping*/
  762.   (hashfunc) ObjCObject_hash,              /*tp_hash*/
  763.   (ternaryfunc) ObjCObject_call,          /*tp_call*/
  764.   (reprfunc) 0,                      /*tp_str*/
  765.   (getattrofunc) 0,                  /*tp_getattro*/
  766.   (setattrofunc) 0,                  /*tp_setattro*/
  767.  
  768.   /* Space for future expansion */
  769.   0L,0L,
  770.   
  771.   "Wrapper around Objective-C id"          /* Documentation string */
  772. };
  773.  
  774. PyTypeObject ObjCSequenceObject_Type =
  775. {
  776.   PyObject_HEAD_INIT (&PyType_Type)
  777.   0,                          /*ob_size*/
  778.   "ObjCSequenceObject",                  /*tp_name*/
  779.   sizeof (ObjCObject),                  /*tp_basicsize*/
  780.   0,                          /*tp_itemsize*/
  781.   
  782.   /* methods */
  783.   (destructor) ObjCObject_dealloc,          /*tp_dealloc*/
  784.   (printfunc) 0,                  /*tp_print*/
  785.   (getattrfunc) ObjCObject_getattr,          /*tp_getattr*/
  786.   (setattrfunc) 0,                  /*tp_setattr*/
  787.   (cmpfunc) 0,                      /*tp_compare*/
  788.   (reprfunc) ObjCObject_repr,              /*tp_repr*/
  789.   0,                          /*tp_as_number*/
  790.   &ObjCObject_as_sequence,                  /*tp_as_sequence*/
  791.   0,                          /*tp_as_mapping*/
  792.   (hashfunc) ObjCObject_hash,              /*tp_hash*/
  793.   (ternaryfunc) ObjCObject_call,          /*tp_call*/
  794.   (reprfunc) 0,                      /*tp_str*/
  795.   (getattrofunc) 0,                  /*tp_getattro*/
  796.   (setattrofunc) 0,                  /*tp_setattro*/
  797.  
  798.   /* Space for future expansion */
  799.   0L,0L,
  800.   
  801.   "Wrapper around Objective-C id"          /* Documentation string */
  802. };
  803.  
  804. PyTypeObject ObjCMappingObject_Type =
  805. {
  806.   PyObject_HEAD_INIT (&PyType_Type)
  807.   0,                          /*ob_size*/
  808.   "ObjCMappingObject",                  /*tp_name*/
  809.   sizeof (ObjCObject),                  /*tp_basicsize*/
  810.   0,                          /*tp_itemsize*/
  811.   
  812.   /* methods */
  813.   (destructor) ObjCObject_dealloc,          /*tp_dealloc*/
  814.   (printfunc) 0,                  /*tp_print*/
  815.   (getattrfunc) ObjCObject_getattr,          /*tp_getattr*/
  816.   (setattrfunc) 0,                  /*tp_setattr*/
  817.   (cmpfunc) 0,                      /*tp_compare*/
  818.   (reprfunc) ObjCObject_repr,              /*tp_repr*/
  819.   0,                          /*tp_as_number*/
  820.   0,                          /*tp_as_sequence*/
  821.   &ObjCObject_as_mapping,              /*tp_as_mapping*/
  822.   (hashfunc) ObjCObject_hash,              /*tp_hash*/
  823.   (ternaryfunc) ObjCObject_call,          /*tp_call*/
  824.   (reprfunc) 0,                      /*tp_str*/
  825.   (getattrofunc) 0,                  /*tp_getattro*/
  826.   (setattrofunc) 0,                  /*tp_setattro*/
  827.  
  828.   /* Space for future expansion */
  829.   0L,0L,
  830.   
  831.   "Wrapper around Objective-C id"          /* Documentation string */
  832. };
  833.  
  834.  
  835. /*
  836. ** Local Variables:
  837. ** change-log-default-name:"../ChangeLog.PyObjC"
  838. ** End:
  839. */
  840.