Commits

Ronald Oussoren  committed 3619d77

Cleanup for pyobjc-compat.[hm] and pyobjc.h

* Reorder pyobjc-compat.h (simular definitions are located closer to
each other)

* Reorder pyobjc.h, not completely finished (the file should at the end
contain a number of configuration macros and includes, all other
definitions will be in appriopriate headers)

* Remove unused functionality from pyobjc-compat

* Remove Py_ARG_SIZE_T: not needed now that PyObjC requires Python 2.6

  • Participants
  • Parent commits b582f59

Comments (0)

Files changed (21)

File pyobjc-core/Modules/objc/OC_PythonArray.m

             }
         }
 
-        w = PyObject_CallMethod(value, "insert", Py_ARG_SIZE_T "O", theIndex, v);
+        w = PyObject_CallMethod(value, "insert", "nO", theIndex, v);
         Py_DECREF(v);
         if (unlikely(w == NULL)) {
             PyObjC_GIL_FORWARD_EXC();

File pyobjc-core/Modules/objc/helpers-foundation-nscoder.m

 
     struct objc_super super;
 
-    if  (!PyArg_ParseTuple(arguments, Py_ARG_BYTES"#"Py_ARG_SIZE_T, &bytes, &size, &length)) {
+    if  (!PyArg_ParseTuple(arguments, Py_ARG_BYTES"#n", &bytes, &size, &length)) {
         return NULL;
     }
 

File pyobjc-core/Modules/objc/helpers-foundation-nsdecimal.m

     Py_ssize_t digits = 0;
     NSDecimal  result;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|" Py_ARG_SIZE_T, keywords, &digits)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|n", keywords, &digits)) {
         return NULL;
     }
 

File pyobjc-core/Modules/objc/module.m

     static    char* keywords[] = { "length", 0 };
     Py_ssize_t length;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, Py_ARG_SIZE_T,
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "n",
                 keywords, &length)) {
         return NULL;
     }
     Py_ssize_t pack = -1;
 
     if (!PyArg_ParseTupleAndKeywords(args, kwds,
-                "s"Py_ARG_BYTES"O|z" Py_ARG_SIZE_T ,
+                "s"Py_ARG_BYTES"O|zn",
                 keywords,
                 &name, &typestr, &pyfieldnames, &docstr, &pack)) {
         return NULL;
     Py_ssize_t i;
 
     argIndex=-1;
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|" Py_ARG_SIZE_T ,
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|n",
         keywords, &callable, &closureFor, &argIndex)) {
         return NULL;
     }
 
 
 
-static PyObject*
-_clear_intern(PyObject* self __attribute__((__unused__)))
-{
-    PyObjC_ClearIntern();
-    Py_INCREF(Py_None);
-    return Py_None;
-}
-
-
 #if    PyObjC_BUILD_RELEASE >= 1006
     /* Associated Object support. Functionality is available on OSX 10.6 or later. */
 
     { "_typestr2typestr", (PyCFunction)typestr2typestr,
         METH_O, "private function" },
 
-    { "_clear_intern", (PyCFunction)_clear_intern, METH_NOARGS,  NULL },
-
 #if    PyObjC_BUILD_RELEASE >= 1006
 
     { "setAssociatedObject", (PyCFunction)PyObjC_setAssociatedObject,

File pyobjc-core/Modules/objc/pyobjc-compat.h

 #ifndef PyObjC_COMPAT_H
 #define PyObjC_COMPAT_H
 
-#import <Cocoa/Cocoa.h>
-#import <Foundation/NSObjCRuntime.h>
-
-
+/*
+ *
+ * Start of Cocoa definitions
+ *
+ *
+ * Ensure that CGFloat and NSInteger are always
+ * available, even when compiling with ancient SDKs.
+ *
+ * Also ensure that MAC_OS_X_VERSION_... macros are available
+ * for all existing OSX versions.
+ */
 #ifndef CGFLOAT_DEFINED
 
 #ifdef __LP64__
 
 #endif /* CGFLOAT_DEFINED */
 
-
-#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 3
-
-/*
- * A micro optimization: when using Python 3.3 or later it
- * is possible to access a 'char*' with an ASCII representation
- * of a unicode object without first converting it to a bytes
- * string (if the string can be encoded as ASCII in the first
- * place.
- *
- * This slightly reduces the object allocation rate during
- * attribute access.
- */
-
-#  define PyObjC_FAST_UNICODE_ASCII 1
-
-extern const char* PyObjC_Unicode_Fast_Bytes(PyObject* object);
-
-#endif
-
-
 #ifndef NSINTEGER_DEFINED
 
 #ifdef __LP64__
 
 #endif
 
-
-/*
- * Compatibilty definitions
- */
-
-#ifdef __GNUC__
-#define unlikely(x)    __builtin_expect (!!(x), 0)
-#define likely(x)    __builtin_expect (!!(x), 1)
-#else
-#define likely(x)    x
-#define likely(x)    x
-#endif
-
-#import <AvailabilityMacros.h>
 /* On 10.1 there are no defines for the OS version. */
 #ifndef MAC_OS_X_VERSION_10_1
 #define MAC_OS_X_VERSION_10_1 1010
 #define MAC_OS_X_VERSION_10_8 1080
 #endif
 
+#if PyObjC_BUILD_RELEASE <= 1005
 
-/* On some versions of GCC <limits.h> defines LONG_LONG_MAX but not LLONG_MAX,
- * compensate.
+/* On MacOS X, +signatureWithObjCTypes: is a method of NSMethodSignature,
+ * but that method is not present in the header files until Mac OS X 10.5.
+ *
+ * Add a definition of the method when compiling on ancient OSX releases
+ * to ensure that the code gets compiled without warnings.
  */
+@interface NSMethodSignature (WarningKiller)
+    +(instancetype)signatureWithObjCTypes:(const char*)types;
+    @end /* interface NSMethodSignature */
+
+#endif /* PyObjC_BUILD_RELEASE <= 1005 */
+
+/*
+ *
+ * End of Cocoa definitions
+ *
+ */
+
+
+/*
+ *
+ * Start of compiler support helpers
+ *
+ */
+
+#ifdef __GNUC__
+#define unlikely(x)  __builtin_expect (!!(x), 0)
+#define likely(x)    __builtin_expect (!!(x), 1)
+#else
+#define likely(x)    x
+#define likely(x)    x
+#endif
+
+
+
+#ifndef __has_feature
+#  define __has_feature(x) 0
+#endif
+
+#if !__has_feature(objc_instancetype)
+#  define instancetype id
+#endif
+
+/* On some versions of GCC <limits.h> defines LONG_LONG_MAX but not LLONG_MAX, compensate.  */
 #ifndef LLONG_MIN
 #ifdef LONG_LONG_MIN
 #define LLONG_MIN LONG_LONG_MIN
 #endif
 #endif
 
-#if (PY_VERSION_HEX < 0x02050000)
-typedef int Py_ssize_t;
-#define PY_FORMAT_SIZE_T ""
-#define Py_ARG_SIZE_T "i"
-#define PY_SSIZE_T_MAX INT_MAX
+/*
+ *
+ * End of compiler support helpers
+ *
+ */
 
-#else
-
-#ifndef Py_ARG_SIZE_T
-#define Py_ARG_SIZE_T "n"
-#endif
-
-
-#endif
-
-#if PY_MAJOR_VERSION == 2
-
-typedef long Py_hash_t;
-
-#ifndef Py_ARG_BYTES
-#define Py_ARG_BYTES "z"
-#endif
-
-/* Cast a PyObject* to the type expected by the 2.x C API.
- * This is a macro because the cast is not necessary for the 3.x C API)
- */
-#define UNICODE_CAST(item)  ((PyUnicodeObject*)(item))
-#define SLICE_CAST(item)       ((PySliceObject*)(item))
-
-#else
-
-#ifndef Py_ARG_BYTES
-#define Py_ARG_BYTES "y"
-#endif
-
-#define UNICODE_CAST(item)    (item)
-#define SLICE_CAST(item)    (item)
-
-#endif
 
 #if __LP64__
 #define Py_ARG_NSInteger "l"
 #define Py_ARG_NSUInteger "I"
 #endif
 
-#if PY_MAJOR_VERSION == 2
-#define Py_REFCNT(ob)           (((PyObject*)(ob))->ob_refcnt)
-#define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
-#define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
 
-
-/* Source-level backward compatibility: use PyCapsule API in sources, fall back to
- * PyCObject when needed.
+/*
+ *
+ * Python version compatibility
+ *
  */
-#if PY_MINOR_VERSION < 7
-#define PyCapsule_New(pointer, name, destructor) PyCObject_FromVoidPtr(pointer, destructor)
-#define PyCapsule_GetPointer(object, name) PyCObject_AsVoidPtr(object)
-#define PyCapsule_CheckExact(object)    PyCObject_Check(object)
-#endif
-
-#endif
 
 #if PY_MAJOR_VERSION == 2
 
-#define PyErr_Format PyObjCErr_Format
+    typedef long Py_hash_t;
 
-extern PyObject* PyObjCErr_Format(PyObject* exception, const char* format, ...);
+#   ifndef Py_ARG_BYTES
+#       define Py_ARG_BYTES "z"
+#   endif
 
-#define PyText_Check PyString_Check
-#define PyText_FromFormat PyString_FromFormat
-#define PyText_FromString PyString_FromString
-#define PyText_FromStringAndSize PyString_FromStringAndSize
-#define PyText_InternFromString PyString_InternFromString
-#define PyText_InternInPlace PyString_InternInPlace
-#define PyText_Append PyString_ConcatAndDel
-#define PyText_AsString    PyString_AsString
+    /* Cast a PyObject* to the type expected by the 2.x C API.
+     * This is a macro because the cast is not necessary for the 3.x C API)
+     */
+#   define UNICODE_CAST(item)  ((PyUnicodeObject*)(item))
+#   define SLICE_CAST(item)    ((PySliceObject*)(item))
 
-#ifndef PyBytes_FromString
-#define PyBytes_AsString    PyString_AsString
-#define PyBytes_Size        PyString_Size
-#define PyBytes_FromString    PyString_FromString
-#define PyBytes_FromStringAndSize    PyString_FromStringAndSize
-#define PyBytes_AS_STRING    PyString_AS_STRING
-#define PyBytes_GET_SIZE    PyString_GET_SIZE
-#endif
+#   define Py_REFCNT(ob)           (((PyObject*)(ob))->ob_refcnt)
+#   define Py_TYPE(ob)             (((PyObject*)(ob))->ob_type)
+#   define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
 
-#define PyBytes_InternFromString    PyString_InternFromString
-#define PyBytes_InternFromStringAndSize    PyObjCString_InternFromStringAndSize
 
-extern PyObject* PyObjCString_InternFromStringAndSize(const char* v, Py_ssize_t l);
+    /* Source-level backward compatibility: use PyCapsule API in sources, fall back to
+     * PyCObject when needed.
+     */
+#   if PY_MINOR_VERSION < 7
+#       define PyCapsule_New(pointer, name, destructor) PyCObject_FromVoidPtr(pointer, destructor)
+#       define PyCapsule_GetPointer(object, name) PyCObject_AsVoidPtr(object)
+#       define PyCapsule_CheckExact(object)    PyCObject_Check(object)
+#   endif /* Python < 2.7 */
 
-#else
+#   define PyErr_Format PyObjCErr_Format
 
-#define PyText_Check PyUnicode_Check
-#define PyText_FromFormat PyUnicode_FromFormat
-#define PyText_FromString PyUnicode_FromString
-#define PyText_FromStringAndSize PyUnicode_FromStringAndSize
-#define PyText_InternFromString PyUnicode_InternFromString
-#define PyText_InternInPlace PyUnicode_InternInPlace
-#define PyText_Append PyUnicode_Append
-#define PyText_AsString    _PyUnicode_AsString
+    extern PyObject* PyObjCErr_Format(PyObject* exception, const char* format, ...);
 
-#endif
+#   define PyText_Check PyString_Check
+#   define PyText_FromFormat PyString_FromFormat
+#   define PyText_FromString PyString_FromString
+#   define PyText_FromStringAndSize PyString_FromStringAndSize
+#   define PyText_InternFromString PyString_InternFromString
+#   define PyText_InternInPlace PyString_InternInPlace
+#   define PyText_Append PyString_ConcatAndDel
+#   define PyText_AsString    PyString_AsString
 
-#if PY_MAJOR_VERSION == 3
-#define PyInt_FromLong        PyLong_FromLong
-#define PyInt_FromString    PyLong_FromString
+#   ifndef PyBytes_FromString
+#       define PyBytes_AsString    PyString_AsString
+#       define PyBytes_Size        PyString_Size
+#       define PyBytes_FromString    PyString_FromString
+#       define PyBytes_FromStringAndSize    PyString_FromStringAndSize
+#       define PyBytes_AS_STRING    PyString_AS_STRING
+#       define PyBytes_GET_SIZE    PyString_GET_SIZE
+#   endif /* !PyBytes_FromString */
 
-extern int PyObject_Cmp (PyObject *o1, PyObject *o2, int *result);
-extern PyObject* PyBytes_InternFromString(const char* v);
-extern PyObject* PyBytes_InternFromStringAndSize(const char* v, Py_ssize_t l);
-#endif
+#   define PyBytes_InternFromString    PyString_InternFromString
+#   define PyBytes_InternFromStringAndSize    PyObjCString_InternFromStringAndSize
 
-extern void      PyObjC_ClearIntern(void);
-extern PyObject* PyObjC_InternValue(PyObject* orig);
-extern PyObject* PyObjC_IntFromString(char* v, char**pend, int base);
-extern PyObject* PyObjC_IntFromLong(long v);
+    extern PyObject* PyObjCString_InternFromStringAndSize(const char* v, Py_ssize_t l);
 
 
-#ifndef __has_feature
-#  define __has_feature(x) 0
-#endif
+# else /* Py_MAJOR_VERSION == 3 */
 
-#if !__has_feature(objc_instancetype)
-#  define instancetype id
-#endif
+#   ifndef Py_ARG_BYTES
+#       define Py_ARG_BYTES "y"
+#   endif
+
+#   define UNICODE_CAST(item) (item)
+#   define SLICE_CAST(item) (item)
+
+
+#   define PyText_Check PyUnicode_Check
+#   define PyText_FromFormat PyUnicode_FromFormat
+#   define PyText_FromString PyUnicode_FromString
+#   define PyText_FromStringAndSize PyUnicode_FromStringAndSize
+#   define PyText_InternFromString PyUnicode_InternFromString
+#   define PyText_InternInPlace PyUnicode_InternInPlace
+#   define PyText_Append PyUnicode_Append
+#   define PyText_AsString _PyUnicode_AsString
+
+#   define PyInt_FromLong PyLong_FromLong
+#   define PyInt_FromString PyLong_FromString
+
+    extern int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);
+    extern PyObject* PyBytes_InternFromString(const char* v);
+    extern PyObject* PyBytes_InternFromStringAndSize(const char* v, Py_ssize_t l);
+
+#   if PY_MINOR_VERSION >= 3
+
+        /*
+         * A micro optimization: when using Python 3.3 or later it
+         * is possible to access a 'char*' with an ASCII representation
+         * of a unicode object without first converting it to a bytes
+         * string (if the string can be encoded as ASCII in the first
+         * place.
+         *
+         * This slightly reduces the object allocation rate during
+         * attribute access.
+         */
+
+#       define PyObjC_FAST_UNICODE_ASCII 1
+
+        extern const char* PyObjC_Unicode_Fast_Bytes(PyObject* object);
+
+#   endif /* Python >= 3.3 */
+
+#endif /* PY_MAJOR_VERSION == 3 */
+
+
+
+
+#ifdef __clang__
+
+/* This is a crude hack to disable a otherwise useful warning in the context of
+ * PyTuple_SET_ITEM, without disabling it everywhere
+ */
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Warray-bounds"
+static inline void _PyObjCTuple_SetItem(PyObject* tuple, Py_ssize_t idx, PyObject* value)
+{
+    PyTuple_SET_ITEM(tuple, idx, value);
+}
+#undef PyTuple_SET_ITEM
+#define PyTuple_SET_ITEM(a, b, c) _PyObjCTuple_SetItem(a, b, c)
+
+static inline PyObject* _PyObjCTuple_GetItem(PyObject* tuple, Py_ssize_t idx)
+{
+    return PyTuple_GET_ITEM(tuple, idx);
+}
+#undef PyTuple_GET_ITEM
+#define PyTuple_GET_ITEM(a, b) _PyObjCTuple_GetItem(a, b)
+
+#pragma clang diagnostic pop
+
+#endif /* __clang__ */
+
 
 #endif /* PyObjC_COMPAT_H */

File pyobjc-core/Modules/objc/pyobjc-compat.m

     if (result == NULL) {
         return NULL;
     }
+
     PyString_InternInPlace(&result);
     return result;
 }
 
-
-
 #ifndef PY_FORMAT_LONG_LONG
 #define   PY_FORMAT_LONG_LONG "ll"
 #endif
     const char* f;
     char *s;
     PyObject* string;
-        Py_ssize_t callcount = 0;
+    Py_ssize_t callcount = 0;
     PyObject **callresults = NULL;
-        PyObject **callresult = NULL;
+    PyObject **callresult = NULL;
 
 #ifdef VA_LIST_IS_ARRAY
     Py_MEMCPY(count, vargs, sizeof(va_list));
         if (*f == '%') {
             if (*(f+1)=='%')
                 continue;
+
             if (*(f+1)=='S' || *(f+1)=='R')
                 ++callcount;
          }
     }
+
     if (callcount) {
         callresults = PyObject_Malloc(sizeof(PyObject *)*callcount);
         if (!callresults) {
                 }
 #endif
             }
+
             else if (*f == 'z' && (f[1] == 'd' || f[1] == 'u')) {
                 ++f;
             }
     }
 }
 
-
-#endif /* Py3K */
-
-/*
- * Helper function for making sure that we don't store duplicate data
- * for the metadata bridges.
- *
- * Interface: call on value, don't update value afterwards. Steals
- * reference to argument and returns a new reference.
- */
-static    PyObject* intern_mapping = NULL;
-
-void      PyObjC_ClearIntern(void)
-{
-    Py_CLEAR(intern_mapping);
-}
-
-PyObject* PyObjC_InternValue(PyObject* orig)
-{
-    return orig;
-}
-
-PyObject* PyObjC_IntFromString(char* v, char**pend, int base)
-{
-    PyObject* r = PyInt_FromString(v, pend, base);
-    if (r == NULL) {
-        return NULL;
-    }
-    return PyObjC_InternValue(r);
-}
-
-
-PyObject* PyObjC_IntFromLong(long v)
-{
-    PyObject* r = PyInt_FromLong(v);
-    if (r == NULL) {
-        return NULL;
-    }
-    return PyObjC_InternValue(r);
-}
-
 #ifdef PyObjC_FAST_UNICODE_ASCII
 
 const char* PyObjC_Unicode_Fast_Bytes(PyObject* object)
 }
 
 #endif /* PyObjC_FAST_UNICODE_ASCII */
+
+#endif /* Py3K */

File pyobjc-core/Modules/objc/pyobjc.h

 
 #define OBJC_VERSION "3.0a1"
 
-/*
- * Loading Quartz results close to 5K classes
- * on OSX 10.8
- */
-#define PYOBJC_EXPECTED_CLASS_COUNT 10000
+
 #define PY_SSIZE_T_CLEAN
-
 #include <Python.h>
 #include "structmember.h"
+
+#import <Foundation/Foundation.h>
+#include <AvailabilityMacros.h>
+#include <objc/objc-runtime.h>
+#include <objc/objc.h>
+
+
 #include "pyobjc-compat.h"
 
-#import <Foundation/Foundation.h>
-
 /*
- * SET_FIELD(op, value):
- *    macro for updating the value of 'op' to 'value',
- *    steals a reference to 'value'.
- *
- *    use this instead of 'Py_XDECREF(op); op = value'
+ * Configuration block
  */
-#define SET_FIELD(op, value)                    \
-    do {                                        \
-        PyObject* _py_tmp = (PyObject*)(op);    \
-        (op) = value;                           \
-        Py_XDECREF(_py_tmp);                    \
-    } while(0)
-
-/*
- * SET_FIELD_INCREF(op, value):
- *    macro for updating the value of 'op' to 'value'.
- *
- *    use this instead of 'Py_XDECREF(op); Py_INCREF(value); op = value'
- */
-#define SET_FIELD_INCREF(op, value)             \
-    do {                                        \
-        PyObject* _py_tmp = (PyObject*)(op);    \
-        Py_XINCREF(value);                       \
-        (op) = value;                           \
-        Py_XDECREF(_py_tmp);                    \
-    } while(0)
-
-#ifdef __clang__
-
-/* This is a crude hack to disable a otherwise useful warning in the context of
- * PyTuple_SET_ITEM, without disabling it everywhere
- */
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Warray-bounds"
-static inline void _PyObjCTuple_SetItem(PyObject* tuple, Py_ssize_t idx, PyObject* value)
-{
-    PyTuple_SET_ITEM(tuple, idx, value);
-}
-#undef PyTuple_SET_ITEM
-#define PyTuple_SET_ITEM(a, b, c) _PyObjCTuple_SetItem(a, b, c)
-
-static inline PyObject* _PyObjCTuple_GetItem(PyObject* tuple, Py_ssize_t idx)
-{
-    return PyTuple_GET_ITEM(tuple, idx);
-}
-#undef PyTuple_GET_ITEM
-#define PyTuple_GET_ITEM(a, b) _PyObjCTuple_GetItem(a, b)
-
-#pragma clang diagnostic pop
-
-#endif /* __clang__ */
-
 
 /* PyObjC_DEBUG: If defined the bridge will perform more internal checks */
 #ifdef Py_DEBUG
 /*#define PyObjC_FAST_BUT_INEXACT 1*/
 
 
