[Pyobjc-dev] Re: [Pyobjc-checkins] CVS: pyobjc/Modules/objc OC_PythonString.[hm]
Brought to you by:
ronaldoussoren
From: Bill B. <bb...@co...> - 2003-02-15 23:02:19
|
Oops. I really didn't mean to check these in. Instead of undoing it, I'll leave it for now as this code is *not* used currently. They actually work -- all unit tests pass -- but do not work in that they do not handle unicode correctly. I believe this is the direction we should move in when bridging strings from Python into ObjC -- it can be made fast and it will often avoid copying the python buffers. There are very likely reference counting issues. I'm not sure. If we don't use this stuff, OC_PythonString.[hm] should be removed entirely from the project. b.bum On Saturday, Feb 15, 2003, at 17:56 US/Eastern, Bill Bumgarner wrote: > Update of /cvsroot/pyobjc/pyobjc/Modules/objc > In directory sc8-pr-cvs1:/tmp/cvs-serv16696/Modules/objc > > Modified Files: > OC_PythonString.h OC_PythonString.m pyobjc.h > Log Message: > Fixed autoreleasepool silliness. > > Index: OC_PythonString.h > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/OC_PythonString.h,v > retrieving revision 1.3 > retrieving revision 1.4 > diff -C2 -d -r1.3 -r1.4 > *** OC_PythonString.h 18 Oct 2002 10:03:14 -0000 1.3 > --- OC_PythonString.h 15 Feb 2003 22:56:33 -0000 1.4 > *************** > *** 1,44 **** > ! /* Copyright (c) 1996,97 by Lele Gaifax. All Rights Reserved > ! * > ! * This software may be used and distributed freely for any purpose > ! * provided that this notice is included unchanged on any and all > ! * copies. The author does not warrant or guarantee this software in > ! * any way. > ! * > ! * This file is part of the PyObjC package. > ! * > ! * RCSfile: OC_PythonString.h,v > ! * Revision: 1.8 > ! * Date: 1998/01/04 17:59:21 > ! * > ! * Created Thu Sep 5 19:46:45 1996. > ! */ > > ! #ifndef _OC_PythonString_H > ! #define _OC_PythonString_H > > ! #include "OC_PythonObject.h" > > ! /*#C This class wraps a PyString object, making it easier to handle > this > ! kind of objects from Objective-C. */ > ! @interface OC_PythonString : OC_PythonObject > { > } > > ! /*#M Returns a new autoreleased PyString object with @var{str} of > ! length @var{size} as contents. */ > ! + (id <PythonObject>) fromString:(char *) str andSize:(int) size; > ! > ! //#M Returns a new autoreleased PyString object with @var{str} as > contents. > ! + (id <PythonObject>) fromString:(char *) str; > ! > ! //#M Returns the size of the string. > ! - (int) size; > ! > ! //#M Returns the ``C'' equivalent. > ! - (char *) asString; > ! > ! @end /* OC_PythonString class interface */ > ! > ! > ! #endif /* _OC_PythonString_H */ > --- 1,29 ---- > ! #ifndef OC_PythonString_h > ! #define OC_PythonString_h > > ! #import <CoreFoundation/CoreFoundation.h> > ! #import <Foundation/NSString.h> > ! #include "Python.h" > > ! /* > ! * OC_PythonString - Objective-C proxy class for Python strings > ! * > ! * Instances of this class are used as proxies for Python strings > ! * when these are passed to Objective-C code. Because this class is > ! * a subclass of NSString Python sequences can be used everywhere > ! * where NSString is used. Python strings are immutable. > ! */ > > ! @interface OC_PythonString:NSString > { > + PyObject* value; > + PyObject* _internalRep; > + CFStringRef stringValue; > } > > ! +newWithPythonObject:(PyObject*)value; > ! -initWithPythonObject:(PyObject*)value; > ! -(void)dealloc; > ! -(PyObject*)__pyobjc_PythonObject__; > ! @end > ! #endif > > Index: OC_PythonString.m > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/OC_PythonString.m,v > retrieving revision 1.4 > retrieving revision 1.5 > diff -C2 -d -r1.4 -r1.5 > *** OC_PythonString.m 5 Feb 2003 21:08:51 -0000 1.4 > --- OC_PythonString.m 15 Feb 2003 22:56:33 -0000 1.5 > *************** > *** 1,49 **** > - /* Copyright (c) 1996,97 by Lele Gaifax. All Rights Reserved > - * > - * This software may be used and distributed freely for any purpose > - * provided that this notice is included unchanged on any and all > - * copies. The author does not warrant or guarantee this software in > - * any way. > - * > - * This file is part of the PyObjC package. > - * > - * RCSfile: OC_PythonString.m,v > - * Revision: 1.9 > - * Date: 1998/01/04 17:59:22 > - * > - * Created Thu Sep 5 19:49:36 1996. > - */ > - > #include "OC_PythonString.h" > > @implementation OC_PythonString > > ! + (id <PythonObject>) fromString:(char *) str andSize:(int) size > { > ! PyObject *pystr = PyString_FromStringAndSize (str, size); > ! id <PythonObject> result = [self newWithObject:pystr]; > > ! Py_DECREF(pystr); > ! return result; > } > > ! + (id <PythonObject>) fromString:(char *) str > { > ! PyObject *pystr = PyString_FromString(str); > ! id <PythonObject> result = [self newWithObject:pystr]; > ! > ! Py_DECREF(pystr); > ! return result; > } > > ! - (int) size > { > ! return PyString_Size([self pyObject]); > } > > ! - (char *) asString > { > ! return PyString_AsString([self pyObject]); > } > > ! @end /* OC_PythonString class implementation */ > --- 1,84 ---- > #include "OC_PythonString.h" > + #include "pyobjc.h" > + #include "objc_support.h" > > @implementation OC_PythonString > + +newWithPythonObject:(PyObject*)v; > + { > + OC_PythonString* res = [[OC_PythonString alloc] > initWithPythonObject:v]; > + [res autorelease]; > + return res; > + } > > ! -initWithPythonObject:(PyObject*)v; > { > ! value = v; > > ! if (PyString_Check(value)) { > ! char *buffer; > ! int length; > ! int result; > ! > ! result = PyString_AsStringAndSize(value, &buffer, &length); > ! if(result == -1) { > ! ObjCErr_ToObjC(); > ! [self release]; > ! return nil; // not reached > ! } > ! stringValue = CFStringCreateWithCStringNoCopy(NULL, > ! buffer, > ! kCFStringEncodingUTF8, > ! kCFAllocatorNull); > ! _internalRep = NULL; > ! } else if (PyUnicode_Check(value)) { > ! char *buffer; > ! int length; > ! int result; > ! #warning Is there a way to determine what the encoding of value is > and instantiate a CFString directly? > ! _internalRep = PyUnicode_AsUTF8String(value); > ! result = PyString_AsStringAndSize(_internalRep, &buffer, &length); > ! if(result == -1) { > ! ObjCErr_ToObjC(); > ! [self release]; > ! return nil; > ! } > ! > ! stringValue = CFStringCreateWithCStringNoCopy(NULL, > ! buffer, > ! kCFStringEncodingUTF8, > ! kCFAllocatorNull); > ! } > ! > ! Py_INCREF(value); > ! > ! return self; > } > > ! -(PyObject*)__pyobjc_PythonObject__ > { > ! Py_INCREF(value); > ! return value; > } > > ! -(void)dealloc > { > ! CFRelease(stringValue); > ! Py_XDECREF(value); > ! Py_XDECREF(_internalRep); > ! [super dealloc]; > } > > ! - (unsigned int)length; > { > ! int result; > ! result = CFStringGetLength(stringValue); > ! return result; > } > > ! - (unichar)characterAtIndex:(unsigned)index; > ! { > ! UniChar result; > ! result = CFStringGetCharacterAtIndex(stringValue, index); > ! return result; > ! } > ! @end > > Index: pyobjc.h > =================================================================== > RCS file: /cvsroot/pyobjc/pyobjc/Modules/objc/pyobjc.h,v > retrieving revision 1.20 > retrieving revision 1.21 > diff -C2 -d -r1.20 -r1.21 > *** pyobjc.h 8 Feb 2003 21:41:22 -0000 1.20 > --- pyobjc.h 15 Feb 2003 22:56:33 -0000 1.21 > *************** > *** 13,16 **** > --- 13,17 ---- > #include "OC_PythonArray.h" > #include "OC_PythonDictionary.h" > + #include "OC_PythonString.h" > #include "super-call.h" > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > pyobjc-checkins mailing list > pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-checkins > b.bum In cyberspace, no one can hear you laugh. |