Author: Devin Jeanpierre <jeanpierr...@gmail.com>
Branch: cpyext-macros-cast
Changeset: r84388:b3124c608c44
Date: 2016-05-11 09:47 -0700
http://bitbucket.org/pypy/pypy/changeset/b3124c608c44/

Log:    Back out non-test changes, since I'm going to rewrite how I make the
        tests pass.

        hg backout cf292fe --no-commit hg status -n | grep test/ | xargs hg
        revert

diff --git a/pypy/module/cpyext/cdatetime.py b/pypy/module/cpyext/cdatetime.py
--- a/pypy/module/cpyext/cdatetime.py
+++ b/pypy/module/cpyext/cdatetime.py
@@ -179,67 +179,67 @@
 # Accessors
 
 @cpython_api([PyDateTime_Date], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_GET_YEAR(space, w_obj):
+def PyDateTime_GET_YEAR(space, w_obj):
     """Return the year, as a positive int.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("year")))
 
 @cpython_api([PyDateTime_Date], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_GET_MONTH(space, w_obj):
+def PyDateTime_GET_MONTH(space, w_obj):
     """Return the month, as an int from 1 through 12.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("month")))
 
 @cpython_api([PyDateTime_Date], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_GET_DAY(space, w_obj):
+def PyDateTime_GET_DAY(space, w_obj):
     """Return the day, as an int from 1 through 31.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("day")))
 
 @cpython_api([PyDateTime_DateTime], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_DATE_GET_HOUR(space, w_obj):
+def PyDateTime_DATE_GET_HOUR(space, w_obj):
     """Return the hour, as an int from 0 through 23.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("hour")))
 
 @cpython_api([PyDateTime_DateTime], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_DATE_GET_MINUTE(space, w_obj):
+def PyDateTime_DATE_GET_MINUTE(space, w_obj):
     """Return the minute, as an int from 0 through 59.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("minute")))
 
 @cpython_api([PyDateTime_DateTime], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_DATE_GET_SECOND(space, w_obj):
+def PyDateTime_DATE_GET_SECOND(space, w_obj):
     """Return the second, as an int from 0 through 59.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("second")))
 
 @cpython_api([PyDateTime_DateTime], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_DATE_GET_MICROSECOND(space, w_obj):
+def PyDateTime_DATE_GET_MICROSECOND(space, w_obj):
     """Return the microsecond, as an int from 0 through 999999.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("microsecond")))
 
 @cpython_api([PyDateTime_Time], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_TIME_GET_HOUR(space, w_obj):
+def PyDateTime_TIME_GET_HOUR(space, w_obj):
     """Return the hour, as an int from 0 through 23.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("hour")))
 
 @cpython_api([PyDateTime_Time], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_TIME_GET_MINUTE(space, w_obj):
+def PyDateTime_TIME_GET_MINUTE(space, w_obj):
     """Return the minute, as an int from 0 through 59.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("minute")))
 
 @cpython_api([PyDateTime_Time], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_TIME_GET_SECOND(space, w_obj):
+def PyDateTime_TIME_GET_SECOND(space, w_obj):
     """Return the second, as an int from 0 through 59.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("second")))
 
 @cpython_api([PyDateTime_Time], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_TIME_GET_MICROSECOND(space, w_obj):
+def PyDateTime_TIME_GET_MICROSECOND(space, w_obj):
     """Return the microsecond, as an int from 0 through 999999.
     """
     return space.int_w(space.getattr(w_obj, space.wrap("microsecond")))
@@ -249,13 +249,13 @@
 # for types defined in a python module like lib/datetime.py.
 
 @cpython_api([PyDateTime_Delta], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_DELTA_GET_DAYS(space, w_obj):
+def PyDateTime_DELTA_GET_DAYS(space, w_obj):
     return space.int_w(space.getattr(w_obj, space.wrap("days")))
 
 @cpython_api([PyDateTime_Delta], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_DELTA_GET_SECONDS(space, w_obj):
+def PyDateTime_DELTA_GET_SECONDS(space, w_obj):
     return space.int_w(space.getattr(w_obj, space.wrap("seconds")))
 
 @cpython_api([PyDateTime_Delta], rffi.INT_real, error=CANNOT_FAIL)
-def _PyDateTime_DELTA_GET_MICROSECONDS(space, w_obj):
+def PyDateTime_DELTA_GET_MICROSECONDS(space, w_obj):
     return space.int_w(space.getattr(w_obj, space.wrap("microseconds")))
diff --git a/pypy/module/cpyext/floatobject.py 
b/pypy/module/cpyext/floatobject.py
--- a/pypy/module/cpyext/floatobject.py
+++ b/pypy/module/cpyext/floatobject.py
@@ -49,7 +49,7 @@
     return space.float_w(space.float(w_obj))
 
 @cpython_api([PyObject], lltype.Float, error=CANNOT_FAIL)
-def _PyFloat_AS_DOUBLE(space, w_float):
+def PyFloat_AS_DOUBLE(space, w_float):
     """Return a C double representation of the contents of w_float, but
     without error checking."""
     return space.float_w(w_float)
diff --git a/pypy/module/cpyext/include/Python.h 
b/pypy/module/cpyext/include/Python.h
--- a/pypy/module/cpyext/include/Python.h
+++ b/pypy/module/cpyext/include/Python.h
@@ -87,7 +87,6 @@
 #include "pymath.h"
 #include "pyport.h"
 #include "warnings.h"
-#include "weakrefobject.h"
 
 #include <stdarg.h>
 #include <stdio.h>
@@ -103,7 +102,6 @@
 #include "funcobject.h"
 #include "code.h"
 
-#include "abstract.h"
 #include "modsupport.h"
 #include "pythonrun.h"
 #include "pyerrors.h"
@@ -131,7 +129,6 @@
 #include "fileobject.h"
 #include "pysignals.h"
 #include "pythread.h"
-#include "setobject.h"
 #include "traceback.h"
 
 /* Missing definitions */
diff --git a/pypy/module/cpyext/include/abstract.h 
b/pypy/module/cpyext/include/abstract.h
--- a/pypy/module/cpyext/include/abstract.h
+++ b/pypy/module/cpyext/include/abstract.h
@@ -1,3 +1,1 @@
-#define PySequence_Fast_GET_ITEM(seq, i) 
_PySequence_Fast_GET_ITEM((PyObject*)(seq), (i))
-#define PySequence_Fast_GET_SIZE(seq) 
_PySequence_Fast_GET_SIZE((PyObject*)(seq))
-#define PySequence_ITEM(seq, i) _PySequence_ITEM((PyObject*)(seq), (i))
+/* empty */
diff --git a/pypy/module/cpyext/include/datetime.h 
b/pypy/module/cpyext/include/datetime.h
--- a/pypy/module/cpyext/include/datetime.h
+++ b/pypy/module/cpyext/include/datetime.h
@@ -4,27 +4,6 @@
 extern "C" {
 #endif
 
-
-#define PyDateTime_GET_YEAR(o)  _PyDateTime_GET_YEAR((PyDateTime_Date*)(o))
-#define PyDateTime_GET_MONTH(o) _PyDateTime_GET_MONTH((PyDateTime_Date*)(o))
-#define PyDateTime_GET_DAY(o)   _PyDateTime_GET_DAY((PyDateTime_Date*)(o))
-
-#define PyDateTime_DATE_GET_HOUR(o)        
_PyDateTime_DATE_GET_HOUR((PyDateTime_DateTime*)(o))
-#define PyDateTime_DATE_GET_MINUTE(o)      
_PyDateTime_DATE_GET_MINUTE((PyDateTime_DateTime*)(o))
-#define PyDateTime_DATE_GET_SECOND(o)      
_PyDateTime_DATE_GET_SECOND((PyDateTime_DateTime*)(o))
-#define PyDateTime_DATE_GET_MICROSECOND(o) 
_PyDateTime_DATE_GET_MICROSECOND((PyDateTime_DateTime*)(o))
-
-#define PyDateTime_TIME_GET_HOUR(o)        
_PyDateTime_TIME_GET_HOUR((PyDateTime_Time*)(o))
-#define PyDateTime_TIME_GET_MINUTE(o)      
_PyDateTime_TIME_GET_MINUTE((PyDateTime_Time*)(o))
-#define PyDateTime_TIME_GET_SECOND(o)      
_PyDateTime_TIME_GET_SECOND((PyDateTime_Time*)(o))
-#define PyDateTime_TIME_GET_MICROSECOND(o) 
_PyDateTime_TIME_GET_MICROSECOND((PyDateTime_Time*)(o))
-
-#define PyDateTime_DELTA_GET_DAYS(o)         
_PyDateTime_DELTA_GET_DAYS((PyDateTime_Delta*)(o))
-#define PyDateTime_DELTA_GET_SECONDS(o)      
_PyDateTime_DELTA_GET_SECONDS((PyDateTime_Delta*)(o))
-#define PyDateTime_DELTA_GET_MICROSECONDS(o) 
_PyDateTime_DELTA_GET_MICROSECONDS((PyDateTime_Delta*)(o))
-
-
-
 /* Define structure for C API. */
 typedef struct {
     /* type objects */
diff --git a/pypy/module/cpyext/include/floatobject.h 
b/pypy/module/cpyext/include/floatobject.h
--- a/pypy/module/cpyext/include/floatobject.h
+++ b/pypy/module/cpyext/include/floatobject.h
@@ -19,8 +19,6 @@
     double ob_fval;
 } PyFloatObject;
 
-#define PyFloat_AS_DOUBLE(o) _PyFloat_AS_DOUBLE((PyObject*)(o))
-
 #define PyFloat_STR_PRECISION 12
 
 #ifdef Py_NAN
diff --git a/pypy/module/cpyext/include/intobject.h 
b/pypy/module/cpyext/include/intobject.h
--- a/pypy/module/cpyext/include/intobject.h
+++ b/pypy/module/cpyext/include/intobject.h
@@ -7,8 +7,6 @@
 extern "C" {
 #endif
 
-#define PyInt_AS_LONG(obj) _PyInt_AS_LONG((PyObject*)obj)
-
 typedef struct {
     PyObject_HEAD
     long ob_ival;
diff --git a/pypy/module/cpyext/include/listobject.h 
b/pypy/module/cpyext/include/listobject.h
--- a/pypy/module/cpyext/include/listobject.h
+++ b/pypy/module/cpyext/include/listobject.h
@@ -1,3 +1,1 @@
-#define PyList_GET_ITEM(o, i)     PyList_GetItem((PyObject*)(o), (i))
-#define PyList_SET_ITEM(o, i, v)  _PyList_SET_ITEM((PyObject*)(o), (i), (v))
-#define PyList_GET_SIZE(o)        _PyList_GET_SIZE((PyObject*)(o))
+#define PyList_GET_ITEM PyList_GetItem
diff --git a/pypy/module/cpyext/include/setobject.h 
b/pypy/module/cpyext/include/setobject.h
deleted file mode 100644
--- a/pypy/module/cpyext/include/setobject.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* Int object interface */
-
-#ifndef Py_SETOBJECT_H
-#define Py_SETOBJECT_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define PySet_GET_SIZE(obj) _PySet_GET_SIZE((PyObject*)obj)
-
-#ifdef __cplusplus
-}
-#endif
-#endif /* !Py_SETOBJECT_H */
diff --git a/pypy/module/cpyext/include/unicodeobject.h 
b/pypy/module/cpyext/include/unicodeobject.h
--- a/pypy/module/cpyext/include/unicodeobject.h
+++ b/pypy/module/cpyext/include/unicodeobject.h
@@ -5,10 +5,6 @@
 extern "C" {
 #endif
 
-#define PyUnicode_GET_SIZE(o) _PyUnicode_GET_SIZE((PyObject*)(o))
-#define PyUnicode_GET_DATA_SIZE(o) _PyUnicode_GET_DATA_SIZE((PyObject*)(o))
-#define PyUnicode_AS_UNICODE(o) _PyUnicode_AS_UNICODE((PyObject*)(o))
-
 
 typedef unsigned int Py_UCS4;
 #ifdef HAVE_USABLE_WCHAR_T
diff --git a/pypy/module/cpyext/include/weakrefobject.h 
b/pypy/module/cpyext/include/weakrefobject.h
deleted file mode 100644
--- a/pypy/module/cpyext/include/weakrefobject.h
+++ /dev/null
@@ -1,1 +0,0 @@
-#define PyWeakref_GET_OBJECT(o) PyWeakref_GetObject((PyObject*)(o))
diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py
--- a/pypy/module/cpyext/intobject.py
+++ b/pypy/module/cpyext/intobject.py
@@ -105,7 +105,7 @@
         return num.ulonglongmask()
 
 @cpython_api([PyObject], lltype.Signed, error=CANNOT_FAIL)
-def _PyInt_AS_LONG(space, w_int):
+def PyInt_AS_LONG(space, w_int):
     """Return the value of the object w_int. No error checking is performed."""
     return space.int_w(w_int)
 
diff --git a/pypy/module/cpyext/listobject.py b/pypy/module/cpyext/listobject.py
--- a/pypy/module/cpyext/listobject.py
+++ b/pypy/module/cpyext/listobject.py
@@ -23,7 +23,7 @@
 
 @cpython_api([PyObject, Py_ssize_t, PyObject], PyObject, error=CANNOT_FAIL,
              result_borrowed=True)
-def _PyList_SET_ITEM(space, w_list, index, w_item):
+def PyList_SET_ITEM(space, w_list, index, w_item):
     """Macro form of PyList_SetItem() without error checking. This is normally
     only used to fill in new lists where there is no previous content.
 
@@ -88,7 +88,7 @@
     return 0
 
 @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def _PyList_GET_SIZE(space, w_list):
+def PyList_GET_SIZE(space, w_list):
     """Macro form of PyList_Size() without error checking.
     """
     assert isinstance(w_list, W_ListObject)
@@ -102,7 +102,7 @@
     """
     if not PyList_Check(space, ref):
         raise oefmt(space.w_TypeError, "expected list object")
-    return _PyList_GET_SIZE(space, ref)
+    return PyList_GET_SIZE(space, ref)
 
 @cpython_api([PyObject], PyObject)
 def PyList_AsTuple(space, w_list):
diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -46,7 +46,7 @@
     members of the result.  Returns NULL on failure.  If the object is not a
     sequence, raises TypeError with m as the message text."""
     if isinstance(w_obj, W_ListObject):
-        # make sure we can return a borrowed obj from _PySequence_Fast_GET_ITEM
+        # make sure we can return a borrowed obj from PySequence_Fast_GET_ITEM 
   
         w_obj.convert_to_cpy_strategy(space)
         return w_obj
     try:
@@ -55,7 +55,7 @@
         raise OperationError(space.w_TypeError, space.wrap(rffi.charp2str(m)))
 
 @cpython_api([PyObject, Py_ssize_t], PyObject, result_borrowed=True)
-def _PySequence_Fast_GET_ITEM(space, w_obj, index):
+def PySequence_Fast_GET_ITEM(space, w_obj, index):
     """Return the ith element of o, assuming that o was returned by
     PySequence_Fast(), o is not NULL, and that i is within bounds.
     """
@@ -68,7 +68,7 @@
                 "sequence")
 
 @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def _PySequence_Fast_GET_SIZE(space, w_obj):
+def PySequence_Fast_GET_SIZE(space, w_obj):
     """Returns the length of o, assuming that o was returned by
     PySequence_Fast() and that o is not NULL.  The size can also be
     gotten by calling PySequence_Size() on o, but
@@ -120,7 +120,7 @@
     return 0
 
 @cpython_api([PyObject, Py_ssize_t], PyObject)
-def _PySequence_ITEM(space, w_obj, i):
+def PySequence_ITEM(space, w_obj, i):
     """Return the ith element of o or NULL on failure. Macro form of
     PySequence_GetItem() but without checking that
     PySequence_Check(o)() is true and without adjustment for negative
@@ -134,7 +134,7 @@
 def PySequence_GetItem(space, w_obj, i):
     """Return the ith element of o, or NULL on failure. This is the equivalent 
of
     the Python expression o[i]."""
-    return _PySequence_ITEM(space, w_obj, i)
+    return PySequence_ITEM(space, w_obj, i)
 
 @cpython_api([PyObject], PyObject)
 def PySequence_List(space, w_obj):
diff --git a/pypy/module/cpyext/setobject.py b/pypy/module/cpyext/setobject.py
--- a/pypy/module/cpyext/setobject.py
+++ b/pypy/module/cpyext/setobject.py
@@ -75,7 +75,7 @@
     return 0
 
 @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def _PySet_GET_SIZE(space, w_s):
+def PySet_GET_SIZE(space, w_s):
     """Macro form of PySet_Size() without error checking."""
     return space.int_w(space.len(w_s))
 
@@ -86,7 +86,7 @@
     or an instance of a subtype."""
     if not PySet_Check(space, ref):
         raise oefmt(space.w_TypeError, "expected set object")
-    return _PySet_GET_SIZE(space, ref)
+    return PySet_GET_SIZE(space, ref)
 
 @cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
 def PySet_Contains(space, w_obj, w_key):
diff --git a/pypy/module/cpyext/unicodeobject.py 
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -192,23 +192,23 @@
 def PyUnicode_AS_DATA(space, ref):
     """Return a pointer to the internal buffer of the object. o has to be a
     PyUnicodeObject (not checked)."""
-    return rffi.cast(rffi.CCHARP, _PyUnicode_AS_UNICODE(space, ref))
+    return rffi.cast(rffi.CCHARP, PyUnicode_AS_UNICODE(space, ref))
 
 @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def _PyUnicode_GET_DATA_SIZE(space, w_obj):
+def PyUnicode_GET_DATA_SIZE(space, w_obj):
     """Return the size of the object's internal buffer in bytes.  o has to be a
     PyUnicodeObject (not checked)."""
-    return rffi.sizeof(lltype.UniChar) * _PyUnicode_GET_SIZE(space, w_obj)
+    return rffi.sizeof(lltype.UniChar) * PyUnicode_GET_SIZE(space, w_obj)
 
 @cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
-def _PyUnicode_GET_SIZE(space, w_obj):
+def PyUnicode_GET_SIZE(space, w_obj):
     """Return the size of the object.  o has to be a PyUnicodeObject (not
     checked)."""
     assert isinstance(w_obj, unicodeobject.W_UnicodeObject)
     return space.len_w(w_obj)
 
 @cpython_api([PyObject], rffi.CWCHARP, error=CANNOT_FAIL)
-def _PyUnicode_AS_UNICODE(space, ref):
+def PyUnicode_AS_UNICODE(space, ref):
     """Return a pointer to the internal Py_UNICODE buffer of the object.  ref
     has to be a PyUnicodeObject (not checked)."""
     ref_unicode = rffi.cast(PyUnicodeObject, ref)
@@ -227,7 +227,7 @@
     w_type = from_ref(space, rffi.cast(PyObject, ref.c_ob_type))
     if not space.is_true(space.issubtype(w_type, space.w_unicode)):
         raise oefmt(space.w_TypeError, "expected unicode object")
-    return _PyUnicode_AS_UNICODE(space, ref)
+    return PyUnicode_AS_UNICODE(space, ref)
 
 @cpython_api([PyObject], Py_ssize_t, error=-1)
 def PyUnicode_GetSize(space, ref):
@@ -247,7 +247,7 @@
     string may or may not be 0-terminated.  It is the responsibility of the 
caller
     to make sure that the wchar_t string is 0-terminated in case this is
     required by the application."""
-    c_str = _PyUnicode_AS_UNICODE(space, rffi.cast(PyObject, ref))
+    c_str = PyUnicode_AS_UNICODE(space, rffi.cast(PyObject, ref))
     c_length = ref.c_length
 
     # If possible, try to copy the 0-termination as well
diff --git a/pypy/module/cpyext/weakrefobject.py 
b/pypy/module/cpyext/weakrefobject.py
--- a/pypy/module/cpyext/weakrefobject.py
+++ b/pypy/module/cpyext/weakrefobject.py
@@ -37,6 +37,13 @@
     """
     return space.call_function(w_ref)     # borrowed ref
 
+@cpython_api([PyObject], PyObject, result_borrowed=True)
+def PyWeakref_GET_OBJECT(space, w_ref):
+    """Similar to PyWeakref_GetObject(), but implemented as a macro that does 
no
+    error checking.
+    """
+    return space.call_function(w_ref)     # borrowed ref
+
 @cpython_api([PyObject], PyObject)
 def PyWeakref_LockObject(space, w_ref):
     """Return the referenced object from a weak reference.  If the referent is
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to