-#include <objc/objc-runtime.h>
-#include <objc/objc.h>
+/*
+ * End of configuration block
+ */
 
-/* Define PyObjC_UNICODE_FAST_PATH when
- * 1) We're before Python 3.3, and
- * 2) Py_UNICODE has the same size as unichar
- *
- * Python 3.3 has an optimized representation that
- * makes it impossible to use the "fast path"
- */
-#if PY_VERSION_HEX >= 0x03030000
-#undef PyObjC_UNICODE_FAST_PATH
-#elif Py_UNICODE_SIZE == 2
-#define PyObjC_UNICODE_FAST_PATH
-#endif
 
-/*
- * XXX: disable the fast path for
- * unicode strings due to unexplained
- * test failures.
- */
-#if 0
-#ifdef PyObjC_UNICODE_FAST_PATH
-#undef PyObjC_UNICODE_FAST_PATH
-#endif
-#endif
 
 #include "arc-runtime.h"
 #include "objc-runtime-compat.h"
 #include "objc_super.h"
 #include "fsref.h"
 #include "fsspec.h"
+#include "registry.h"
+#include "corefoundation.h"
+#include "closure_pool.h"
+#include "block_support.h"
+#include "helpers.h"
 
+#define PYOBJC_BUILD
+#include "pyobjc-api.h"
+#undef PyObjC_BUILD
 
 /*
  * XXX: All definitions below here should be moved to different/new
  * headers
  */
 
-/* On MacOS X, +signatureWithObjCTypes: is a method of NSMethodSignature,
- * but that method is not present in the header files. We add the definition
- * here to avoid warnings.
- *
- * XXX: We use an undocumented API, but we also don't have much choice: we
- * must create the things and this is the only way to do it...
- */
-@interface NSMethodSignature (WarningKiller)
-    +(instancetype)signatureWithObjCTypes:(const char*)types;
-@end /* interface NSMethodSignature */
-
 
 extern BOOL PyObjC_useKVO;
 extern BOOL PyObjC_nativeProperties;
 
 
 int PyObjCAPI_Register(PyObject* module);
-#define PYOBJC_BUILD
-#include "pyobjc-api.h"
-#include "registry.h"
-#include "corefoundation.h"
-#include "closure_pool.h"
-#include "block_support.h"
-#include "helpers.h"
+
 
 extern PyObject* PyObjCMethodAccessor_New(PyObject* base, int class_method);
 
 #endif
 
 
+/*!
+ * PYOBJC_EXPECTED_CLASS_COUNT: Hint about the number of classes to expect
+ *
+ * Loading Quartz results close to 5K classes on OSX 10.8
+ */
+#define PYOBJC_EXPECTED_CLASS_COUNT 10000
 
+/*
+ * SET_FIELD(op, value):
+ *    macro for updating the value of 'op' to 'value',
+ *    steals a reference to 'value'.
+ *
+ *    use this instead of 'Py_XDECREF(op); op = value'
+ */
+#define SET_FIELD(op, value)                    \
+    do {                                        \
+        PyObject* _py_tmp = (PyObject*)(op);    \
+        (op) = value;                           \
+        Py_XDECREF(_py_tmp);                    \
+    } while(0)
+
+/*
+ * SET_FIELD_INCREF(op, value):
+ *    macro for updating the value of 'op' to 'value'.
+ *
+ *    use this instead of 'Py_XDECREF(op); Py_INCREF(value); op = value'
+ */
+#define SET_FIELD_INCREF(op, value)             \
+    do {                                        \
+        PyObject* _py_tmp = (PyObject*)(op);    \
+        Py_XINCREF(value);                       \
+        (op) = value;                           \
+        Py_XDECREF(_py_tmp);                    \
+    } while(0)
+
+
+/* Define PyObjC_UNICODE_FAST_PATH when
+ * 1) We're before Python 3.3, and
+ * 2) Py_UNICODE has the same size as unichar
+ *
+ * Python 3.3 has an optimized representation that
+ * makes it impossible (and unnecessary) to use the
+ * "fast path"
+ */
+#if PY_VERSION_HEX >= 0x03030000
+
+#undef PyObjC_UNICODE_FAST_PATH
+
+#elif Py_UNICODE_SIZE == 2
+
+#define PyObjC_UNICODE_FAST_PATH
+
+#endif
 
 #ifdef PyObjC_DEBUG
 

File pyobjc-core/Modules/objc/registry.h

 #ifndef PyObjC_registry_H
 #define PyObjC_registry_H
-/* Where's the documentation? */
 
-PyObject* PyObjC_NewRegistry(void);
-int PyObjC_AddToRegistry(PyObject*, PyObject*, PyObject*, PyObject*);
-PyObject* PyObjC_FindInRegistry(PyObject*, Class, SEL);
+extern PyObject* PyObjC_NewRegistry(void);
+extern int PyObjC_AddToRegistry(PyObject*, PyObject*, PyObject*, PyObject*);
+extern PyObject* PyObjC_FindInRegistry(PyObject*, Class, SEL);
 
 #endif /* PyObjC_registry_H */

File pyobjc-core/Modules/objc/registry.m

     return PyDict_New();
 }
 
