[PyObjC-svn] r2409 - in trunk/pyobjc/pyobjc-core: Lib/PyObjCTools Lib/objc Modules/objc PyObjCTest
[email protected] Sun, 28 Feb 2010 15:14:23 -0600
| Newsgroups | gmane.comp.python.pyobjc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: ronaldoussoren
Date: Sun Feb 28 15:14:22 2010
New Revision: 2409
Log:
* Improve py3k port
* Don't use Carbon.CF compatibility code, Carbon.CF is not very
useful anyway and keeping this code working is too much of
a hassle.
* Improve test coverage for objc.object_property
Modified:
trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py
trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py
trunk/pyobjc/pyobjc-core/Lib/objc/_properties.py
trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
trunk/pyobjc/pyobjc-core/Modules/objc/method-signature.m
trunk/pyobjc/pyobjc-core/Modules/objc/module.m
trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m
trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m
trunk/pyobjc/pyobjc-core/Modules/objc/parsexml.m
trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc-compat.h
trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h
trunk/pyobjc/pyobjc-core/Modules/objc/toll-free-bridging.m
trunk/pyobjc/pyobjc-core/PyObjCTest/test_metadata.py
Modified: trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py (original)
+++ trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py Sun Feb 28 15:14:22 2010
@@ -403,7 +403,7 @@
offset = 0
info = method.__metadata__()
type = info['arguments'][argno+offset]['type']
- if type != '^?':
+ if type != b'^?':
self.fail(message or "arg %d of %s is not of type function_pointer"%(
argno, method))
Modified: trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py (original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py Sun Feb 28 15:14:22 2010
@@ -582,6 +582,7 @@
CLASS_METHODS['NSNull'] = (
('__nonzero__', lambda self: False ),
+ ('__bool__', lambda self: False ),
)
NSDecimalNumber = lookUpClass('NSDecimalNumber')
@@ -667,14 +668,15 @@
result.symmetric_difference_update(other)
return result
- def __len__(self):
- return len(self.__value)
class nsdict_keys(nsdict_view):
__slots__=('__value')
def __init__(self, value):
self.__value = value
+ def __len__(self):
+ return len(self.__value)
+
def __iter__(self):
return iter(self.__value)
@@ -686,8 +688,11 @@
def __init__(self, value):
self.__value = value
+ def __len__(self):
+ return len(self.__value)
+
def __iter__(self):
- return iter(self.objectEnumerator())
+ return iter(self.__value.objectEnumerator())
def __contains__(self, value):
for v in iter(self):
@@ -700,6 +705,9 @@
def __init__(self, value):
self.__value = value
+ def __len__(self):
+ return len(self.__value)
+
def __iter__(self):
for k in self.__value:
yield (k, self.__value[k])
Modified: trunk/pyobjc/pyobjc-core/Lib/objc/_properties.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/_properties.py (original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/_properties.py Sun Feb 28 15:14:22 2010
@@ -53,7 +53,10 @@
self._getter = None
self._setter = None
self._validate = None
- self._depends_on = list(depends_on)
+ if depends_on is None:
+ self._depends_on = ()
+ else:
+ self._depends_on = list(depends_on)
self.__getprop = None
self.__setprop = None
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m Sun Feb 28 15:14:22 2010
@@ -1867,7 +1867,7 @@
if (stubUserdata->argCount == Py_SIZE(methinfo) && !haveVarArgs && !haveVarKwds) {
/* OK */
- } else if ((stubUserdata->argCount <= 1) && haveVarArgs && haveVarKwds) {
+ } else if ((stubUserdata->argCount <= 1) && (haveVarArgs || haveVarKwds)) {
/* OK:
* def m(self, *args, **kwds), or
* def m(*args, **kwds)
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/method-signature.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/method-signature.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/method-signature.m Sun Feb 28 15:14:22 2010
@@ -295,15 +295,12 @@
if (descr->sel_type == NULL) {
return -1;
}
- }
-#if PY_MAJOR_VERSION == 2
- else if (PyString_Check(d)) {
- descr->sel_type = PyObjCUtil_Strdup(PyString_AsString(d));
+ } else if (PyBytes_Check(d)) {
+ descr->sel_type = PyObjCUtil_Strdup(PyBytes_AsString(d));
if (descr->sel_type == NULL) {
return -1;
}
}
-#endif
}
}
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/module.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/module.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/module.m Sun Feb 28 15:14:22 2010
@@ -331,7 +331,7 @@
name = PyObject_GetAttrString(aMethod, "__name__");
-#if PY_MAJOR_VERSION == 2
+#if PY_MAJOR_VERSION == 3
if (PyBytes_Check(name)) {
PyObject* t = PyUnicode_Decode(
PyBytes_AsString(name),
@@ -2142,6 +2142,18 @@
global_release_pool = [[NSAutoreleasePool alloc] init];
[OC_NSAutoreleasePoolCollector newAutoreleasePool];
+#ifndef Py_ARG_BYTES
+#error "No Py_ARG_BYTES"
+#endif
+
+#ifndef Py_ARG_NSInteger
+#error "No Py_ARG_NSInteger"
+#endif
+
+#ifndef Py_ARG_NSUInteger
+#error "No Py_ARG_NSUInteger"
+#endif
+
#if PY_MAJOR_VERSION == 3
return m;
#endif
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m Sun Feb 28 15:14:22 2010
@@ -92,7 +92,7 @@
nsmutabledata_getbuffer(PyObject* obj, Py_buffer* view, int flags)
{
NSMutableData *self = (NSMutableData *)PyObjCObject_GetObject(obj);
- if (flags & PyBUF_WRITABLE) {
+ if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
return PyBuffer_FillInfo(view, obj, (void*)[self mutableBytes], [self length], 0, flags);
} else {
return PyBuffer_FillInfo(view, obj, (void*)[self bytes], [self length], 1, flags);
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m Sun Feb 28 15:14:22 2010
@@ -117,8 +117,8 @@
* Don't call 'description' for uninitialized objects, that
* is undefined behaviour and will crash the interpreter sometimes.
*/
- //res = PyObject_CallMethod((PyObject*)self, "description", NULL);
- res = NULL;
+ res = PyObject_CallMethod((PyObject*)self, "description", NULL);
+ //res = NULL;
if (res == NULL) {
PyErr_Clear();
} else {
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/parsexml.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/parsexml.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/parsexml.m Sun Feb 28 15:14:22 2010
@@ -651,23 +651,14 @@
{
char* name = attribute_string(cur_node, "name", NULL);
char* value = attribute_string(cur_node, "value", "value64");
+ BOOL nsstring = attribute_bool(cur_node, "nsstring", NULL, NO);
if (name != NULL && value != NULL && *value != '\0') {
- size_t i, len = strlen(value);
-
- PyObject* v = NULL;
- for (i = 0; i < len; i++) {
- if (((unsigned char)value[i]) > 127) {
- v = PyUnicode_DecodeUTF8(value, len, "strict");
- if (v == NULL) {
- if (name) xmlFree(name);
- if (value) xmlFree(value);
- return -1;
- }
- break;
- }
- }
- if (v == NULL) {
+ size_t len = strlen(value);
+ PyObject* v;
+ if (nsstring) {
+ v = PyUnicode_DecodeUTF8(value, len, "strict");
+ } else {
v = PyBytes_InternFromStringAndSize(value, len);
}
if (v == NULL) {
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc-compat.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc-compat.h (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc-compat.h Sun Feb 28 15:14:22 2010
@@ -108,7 +108,7 @@
#endif
-#if PY_VERSION_HEX < 0x03000000
+#if PY_MAJOR_VERSION == 2
#ifndef Py_ARG_BYTES
#define Py_ARG_BYTES "s"
@@ -124,10 +124,10 @@
#if __LP64__
#define Py_ARG_NSInteger "l"
-#define Py_ARG_NSUInteger "L"
+#define Py_ARG_NSUInteger "k"
#else
#define Py_ARG_NSInteger "i"
-#define Py_ARG_NSUInteger "L"
+#define Py_ARG_NSUInteger "I"
#endif
#if PY_MAJOR_VERSION == 2
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h Sun Feb 28 15:14:22 2010
@@ -9,13 +9,22 @@
// Loading in AppKit on Mac OS X 10.3 results in
// a bit less than 1500 classes.
-#define PYOBJC_EXPECTED_CLASS_COUNT 2048
+#define PYOBJC_EXPECTED_CLASS_COUNT 3000
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "structmember.h"
#include "pyobjc-compat.h"
+/* PyObjC_DEBUG: If defined the bridge will perform more internal checks */
+#ifdef Py_DEBUG
+ /* Enable when Python is compiled with internal checks enabled */
+# define PyObjC_DEBUG
+#endif
+
+/* PyObjC_ERROR_ABORT: If defined an internal error will result in an abort() */
+#define PyObjC_ERROR_ABORT 1
+
#include <objc/objc-runtime.h>
#include <objc/objc.h>
@@ -23,6 +32,8 @@
// how do we make this dependent on sizeof(unichar)??
#if Py_UNICODE_SIZE == 2
#define PyObjC_UNICODE_FAST_PATH
+#else
+#error "Py_UNICODE_SIZE != 2 is not supported"
#endif
#include "objc-runtime-compat.h"
@@ -136,18 +147,39 @@
-//#ifdef Py_DEBUG
-#if 1
+#ifdef PyObjC_DEBUG
+
+#ifdef PyObjCErr_InternalError
+#define _PyObjC_InternalError_Bailout() abort()
+#else
+#define _PyObjC_InternalError_Bailout() ((void)0)
+#endif
#define PyObjCErr_InternalError() \
+ do { \
PyErr_Format(PyObjCExc_InternalError, \
"PyObjC: internal error in %s at %s:%d", \
- __FUNCTION__, __FILE__, __LINE__)
+ __FUNCTION__, __FILE__, __LINE__); \
+ _PyObjC_InternalError_Bailout(); \
+ } while (0)
+
+#define PyObjCErr_InternalErrorMesg(msg) \
+ do { \
+ PyErr_Format(PyObjCExc_InternalError, \
+ "PyObjC: internal error in %s at %s:%d: %s", \
+ __FUNCTION__, __FILE__, __LINE__, msg) \
+ _PyObjC_InternalError_Bailout(); \
+ } while (0)
+
#define PyObjC_Assert(expr, retval) \
- if (!(expr)) { PyObjCErr_InternalError(); return (retval); }
+ if (!(expr)) { PyObjCErr_InternalErrorMesg(\
+ "assertion failed: " #expr); return (retval); }
#else
+#define PyObjCErr_InternalError() ((void)0)
+#define PyObjCErr_InternalErrorMesg(mesg) ((void)0)
+
#define PyObjC_Assert(expr, retval) ((void)0)
#endif
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/toll-free-bridging.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/toll-free-bridging.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/toll-free-bridging.m Sun Feb 28 15:14:22 2010
@@ -10,7 +10,7 @@
#import <Foundation/NSURL.h>
-#if !defined(__OBJC2__) && (PY_VERSION_HEX < 0x02050000)
+#if 0 && !defined(__OBJC2__) && (PY_MAJOR_VERSION == 2)
#include "pymactoolbox.h"
#endif
@@ -51,7 +51,7 @@
PyObjC_IDToCFType(id argument __attribute__((__unused__)))
{
-#if !defined(__OBJC2__) && (PY_MAJOR_VERSION == 2)
+#if 0 && !defined(__OBJC2__) && (PY_MAJOR_VERSION == 2)
CFTypeRef typeRef = (CFTypeRef)argument;
CFTypeID typeID = CFGetTypeID(argument);
Modified: trunk/pyobjc/pyobjc-core/PyObjCTest/test_metadata.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/PyObjCTest/test_metadata.py (original)
+++ trunk/pyobjc/pyobjc-core/PyObjCTest/test_metadata.py Sun Feb 28 15:14:22 2010
@@ -1060,7 +1060,7 @@
if sys.version_info[0] == 2:
self.assertEquals(
[ ord(x)+1 for x in "hello\0world" ],
- [ ord(x) for x in v ])
+ [ x for x in v ])
else:
self.assertEquals(
[ x+1 for x in b"hello\0world" ],
@@ -1093,7 +1093,7 @@
if sys.version_info[0] == 2:
self.assertEquals(
[ ord(x)+2 for x in b"hello\0world" ],
- [ ord(x) for x in v ])
+ [ x for x in v ])
else:
self.assertEquals(
[ x+2 for x in b"hello\0world" ],
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev