[pypy-commit] extradoc extradoc: Nearly done ?

2014-12-06 Thread rguillebert
Author: Romain Guillebert 
Branch: extradoc
Changeset: r5481:89e8eadeff5e
Date: 2014-12-06 14:02 +0530
http://bitbucket.org/pypy/extradoc/changeset/89e8eadeff5e/

Log:Nearly done ?

diff --git a/talk/scipyindia2014/talk.pdf b/talk/scipyindia2014/talk.pdf
new file mode 100644
index 
..4be849fc047dc21919a478732a2521894f5b01fc
GIT binary patch

[cut]

diff --git a/talk/scipyindia2014/talk.rst b/talk/scipyindia2014/talk.rst
--- a/talk/scipyindia2014/talk.rst
+++ b/talk/scipyindia2014/talk.rst
@@ -107,14 +107,14 @@
 
 * Most of numpy is there
 
-* XXX is missing
+* linalg and the object dtype are the two biggest features that we haven't 
implemented yet
 
 NumPyPy performance
 ---
 
 * Vectorized operations should be as fast as Numpy
 
-* Using ndarrays as you would use arrays in C or Java should be as fast
+* Using ndarrays as you would use arrays in C or Java should be as fast as the 
vectorized way
 
 * Lazy evaluation ?
 
@@ -123,7 +123,7 @@
 
 * Work in progress
 
-* Allows you to use any CPython module on PyPy
+* Allows you to use any CPython module on PyPy (scipy for example)
 
 * Embeds CPython into PyPy with CFFI
 
@@ -164,7 +164,7 @@
 
 * Provides a decorator that allows you to run specific functions on PyPy
 
-* Is used the same way as numba, but different performance caracteristics
+* Is used the same way as numba, but different performance characteristics
 
 JitPy
 -
@@ -188,6 +188,17 @@
 
 |end_scriptsize|
 
+Future
+--
+
+* Full numpy support
+
+* Improved C extension compatibility
+
+* I would like to see Cython work with PyPy
+
+* No more Global Interpreter Lock
+
 Thank You
 -
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy more-rposix: Better placement for sandbox properties

2014-12-06 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: more-rposix
Changeset: r74850:3b5d1aeee6d5
Date: 2014-12-06 11:37 +0100
http://bitbucket.org/pypy/pypy/changeset/3b5d1aeee6d5/

Log:Better placement for sandbox properties

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -296,12 +296,12 @@
 class ExtRegistry(ExtRegistryEntry):
 _about_ = replaced_function
 def compute_annotation(self):
+if sandboxed_name:
+config = self.bookkeeper.annotator.translator.config
+if config.translation.sandbox:
+func._sandbox_external_name = sandboxed_name
+func._dont_inline_ = True
 return self.bookkeeper.immutablevalue(func)
-
-if sandboxed_name:
-func._sandbox_external_name = sandboxed_name
-# XXX THIS IS NOT CORRECT. Only do this when config.sandbox.
-func._dont_inline_ = True
 return func
 return wrap
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy more-rposix: Don't use os.write in gc helper functions.

2014-12-06 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: more-rposix
Changeset: r74851:c722fad1b5bf
Date: 2014-12-06 11:41 +0100
http://bitbucket.org/pypy/pypy/changeset/c722fad1b5bf/

Log:Don't use os.write in gc helper functions. This fixes a test where
os.write is not used in translated function, and is annotated too
late.

extfunc.py uses a "mixed-level delayed object" but I don't know how
to do this here.

diff --git a/rpython/memory/gctransform/support.py 
b/rpython/memory/gctransform/support.py
--- a/rpython/memory/gctransform/support.py
+++ b/rpython/memory/gctransform/support.py
@@ -73,15 +73,19 @@
 hop.exception_cannot_occur()
 return hop.inputconst(hop.r_result.lowleveltype, hop.s_result.const)
 
+def write(fd, string):
+from rpython.rlib.rposix import c_write
+return c_write(fd, string, len(string))
+
 def ll_call_destructor(destrptr, destr_v, typename):
 try:
 destrptr(destr_v)
 except Exception, e:
 try:
-os.write(2, "a destructor of type ")
-os.write(2, typename)
-os.write(2, " raised an exception ")
-os.write(2, str(e))
-os.write(2, " ignoring it\n")
+write(2, "a destructor of type ")
+write(2, typename)
+write(2, " raised an exception ")
+write(2, str(e))
+write(2, " ignoring it\n")
 except:
 pass
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: tweak the regexp to recognize also "#define FOO" with no value specified.

2014-12-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r187:31b44d824886
Date: 2014-12-06 18:03 +0100
http://bitbucket.org/cffi/creflect/changeset/31b44d824886/

Log:tweak the regexp to recognize also "#define FOO" with no value
specified.

diff --git a/creflect/cparser.py b/creflect/cparser.py
--- a/creflect/cparser.py
+++ b/creflect/cparser.py
@@ -31,7 +31,7 @@
 r_empty_braces = re.compile(r"{(\s*)}") # after comments have been removed
 r_typedef_dotdodot = re.compile(r"\btypedef(\s*)[.][.][.]")
 r_define_var = re.compile(
-r"^[ \t]*#[ \t]*define[ \t]+([A-Za-z_][A-Za-z0-9_]+)[ \t][^\n]+",
+r"^[ \t]*#[ \t]*define[ \t]+([A-Za-z_][A-Za-z0-9_]+)([ \t].*)?$",
 re.MULTILINE)
 
 def remove_comments(csource):
diff --git a/creflect/test/codegen/macro-001.c 
b/creflect/test/codegen/macro-001.c
--- a/creflect/test/codegen/macro-001.c
+++ b/creflect/test/codegen/macro-001.c
@@ -1,5 +1,10 @@
+#define FOO
+#define BAR  (40U + 2)
+
+# 
+
+#undef FOO
 #define FOO  42
-#define BAR  (40U + 2)
 
 # 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: Calling function pointer cdata objects. Works only for types that have

2014-12-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r188:13d44f67603a
Date: 2014-12-06 19:34 +0100
http://bitbucket.org/cffi/creflect/changeset/13d44f67603a/

Log:Calling function pointer cdata objects. Works only for types that
have been declared in the .crx, but without any libffi dependency.

diff --git a/zeffir/builder.c b/zeffir/builder.c
--- a/zeffir/builder.c
+++ b/zeffir/builder.c
@@ -160,6 +160,7 @@
 
 static _crx_type_t *_zef_function(_crx_builder_t *cb, _crx_type_t *ret,
   _crx_qual_type args[], int nargs,
+  _crx_trampoline1_fn trampl,
   int dotdotdot)
 {
 if (PyErr_Occurred())
@@ -223,12 +224,16 @@
 
 ct->ct_size = -1;
 ct->ct_flags = CT_FUNCTION;
-/* XXX more... */
 
 put_cached_type(get_types_dict(cb), name_obj, ct);
 
  done:
 Py_DECREF(name_obj);
+
+if (ct->ct_stuff == NULL && trampl != NULL && !PyErr_Occurred()) {
+assert(!dotdotdot);   /* should have 'trampl == NULL' in this case */
+ct->ct_stuff = make_func_support(ret, args, nargs, trampl, 0);
+}
 return ct;
 }
 
@@ -236,7 +241,7 @@
   _crx_qual_type args[], int nargs,
   _crx_trampoline1_fn trampl)
 {
-return _zef_function(cb, ret, args, nargs, 0);
+return _zef_function(cb, ret, args, nargs, trampl, 0);
 }
 
 static _crx_type_t *zef_get_ellipsis_function_type(_crx_builder_t *cb,
@@ -244,7 +249,7 @@
_crx_qual_type args[],
int nargs)
 {
-return _zef_function(cb, ret, args, nargs, 1);
+return _zef_function(cb, ret, args, nargs, NULL, 1);
 }
 
 static CTypeDescrObject *fetch_pointer_type(PyObject *types_dict,
@@ -517,7 +522,8 @@
 if (interned_fields == NULL)
 return;
 
-previous = (CFieldObject **)&ct->ct_extra;
+assert(ct->ct_fields == NULL);
+previous = &ct->ct_fields;
 
 for (i = 0; i < nfields; i++) {
 _crx_field_t *f = &fields[i];
diff --git a/zeffir/cdata.c b/zeffir/cdata.c
--- a/zeffir/cdata.c
+++ b/zeffir/cdata.c
@@ -638,7 +638,7 @@
 if (PyList_Check(init) || PyTuple_Check(init)) {
 PyObject **items = PySequence_Fast_ITEMS(init);
 Py_ssize_t i, n = PySequence_Fast_GET_SIZE(init);
-CFieldObject *cf = (CFieldObject *)ct->ct_extra;
+CFieldObject *cf = ct->ct_fields;
 
 for (i=0; izfs_nargs;
 Py_ssize_t actualnargs;
 void *llargs[nargs];
@@ -123,8 +123,8 @@
 if (actualnargs != nargs) {
 if (!PyErr_Occurred())
 PyErr_Format(PyExc_TypeError,
- "'%s()' expected %d arguments, but got %zd",
- zfs->zfs_md.ml_name, nargs, actualnargs);
+ "'%s' expected %d arguments, but got %zd",
+ funcname, nargs, actualnargs);
 return NULL;
 }
 
@@ -165,7 +165,14 @@
 lloffset += ct->ct_size;
 }
 
-zfs->zfs_trampl(llargs, llbuffer);
+if (func == NULL) {
+assert(zfs->zfs_md.ml_name != NULL);
+((_crx_trampoline0_fn)zfs->zfs_trampl)(llargs, llbuffer);
+}
+else {
+assert(zfs->zfs_md.ml_name == NULL);
+((_crx_trampoline1_fn)zfs->zfs_trampl)(func, llargs, llbuffer);
+}
 
 if (returns_void) {
 Py_INCREF(Py_None);
@@ -174,21 +181,61 @@
 return convert_to_object(llbuffer, zfs->zfs_ret);
 }
 
-static PyObject *make_builtin_func(PyObject *libname_obj,
-   const char *funcname, _crx_type_t *ret,
+static PyObject *zfs_call(PyObject *self, PyObject *args)
+{
+ZefFuncSupportObject *zfs = (ZefFuncSupportObject *)self;
+return common_call(zfs, args, NULL, zfs->zfs_md.ml_name);
+}
+
+static PyObject*cdata_call(CDataObject *cd, PyObject *args, PyObject *kwds)
+{
+CTypeDescrObject *ct = cd->c_type->ct_itemdescr;
+ZefFuncSupportObject *zfs;
+
+if (!(cd->c_type->ct_flags & CT_POINTER) || !(ct->ct_flags & CT_FUNCTION)) 
{
+PyErr_Format(PyExc_TypeError, "cdata '%s' is not callable",
+ cd->c_type->ct_name);
+return NULL;
+}
+
+zfs = (ZefFuncSupportObject *)ct->ct_stuff;
+if (zfs == NULL) {
+PyErr_SetString(ZefError, "cdata '%s' cannot be called, because no "
+"wrapper was generated for functions of this type ");
+return NULL;
+}
+
+if (kwds != NULL && PyDict_Size(kwds) != 0) {
+PyErr_SetString(PyExc_TypeError,
+"cdata function pointers cannot be called with keyword arguments");
+return NULL;
+}
+if (cd->c_data == NULL) {
+PyErr_SetString(PyExc_RuntimeError, "cannot call NULL cdata");
+return NULL;
+}
+
+return common_call(zfs, args, cd->c_data, cd->c_type->ct_name);
+}
+
+static PyObject *make_func_support(_crx_type_t *ret,

[pypy-commit] creflect default: fix asserts

2014-12-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r189:08d9551d66e1
Date: 2014-12-06 19:42 +0100
http://bitbucket.org/cffi/creflect/changeset/08d9551d66e1/

Log:fix asserts

diff --git a/zeffir/builder.c b/zeffir/builder.c
--- a/zeffir/builder.c
+++ b/zeffir/builder.c
@@ -522,7 +522,6 @@
 if (interned_fields == NULL)
 return;
 
-assert(ct->ct_fields == NULL);
 previous = &ct->ct_fields;
 
 for (i = 0; i < nfields; i++) {
diff --git a/zeffir/cdata.c b/zeffir/cdata.c
--- a/zeffir/cdata.c
+++ b/zeffir/cdata.c
@@ -781,6 +781,7 @@
 return 0;
 }
 if (ct->ct_flags & (CT_STRUCT|CT_UNION)) {
+assert(ct->ct_size >= 0);
 
 if (CData_Check(init)) {
 if (((CDataObject *)init)->c_type == ct && ct->ct_size >= 0) {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: port more from _cffi_backend

2014-12-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r190:4f6dbe2e4bdc
Date: 2014-12-06 20:11 +0100
http://bitbucket.org/cffi/creflect/changeset/4f6dbe2e4bdc/

Log:port more from _cffi_backend

diff --git a/zeffir/builder.c b/zeffir/builder.c
--- a/zeffir/builder.c
+++ b/zeffir/builder.c
@@ -224,15 +224,21 @@
 
 ct->ct_size = -1;
 ct->ct_flags = CT_FUNCTION;
+ct->ct_stuff = make_func_support(ret, args, nargs, dotdotdot, 0);
+if (ct->ct_stuff == NULL) {
+Py_DECREF(ct);
+ct = NULL;
+goto done;
+}
 
 put_cached_type(get_types_dict(cb), name_obj, ct);
 
  done:
 Py_DECREF(name_obj);
 
-if (ct->ct_stuff == NULL && trampl != NULL && !PyErr_Occurred()) {
+if (!PyErr_Occurred() && trampl != NULL) {
 assert(!dotdotdot);   /* should have 'trampl == NULL' in this case */
-ct->ct_stuff = make_func_support(ret, args, nargs, trampl, 0);
+provide_trampoline(ct->ct_stuff, trampl);
 }
 return ct;
 }
diff --git a/zeffir/cdata.c b/zeffir/cdata.c
--- a/zeffir/cdata.c
+++ b/zeffir/cdata.c
@@ -1903,3 +1903,40 @@
  Py_TYPE(ob)->tp_name, ct->ct_name);
 return NULL;
 }
+
+static PyObject *get_field_name(CTypeDescrObject *ct, CFieldObject *cf)
+{
+Py_ssize_t i = 0;
+PyObject *d_key, *d_value;
+while (PyDict_Next(ct->ct_stuff, &i, &d_key, &d_value)) {
+if (d_value == (PyObject *)cf)
+return d_key;
+}
+Py_FatalError("_cffi_backend: get_field_name()");
+return NULL;
+}
+
+static PyObject *cstructtype_getfields(CTypeDescrObject *ct)
+{
+if (ct->ct_size >= 0) {
+CFieldObject *cf;
+PyObject *res = PyList_New(0);
+if (res == NULL)
+return NULL;
+for (cf = ct->ct_fields; cf != NULL; cf = cf->cf_next) {
+PyObject *o = PyTuple_Pack(2, get_field_name(ct, cf),
+   (PyObject *)cf);
+int err = (o != NULL) ? PyList_Append(res, o) : -1;
+Py_XDECREF(o);
+if (err < 0) {
+Py_DECREF(res);
+return NULL;
+}
+}
+return res;
+}
+else {
+Py_INCREF(Py_None);
+return Py_None;
+}
+}
diff --git a/zeffir/cfunc.c b/zeffir/cfunc.c
--- a/zeffir/cfunc.c
+++ b/zeffir/cfunc.c
@@ -2,7 +2,12 @@
 typedef struct {
 PyObject_HEAD
 
+/* note that 'zfs_trampl' is either a '_crx_trampoline0_fn' or a
+   '_crx_trampoline1_fn', depending on how the ZefFuncSupportObject
+   is going to be used.
+*/
 int zfs_nargs;
+int zfs_dotdotdot;
 void   *zfs_trampl;
 PyMethodDef zfs_md;
 size_t  zfs_size_args;
@@ -199,7 +204,7 @@
 }
 
 zfs = (ZefFuncSupportObject *)ct->ct_stuff;
-if (zfs == NULL) {
+if (zfs->zfs_trampl == NULL) {
 PyErr_SetString(ZefError, "cdata '%s' cannot be called, because no "
 "wrapper was generated for functions of this type ");
 return NULL;
@@ -220,12 +225,8 @@
 
 static PyObject *make_func_support(_crx_type_t *ret,
_crx_qual_type args[], int nargs,
-   void *trampl, size_t extra_alloc)
+   int dotdotdot, size_t extra_alloc)
 {
-/* note that 'trampl' is either a '_crx_trampoline0_fn' or a
-   '_crx_trampoline1_fn', depending on how the ZefFuncSupportObject
-   is going to be used.
-*/
 int i;
 size_t size = (sizeof(ZefFuncSupportObject)
+ (nargs - 1) * sizeof(CTypeDescrObject *)
@@ -236,8 +237,9 @@
 PyObject_Init((PyObject *)zfs, &ZefFuncSupport_Type);
 
 memset(&zfs->zfs_md, 0, sizeof(PyMethodDef));
+zfs->zfs_trampl = NULL;
 zfs->zfs_nargs = nargs;
-zfs->zfs_trampl = trampl;
+zfs->zfs_dotdotdot = dotdotdot;
 zfs->zfs_ret = ret;
 Py_INCREF(ret);
 
@@ -258,6 +260,13 @@
 return (PyObject *)zfs;
 }
 
+static void provide_trampoline(PyObject *zfs, void *trampl)
+{
+if (((ZefFuncSupportObject *)zfs)->zfs_trampl == NULL) {
+((ZefFuncSupportObject *)zfs)->zfs_trampl = trampl;
+}
+}
+
 static PyObject *make_builtin_func(PyObject *libname_obj,
const char *funcname, _crx_type_t *ret,
_crx_qual_type args[], int nargs,
@@ -265,11 +274,13 @@
 {
 char *p;
 ZefFuncSupportObject *zfs;
-zfs = (ZefFuncSupportObject *)make_func_support(ret, args, nargs, trampl,
+zfs = (ZefFuncSupportObject *)make_func_support(ret, args, nargs, 0,
 strlen(funcname) + 1);
 if (zfs == NULL)
 return NULL;
 
+zfs->zfs_trampl = trampl;
+
 p = (char *)(zfs->zfs_args + nargs);
 zfs->zfs_md.ml_name = strcpy(p, funcname);
 zfs->zfs_md.ml_meth = &zfs_call;
@@ -281,3 +292,33 @@
 Py_DECREF(zfs);
 return res;
 }
+
+static PyObj

[pypy-commit] pypy default: adjust test_zjit func name for clarity

2014-12-06 Thread bdkearns
Author: Brian Kearns 
Branch: 
Changeset: r74852:b797c990f775
Date: 2014-12-06 15:03 -0500
http://bitbucket.org/pypy/pypy/changeset/b797c990f775/

Log:adjust test_zjit func name for clarity

diff --git a/pypy/module/micronumpy/compile.py 
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -33,9 +33,9 @@
 pass
 
 
-SINGLE_ARG_FUNCTIONS = ["sum", "prod", "max", "min", "all", "any", "xor",
+SINGLE_ARG_FUNCTIONS = ["sum", "prod", "max", "min", "all", "any",
 "unegative", "flat", "tostring", "count_nonzero",
-"argsort", "cumsum"]
+"argsort", "cumsum", "logical_xor_reduce"]
 TWO_ARG_FUNCTIONS = ["dot", 'take', 'searchsorted']
 TWO_ARG_FUNCTIONS_OR_NONE = ['view', 'astype']
 THREE_ARG_FUNCTIONS = ['where']
@@ -561,9 +561,9 @@
 w_res = arr.descr_all(interp.space)
 elif self.name == "cumsum":
 w_res = arr.descr_cumsum(interp.space)
-elif self.name == "xor":
-xor = ufuncs.get(interp.space).logical_xor
-w_res = xor.reduce(interp.space, arr, None)
+elif self.name == "logical_xor_reduce":
+logical_xor = ufuncs.get(interp.space).logical_xor
+w_res = logical_xor.reduce(interp.space, arr, None)
 elif self.name == "unegative":
 neg = ufuncs.get(interp.space).negative
 w_res = neg.call(interp.space, [arr])
diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -416,7 +416,7 @@
 def define_logical_xor_reduce():
 return """
 a = [1,1,1,1,1,1,1,1]
-xor(a)
+logical_xor_reduce(a)
 """
 
 def test_logical_xor_reduce(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: enums

2014-12-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r192:d43293d10be7
Date: 2014-12-06 21:40 +0100
http://bitbucket.org/cffi/creflect/changeset/d43293d10be7/

Log:enums

diff --git a/creflect/cparser.py b/creflect/cparser.py
--- a/creflect/cparser.py
+++ b/creflect/cparser.py
@@ -256,7 +256,7 @@
 
 def get_struct_union_enum_type(self, kind, type, approx_name=None):
 name = type.name or approx_name
-if not name or name.startswith('$$$'):
+if kind != 'enum' and (not name or name.startswith('$$$')):
 self.parse_error("not implemented: anonymous 'struct' elsewhere "
  "than in 'typedef struct { ... } typename;' or "
  "'typedef struct { ... } *typename;'", type)
@@ -270,7 +270,7 @@
 if kind == 'struct' or kind == 'union':
 typedecl = model.StructOrUnionDecl(result)
 elif kind == 'enum':
-typedecl = XXX
+typedecl = model.EnumDecl(result)
 else:
 raise AssertionError("kind = %r" % (kind,))
 self.struct_union_enum_decl[key] = typedecl
@@ -280,8 +280,12 @@
 #
 # is there a 'type.decls'?  If yes, then this is the place in the
 # C sources that declare the fields.
-if type.decls is not None:
-self.add_fields_declaration(typedecl, type.decls)
+if kind == 'struct' or kind == 'union':
+if type.decls is not None:
+self.add_fields_declaration(typedecl, type.decls)
+if kind == 'enum':
+if type.values is not None:
+self.add_enum_values_declaration(typedecl, type.values)
 if must_add:
 self.declarations.append(typedecl)
 return result
@@ -312,6 +316,13 @@
 raise NotImplementedError("%s: using both bitfields and '...;'"
   % (tp,))
 
+def add_enum_values_declaration(self, typedecl, values):
+for enumerator in values.enumerators:
+self.declarations.append(
+model.ConstDecl(enumerator.name,
+model.QualType(model.int_type)))
+typedecl.complete = True
+
 def parse_constant(self, constant):
 return int(constant.value)   # xxx
 
diff --git a/creflect/creflect_debug_print.c b/creflect/creflect_debug_print.c
--- a/creflect/creflect_debug_print.c
+++ b/creflect/creflect_debug_print.c
@@ -202,7 +202,8 @@
 static void tst_complete_enum(_crx_builder_t *cb, _crx_type_t *t,
   _crx_type_t *inttype)
 {
-abort();
+assert(memcmp(t->text, "ENUM ", 5) == 0);
+printf("%s = %s\n", t->text, inttype->text);
 }
 
 static void tst_define_type(_crx_builder_t *cb, const char *name,
diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -249,6 +249,8 @@
 block.writeline('cb->define_num_const(cb, "%s", %s, &v);' % (
 varname, t1))
 
+int_type = PrimitiveType('int')
+
 
 class FunctionType(BaseType):
 _attrs_ = ('args', 'result', 'ellipsis')
@@ -730,6 +732,40 @@
 funcblock.writeline(' %s, %d);' % (d1, len(self.fldnames)))
 
 
+class EnumDecl(object):
+
+def __init__(self, type):
+self.type = type
+self.complete = False
+
+def write_declaration(self, funcblock):
+if not self.complete or self.type.name is None:
+return # opaque
+tp = "%s %s" % (self.type.kind, self.type.name)
+block = CodeBlock(funcblock)
+if not self.type.name.startswith('$'):
+realtp = tp
+else:
+realtp = self.type.name[1:]
+if not realtp.startswith('$'):
+expr = '(%s)-1' % realtp
+else:
+# xxx obscure case: "typedef enum e *t;"
+ptrtp = realtp[1:]
+assert not ptrtp.startswith('$')
+block.writedecl("%s p1;" % (ptrtp,))
+block.writedecl("char b[sizeof(*p1)];")
+block.writeline("memset(b, -1, sizeof(b));")
+block.writeline("p1 = (%s)b;" % (ptrtp,))
+expr = '*p1'
+#
+t1 = self.type.get_type_var(block)
+t2 = block.write_crx_type_var('_CRX_INT_TYPE(cb, %s, _crx_sc_int)' %
+  (expr,))
+block.writeline('cb->complete_enum(cb, %s, %s);' % (t1, t2))
+funcblock.write_subblock(block)
+
+
 class TypeDefDecl(object):
 def __init__(self, name, qualtype):
 self.name = name
diff --git a/creflect/test/codegen/enum-001.c b/creflect/test/codegen/enum-001.c
new file mode 100644
--- /dev/null
+++ b/creflect/test/codegen/enum-001.c
@@ -0,0 +1,13 @@
+typedef enum myname_e foo_t;// unusual, but valid C
+
+# 
+
+void testenum_001(_crx_builder_t *cb)
+{
+_crx_type_t *t1;
+{
+t1 = cb->get_enum_type(cb, "myname_e

[pypy-commit] creflect default: Declare opaque structs

2014-12-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r191:1471bfadbc0f
Date: 2014-12-06 20:25 +0100
http://bitbucket.org/cffi/creflect/changeset/1471bfadbc0f/

Log:Declare opaque structs

diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -659,6 +659,8 @@
 self.fldbitsize = None
 
 def write_declaration(self, funcblock):
+if self.fldnames is None:
+return # opaque
 tp = "%s %s" % (self.type.kind, self.type.name)
 if not self.type.name.startswith('$'):
 realtp = tp
diff --git a/creflect/test/codegen/struct-007.c 
b/creflect/test/codegen/struct-007.c
new file mode 100644
--- /dev/null
+++ b/creflect/test/codegen/struct-007.c
@@ -0,0 +1,13 @@
+typedef struct mystruct_s foo_t;
+
+# 
+
+void teststruct_007(_crx_builder_t *cb)
+{
+_crx_type_t *t1;
+{
+t1 = cb->get_struct_type(cb, "mystruct_s");
+cb->define_type(cb, "foo_t", t1, 0);
+#expect TYPEDEF foo_t = STRUCT mystruct_s
+}
+}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Support building on systems with no ssl3

2014-12-06 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r74853:de9938702e0c
Date: 2014-12-06 20:10 -0800
http://bitbucket.org/pypy/pypy/changeset/de9938702e0c/

Log:Support building on systems with no ssl3

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -52,7 +52,8 @@
 
 if not OPENSSL_NO_SSL2:
 constants["PROTOCOL_SSLv2"]  = PY_SSL_VERSION_SSL2
-constants["PROTOCOL_SSLv3"]  = PY_SSL_VERSION_SSL3
+if not OPENSSL_NO_SSL3:
+constants["PROTOCOL_SSLv3"]  = PY_SSL_VERSION_SSL3
 constants["PROTOCOL_SSLv23"] = PY_SSL_VERSION_SSL23
 constants["PROTOCOL_TLSv1"]  = PY_SSL_VERSION_TLS1
 
@@ -656,7 +657,7 @@
 # set up context
 if protocol == PY_SSL_VERSION_TLS1:
 method = libssl_TLSv1_method()
-elif protocol == PY_SSL_VERSION_SSL3:
+elif protocol == PY_SSL_VERSION_SSL3 and not OPENSSL_NO_SSL3:
 method = libssl_SSLv3_method()
 elif protocol == PY_SSL_VERSION_SSL2 and not OPENSSL_NO_SSL2:
 method = libssl_SSLv2_method()
diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
--- a/rpython/rlib/ropenssl.py
+++ b/rpython/rlib/ropenssl.py
@@ -68,6 +68,7 @@
 SSLEAY_VERSION = rffi_platform.DefinedConstantString(
 "SSLEAY_VERSION", "SSLeay_version(SSLEAY_VERSION)")
 OPENSSL_NO_SSL2 = rffi_platform.Defined("OPENSSL_NO_SSL2")
+OPENSSL_NO_SSL3 = rffi_platform.Defined("OPENSSL_NO_SSL3")
 SSL_FILETYPE_PEM = rffi_platform.ConstantInteger("SSL_FILETYPE_PEM")
 SSL_OP_ALL = rffi_platform.ConstantInteger("SSL_OP_ALL")
 SSL_OP_NO_SSLv2 = rffi_platform.ConstantInteger("SSL_OP_NO_SSLv2")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit