[Zope-Perl] Perl Internal Methods -- accessing PARENTS?
Gisle Aas
gisle@ActiveState.com
08 Aug 2000 20:58:29 +0200
Joseph Wayne Norton <norton@alum.mit.edu> writes:
> a. I can't seem to use the GetItem interface when passing either
> ($i) or (0 + $i). The following error is given:
>
> # The following does not work.
> # Error Type: TypeError
> # Error Value: sequence index must be integer
This patch to Python-Object/Object.xs force the key to always be
passed an integer for sequence objects. This should fix your problem
(I hope).
Regards,
Gisle
Index: Object.xs
===================================================================
RCS file: /home/cvs/activestate/bifrost/Python-Object/Object.xs,v
retrieving revision 1.23
diff -u -p -u -r1.23 Object.xs
--- Object.xs 2000/08/06 20:30:14 1.23
+++ Object.xs 2000/08/08 18:52:30
@@ -426,11 +426,20 @@ PyObject_GetItem(o, key)
CODE:
ASSERT_LOCK_PERL;
ENTER_PYTHON;
- PERL_LOCK;
- py_key = sv2pyo(key);
- PERL_UNLOCK;
- RETVAL = PyObject_GetItem(o, py_key);
- Py_DECREF(py_key);
+ if (PySequence_Check(o)) {
+ int index;
+ ENTER_PERL;
+ index = SvIV(key);
+ ENTER_PYTHON;
+ RETVAL = PySequence_GetItem(o, index);
+ }
+ else {
+ PERL_LOCK;
+ py_key = sv2pyo(key);
+ PERL_UNLOCK;
+ RETVAL = PyObject_GetItem(o, py_key);
+ Py_DECREF(py_key);
+ }
if (!RETVAL)
croak_on_py_exception();
OUTPUT:
@@ -448,11 +457,22 @@ PyObject_SetItem(o, key, v)
ASSERT_LOCK_PERL;
ENTER_PYTHON;
PERL_LOCK;
- py_key = sv2pyo(key);
py_v = sv2pyo(v);
PERL_UNLOCK;
- RETVAL = PyObject_SetItem(o, py_key, py_v);
- Py_DECREF(py_key);
+ if (PySequence_Check(o)) {
+ int index;
+ ENTER_PERL;
+ index = SvIV(key);
+ ENTER_PYTHON;
+ RETVAL = PySequence_SetItem(o, index, py_v);
+ }
+ else {
+ PERL_LOCK;
+ py_key = sv2pyo(key);
+ PERL_UNLOCK;
+ RETVAL = PyObject_SetItem(o, py_key, py_v);
+ Py_DECREF(py_key);
+ }
Py_DECREF(py_v);
if (RETVAL == -1)
croak_on_py_exception();
@@ -469,11 +489,20 @@ PyObject_DelItem(o, key)
CODE:
ASSERT_LOCK_PERL;
ENTER_PYTHON;
- PERL_LOCK;
- py_key = sv2pyo(key);
- PERL_UNLOCK;
- RETVAL = PyObject_DelItem(o, py_key);
- Py_DECREF(py_key);
+ if (PySequence_Check(o)) {
+ int index;
+ ENTER_PERL;
+ index = SvIV(key);
+ ENTER_PYTHON;
+ RETVAL = PySequence_DelItem(o, index);
+ }
+ else {
+ PERL_LOCK;
+ py_key = sv2pyo(key);
+ PERL_UNLOCK;
+ RETVAL = PyObject_DelItem(o, py_key);
+ Py_DECREF(py_key);
+ }
if (RETVAL == -1)
croak_on_py_exception();
ENTER_PERL;