swig/Lib/python/carrays.i
Stefan Zager 3d444101d1 A slew of changes based on William Fulton's code review.
- Fixed naming conventions; SwigPyBuiltin is used a lot
- Removed use of std::vector
- builtin.swg isn't included if -builtin isn't specified
- Changed many feature names to use a "python:" prefix
- Eliminated static vars in std_pair.i
- Eliminated C++-style comments (//)
- Enabled autodoc and docstring with -builtin
- Fixed non-ansi generated C code
- Detect and complain if two incompatible swig modules are loaded
- Removed argcargvtest_runme3.py, and fixed argcargvtest_runme.py
  so that 2to3 handles it better
- Removed anonymous namespaces
- Eliminated builtin_init typemaps; consolidated functionality into
  SWIG_Python_NewPointerObj
- Eliminate printf warnings from %U conversion character by switching
  to %S, which works just as well
- Fixed li_std_set_runme.py for python3, which returns set members in
  a different order from python2





git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12562 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2011-03-29 06:57:02 +00:00

53 lines
937 B
OpenEdge ABL

%define %array_class(TYPE,NAME)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "sq_item", functype="ssizeargfunc") NAME::__getitem__;
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__;
%inline %{
typedef struct NAME {
TYPE *el;
} NAME;
%}
%extend NAME {
NAME(size_t nelements) {
NAME *arr = %new_instance(NAME);
arr->el = %new_array(nelements, TYPE);
return arr;
}
~NAME() {
%delete_array(self->el);
%delete(self);
}
TYPE __getitem__(size_t index) {
return self->el[index];
}
void __setitem__(size_t index, TYPE value) {
self->el[index] = value;
}
TYPE * cast() {
return self->el;
}
static NAME *frompointer(TYPE *t) {
return %reinterpret_cast(t, NAME *);
}
};
%types(NAME = TYPE);
#else
%array_class_wrap(TYPE,NAME,__getitem__,__setitem__)
#endif
%enddef
%include <typemaps/carrays.swg>