-
 int
 PyObjC_AddToRegistry(
         PyObject* registry,
         PyObject* class_name, PyObject* selector,
         PyObject* value)
 {
+    int result;
     PyObject* sublist;
     PyObject* item = Py_BuildValue("(OO)", class_name, value);
     if (item == NULL) {
     if (!PyObjC_UpdatingMetaData) {
         PyObjC_MappingCount += 1;
     }
-    int result = PyList_Append(sublist, item);
+    result = PyList_Append(sublist, item);
     Py_DECREF(item);
     return result;
 }

File pyobjc-core/Modules/objc/struct-sockaddr.m

         addr->sun_family = AF_INET;
 
         if (PyUnicode_Check(value)) {
+#if Py_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2
             value = PyUnicode_EncodeFSDefault(value);
+#else
+            /* The filesystem encoding on OSX is UTF-8,
+             * use that instead of trying to fetch the
+             * filesystem encoding from the sys module.
+             */
+            value = PyUnicode_AsUTF8String(value);
+#endif
             if (value == NULL) {
                 return -1;
             }

File pyobjc-core/Modules/objc/struct-wrapper.m

         /* Store custom struct packing as an attribute of the type
          * object, to be able to  fetch it when depythonifying the object.
          */
-        v = Py_BuildValue(Py_ARG_SIZE_T, pack);
+        v = Py_BuildValue("n", pack);
         if (v == NULL) {
             Py_DECREF(structType);
             return NULL;

File pyobjc-core/Modules/objc/super-call.m

 /* Dict mapping from signature-string to a 'struct registry' */
 static PyObject* signature_registry = NULL;
 
-/* Dict mapping from selector to a list of (Class, struct registry) tuples */
+/* Dict mapping from selector to a list of (Class, struct registry) tuples
+ * XXX: Isn't this a registry (PyObjC_NewRegistry)?
+ */
 static PyObject* special_registry  = NULL;
 
 /*

File pyobjc-core/Modules/objc/varlist.m

     Py_ssize_t i, length;
     PyObject*  result;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, Py_ARG_SIZE_T, keywords, &length)) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "n", keywords, &length)) {
         return NULL;
     }
 

File pyobjc-core/NEWS.txt

   to use type encodings as used in :c:func:`Py_BuildValue` and AFAIK were never
   used in real code.
 
+* Py_ARG_SIZE_T is no longer defined by "pyobjc-api.h"
+
 
 Version 2.6
 -----------

File pyobjc-core/setup.py

     # 1) Testsuite crashes with an incomplete testcase (python2.7, OSX 10.8)
     # 2) There should be a build-time check to see if these options are supported
 
-    # Enable more optimization. 
+    # Enable more optimization.
     vars = get_config_vars()
     for k in vars: # XXX
         if isinstance(vars[k], str) and '-O2' in vars[k]:

File pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFBag.m

  */
 static PyObject*
 mod_CFBagGetValues(
-	PyObject* self __attribute__((__unused__)), 
+	PyObject* self __attribute__((__unused__)),
 	PyObject* args)
 {
 	PyObject* py_bag;
 }
 
 
-static PyObject* 
+static PyObject*
 mod_CFBagCreate(PyObject* self __attribute__((__unused__)),
 	PyObject* args)
 {
 	CFBagRef bag;
 
 
-	if (!PyArg_ParseTuple(args, "OO" Py_ARG_SIZE_T, &py_allocator, &py_members, &count)) {
+	if (!PyArg_ParseTuple(args, "OOn", &py_allocator, &py_members, &count)) {
 		return NULL;
 	}
 
 	return result;
 }
 
-static PyObject* 
+static PyObject*
 mod_CFBagCreateMutable(PyObject* self __attribute__((__unused__)),
 	PyObject* args)
 {
 	CFBagRef bag;
 
 
-	if (!PyArg_ParseTuple(args, "O" Py_ARG_SIZE_T, &py_allocator, &count)) {
+	if (!PyArg_ParseTuple(args, "On", &py_allocator, &count)) {
 		return NULL;
 	}
 

File pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFBinaryHeap.m

 
 static CFStringRef mod_binheap_copydescription(const void* ptr)
 {
-	CFStringRef r =  CFCopyDescription(ptr);	
+	CFStringRef r =  CFCopyDescription(ptr);
 	return r;
 }
 
 
 
 static CFBinaryHeapCallBacks mod_NSObjectBinaryHeapCallbacks = {
-	0, 
+	0,
 	mod_binheap_retain,
 	mod_binheap_release,
 	mod_binheap_copydescription,
 };
 
 
-static PyObject* 
+static PyObject*
 mod_CFBinaryHeapCreate(PyObject* self __attribute__((__unused__)),
 	PyObject* args)
 {
 	CFBinaryHeapRef heap;
 
 
-	if (!PyArg_ParseTuple(args, "O" Py_ARG_SIZE_T, &py_allocator, &count)) {
+	if (!PyArg_ParseTuple(args, "On", &py_allocator, &count)) {
 		return NULL;
 	}
 
 
 static PyObject*
 mod_CFBinaryHeapGetValues(
-	PyObject* self __attribute__((__unused__)), 
+	PyObject* self __attribute__((__unused__)),
 	PyObject* args)
 {
 	PyObject* py_heap;

File pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFBitVector.m

 /*
  * Manual wrappers for CFBitVector
  */
-static PyObject* 
+static PyObject*
 mod_CFBitVectorCreate(PyObject* self __attribute__((__unused__)),
 	PyObject* args)
 {
 	CFBitVectorRef vector;
 
 
-	if (!PyArg_ParseTuple(args, "OO" Py_ARG_SIZE_T, &py_allocator, &py_bytes, &count)) {
+	if (!PyArg_ParseTuple(args, "OOn", &py_allocator, &py_bytes, &count)) {
 		return NULL;
 	}
 
 	void* bytes;
 	int r;
 	Py_ssize_t byteCount;
-	
+
 	if (count == -1) {
 		byteCount = -1;
 	} else {

File pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFNumber.m

 		CFIndex indexv;
 	} buf;
 
-	if (!PyArg_ParseTuple(args, "O"Py_ARG_SIZE_T"O", &py_number, &type, &py_buf)) {
+	if (!PyArg_ParseTuple(args, "OnO", &py_number, &type, &py_buf)) {
 		return NULL;
 	}
 	if (py_buf != Py_None) {
 		CFIndex indexv;
 	} buf;
 
-	if (!PyArg_ParseTuple(args, "O"Py_ARG_SIZE_T"O", &py_allocator, &type, &py_value)) {
+	if (!PyArg_ParseTuple(args, "OnO", &py_allocator, &type, &py_value)) {
 		return NULL;
 	}
 	if (PyObjC_PythonToObjC(@encode(CFAllocatorRef), py_allocator, &allocator) < 0) {

File pyobjc-framework-CoreText/Modules/_manual.m

 
 
 static PyObject*
-m_CTFontCopyAvailableTables(PyObject* self __attribute__((__unused__)), 
+m_CTFontCopyAvailableTables(PyObject* self __attribute__((__unused__)),
 		PyObject* args)
 {
 	PyObject* py_font;
 
 	if (!b) {
 		return Py_BuildValue("OO", Py_False, Py_None);
-	} 
+	}
 
 	result = Py_BuildValue("NN", PyBool_FromLong(b), PyObjC_IdToPython((NSObject*)output));
 	return result;
 	CTParagraphStyleSetting* settings;
 	CTParagraphStyleRef style = NULL;
 
-	if (!PyArg_ParseTuple(args, "O" Py_ARG_SIZE_T, &py_settings, &len)) {
+	if (!PyArg_ParseTuple(args, "On", &py_settings, &len)) {
 		return NULL;
 	}
 
 			return NULL;
 		}
 
-		r = PyObjC_PythonToObjC(@encode(CTParagraphStyleSpecifier), 
+		r = PyObjC_PythonToObjC(@encode(CTParagraphStyleSpecifier),
 				PySequence_Fast_GET_ITEM(s, 0), &cur->spec);
 		if (r == -1) {
 			Py_DECREF(seq);
 			free(settings);
 			return NULL;
 		}
-		r = PyObjC_PythonToObjC(@encode(size_t), 
+		r = PyObjC_PythonToObjC(@encode(size_t),
 				PySequence_Fast_GET_ITEM(s, 1), &cur->valueSize);
 		if (r == -1) {
 			Py_DECREF(seq);
 				r = -1;
 			} else {
 
-				r = PyObjC_PythonToObjC(@encode(CFArrayRef), 
+				r = PyObjC_PythonToObjC(@encode(CFArrayRef),
 					PySequence_Fast_GET_ITEM(s, 2), &aref);
 				cur->value = &aref;
 			}
 	PyObjC_HANDLER
 		rv = NULL;
 		PyObjCErr_FromObjC(localException);
-	
+
 	PyObjC_ENDHANDLER
 
 	free(settings);
-	
+
 	if (PyErr_Occurred()) {
 		if (rv) {
 			CFRelease(rv);

File pyobjc-framework-FSEvents/Modules/_callbacks.m

 	}
 
 	/* description is autoreleased, we should donate a reference to
-	 * our caller 
+	 * our caller
 	 */
 	CFRetain(result);
 
 	PyObject* callback;
 	PyObject* info;
 	PyObject* v;
-	PyObject* paths;	
+	PyObject* paths;
 
 	v = PyTuple_GET_ITEM((PyObject*)clientCallbackInfo, 0);
 	if (PyObjC_PythonToObjC(
 		}
 	} else {
 		/* The evenPaths are a CArray of C strings */
-		paths = PyObjC_CArrayToPython(@encode(char*), 
+		paths = PyObjC_CArrayToPython(@encode(char*),
 				eventPaths, numEvents);
 		if (paths == NULL) {
 			PyObjCErr_ToObjCWithGILState(&state);
 	}
 
 	PyObject* py_streamRef = PyObjC_ObjCToPython(
-			@encode(ConstFSEventStreamRef), 
+			@encode(ConstFSEventStreamRef),
 			&streamRef);
 	if (py_streamRef == NULL) {
 		Py_DECREF(paths);
 		PyObjCErr_ToObjCWithGILState(&state);
 	}
 	PyObject* py_eventFlags = PyObjC_CArrayToPython(
-			@encode(FSEventStreamCreateFlags), 
+			@encode(FSEventStreamCreateFlags),
 			(void*)eventFlags, numEvents);
 	if (py_eventFlags == NULL) {
 		Py_DECREF(paths);
 		PyObjCErr_ToObjCWithGILState(&state);
 	}
 	PyObject* py_eventIds = PyObjC_CArrayToPython(
-			@encode(FSEventStreamEventId), 
+			@encode(FSEventStreamEventId),
 			(void*)eventIds, numEvents);
 	if (py_eventIds == NULL) {
 		Py_DECREF(paths);
 	}
 
 	PyObject* result = PyObject_CallFunction(callback,
-			"OO" Py_ARG_SIZE_T "OOO",
+			"OOnOOO",
 			py_streamRef, info, numEvents, paths,
 			py_eventFlags,
 			py_eventIds);
 
 		return NULL;
 	}
-	
+
 	CFAllocatorRef allocator;
 	if (PyObjC_PythonToObjC(@encode(CFAllocatorRef), py_allocator, &allocator) < 0) {
 		return NULL;
 	}
 
 	PyObject* result =  PyObjC_ObjCToPython(@encode(FSEventStreamRef), &stream);
-	// FSEventStreamRef is not a CF type (AFAIK), hence the user is 
+	// FSEventStreamRef is not a CF type (AFAIK), hence the user is
 	// responsible for maintaining the refcount.
 	//FSEventStreamRelease(stream);
 	return result;
 	PyObject* py_deviceToWatch;
 
 	if (!PyArg_ParseTuple(args, "OOOOOOOO",
-		&py_allocator, &py_callback, &py_callback_info, 
-		&py_deviceToWatch, &py_pathsToWatch, &py_sinceWhen, 
+		&py_allocator, &py_callback, &py_callback_info,
+		&py_deviceToWatch, &py_pathsToWatch, &py_sinceWhen,
 		&py_latency, &py_flags)) {
 
 		return NULL;
 	}
-	
+
 	CFAllocatorRef allocator;
 	if (PyObjC_PythonToObjC(@encode(CFAllocatorRef), py_allocator, &allocator) < 0) {
 		return NULL;
 
 	PyObject* result = PyObjC_ObjCToPython(
 			@encode(FSEventStreamRef), &stream);
-	// FSEventStreamRef is not a CF type (AFAIK), hence the user is 
+	// FSEventStreamRef is not a CF type (AFAIK), hence the user is
 	// responsible for maintaining the refcount.
 	//FSEventStreamRelease(stream);
 	return result;
 		PyObjC_INITERROR();
 	}
 
-        if (PyObjC_ImportAPI(m) < 0) { 
+        if (PyObjC_ImportAPI(m) < 0) {
 		PyObjC_INITERROR();
 	}