perl-ctypes:perl-ctypes.git
11 years agoMerge branch 'master' of gitorious.org:perl-ctypes/perl-ctypes v0.002
Reini Urban [Tue, 11 Jan 2011 17:39:43 +0000 (18:39 +0100)]
Merge branch 'master' of gitorious.org:perl-ctypes/perl-ctypes

11 years agoConsolidating Simple type tests into t/Simple.t
Ryan Jendoubi [Wed, 29 Dec 2010 05:41:54 +0000 (05:41 +0000)]
Consolidating Simple type tests into t/Simple.t

Will have cmd line options: --all, --c_short, --c_int etc.
rurban tells me pack() is knowingly deviates from C overflow
behaviour. One less thing to worry about getting 100% right now.

modified:   lib/Ctypes/Type.pm
new file:   t/Simple.t
deleted:    t/limits_test.t
deleted:    t/pack_overflow.t

11 years agoPlodding on with tests
Ryan Jendoubi [Tue, 28 Dec 2010 02:25:50 +0000 (02:25 +0000)]
Plodding on with tests

Unsigned integer wrap-around by pack() appears irregular. Looking
into it.

Also, since hook_out performs chr() on a c_char's value, ++ might
need overloaded... but I'm not sure how to make it a special
overload just for that type.

modified:   Makefile.PL
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Simple.pm
modified:   t/Simple_int.t
new file:   t/Simple_long.t
modified:   t/Simple_short.t
new file:   t/Simple_uint.t
new file:   t/Simple_ulong.t
modified:   t/Simple_ushort.t
new file:   t/limits_test.t
new file:   t/pack_overflow.t

11 years agoNew tests, new testing function perl_data_validation
Ryan Jendoubi [Mon, 15 Nov 2010 13:17:43 +0000 (13:17 +0000)]
New tests, new testing function

Complete tests for [u]byte, [u]char, [u]short.

Large range of [u]int required writing Ctypes::Util::create_range
to easily make ranges of testing values.

Will also require CTYPES_TEST_FULL env arg for tests to really
test full value range of variables, or whatever standard release
testing flag is.

11 years agoTests for c_uchar
Ryan Jendoubi [Sun, 31 Oct 2010 02:39:19 +0000 (02:39 +0000)]
Tests for c_uchar

modified:   lib/Ctypes/Type.pm
modified:   t/Simple_char.t
new file:   t/Simple_uchar.t

11 years agoMore new tests (c_byte, c_ubyte)
Ryan Jendoubi [Sun, 17 Oct 2010 08:51:32 +0000 (09:51 +0100)]
More new tests (c_byte, c_ubyte)

New XS function (Ctypes::Test::is_a_number) which simply checks
the SvIOK($arg) || SvNOK($arg). Will probably encounter the
same problem later about the values returned by Ctypes objects
not having the public flags set, but that's a problem with the
output so should be fixed at that point.

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Simple.pm
modified:   t/Simple_byte.t
new file:   t/Simple_char.t
new file:   t/Simple_ubyte.t

11 years agohook_* proof-of-concept working for type c_byte
Ryan Jendoubi [Tue, 12 Oct 2010 23:21:27 +0000 (00:21 +0100)]
hook_* proof-of-concept working for type c_byte

. All $_types now have sizecodes and packcodes, since these can
  be different from their typecodes. Since our range of Types
  don't reflect only those in C or Python's Ctypes, typecodes
  are really only for use within Ctypes identify them.

. All $_types need an anonymous sub under the hash key 'hook_in'.
  This takes one argument, the value passed to be STOREd, and
  performs whatever validations necessary. It returns a list of
  two scalars: an indicator of invalidity (must be undef if arg
  was valid) and a 'sanitized' form of the arg - basically, do
  whatever can be done to make the input valid for the type.
  This will be STOREd instead of the original input. The original
  input is stored in $object->{_input} though, for use later by
  hook_out if needs be.

. $_types /can/ have a hook_out, but it's not compulsory. This
  can take two arguments: the STOREd $val, and the $object itself.
  The latter can be used to ascertain information which might
  affect whether anything special needs to be done to the value
  before output (e.g., whether the {_input} was numeric or string).

. Type::Simple objects now have size(), sizecode(), packcode() and
  validate() methods (can you believe they didn't implement size()
  before?? @_@). The validate() is the same as used by STORE. It
  can be used if you happen to need to know if certain input is
  invalid for a given type without squashing its current contents.

Now all the rest of the types need their hooks and test written.
Onward!

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Simple.pm
modified:   t/Simple_byte.t

11 years agoMoving development to new branch
Ryan Jendoubi [Mon, 11 Oct 2010 15:24:23 +0000 (16:24 +0100)]
Moving development to new branch

11 years agoUse of qw(...) as parentheses is deprecated at inc/Devel/CheckLib.pm line 164
Reini Urban [Fri, 8 Oct 2010 07:50:56 +0000 (09:50 +0200)]
Use of qw(...) as parentheses is deprecated at inc/Devel/CheckLib.pm line 164

11 years agoMerge branch 'master' of http://git.gitorious.org/perl-ctypes/perl-ctypes
Reini Urban [Fri, 8 Oct 2010 06:55:40 +0000 (08:55 +0200)]
Merge branch 'master' of git.gitorious.org/perl-ctypes/perl-ctypes

11 years agoFinish Unions
Ryan Jendoubi [Thu, 16 Sep 2010 09:54:56 +0000 (10:54 +0100)]
Finish Unions

Also changed Union.t & Struct.t to show real number of tests (not
mostly in subtests anymore).

modified:   lib/Ctypes/Type/Union.pm
modified:   t/Struct.t
modified:   t/Union.t

11 years agoMerge branch 'unions'
Ryan Jendoubi [Mon, 6 Sep 2010 20:11:10 +0000 (21:11 +0100)]
Merge branch 'unions'

11 years agoUnions work, improvements in Simple, Struct, Field
Ryan Jendoubi [Mon, 6 Sep 2010 20:09:46 +0000 (21:09 +0100)]
Unions work, improvements in Simple, Struct, Field

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Pointer.pm
modified:   lib/Ctypes/Type/Simple.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   lib/Ctypes/Type/Union.pm
modified:   t/Struct.t
modified:   t/Union.t
modified:   t/types.t
modified:   t/win-proto.t

11 years agoMerge changes to Array, Pointer from branch unions
Ryan Jendoubi [Sun, 5 Sep 2010 16:57:08 +0000 (17:57 +0100)]
Merge changes to Array, Pointer from branch unions

modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Pointer.pm

11 years agoFix ->copy method for Arrays, Pointers need tests
Ryan Jendoubi [Sun, 5 Sep 2010 16:50:49 +0000 (17:50 +0100)]
Fix ->copy method for Arrays, Pointers need tests

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Pointer.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   lib/Ctypes/Type/Union.pm
modified:   t/Array.t
modified:   t/Union.t

11 years agoRe-add t/Union.t
Ryan Jendoubi [Sun, 5 Sep 2010 14:28:10 +0000 (15:28 +0100)]
Re-add t/Union.t

new file:   t/Union.t

11 years agoMerge branch 'master' into unions
Ryan Jendoubi [Sun, 5 Sep 2010 14:19:23 +0000 (15:19 +0100)]
Merge branch 'master' into unions

Conflicts:
lib/Ctypes/Type.pm
lib/Ctypes/Type/Union.pm

modified:   Ctypes.xs
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Pointer.pm
modified:   lib/Ctypes/Type/Simple.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   t/Array.t
modified:   t/Pointer.t
modified:   t/Struct.t
deleted:    t/Struct.t_pyguides
deleted:    t/Union.t
modified:   t/pod-coverage.t
modified:   t/t_POINT.pm
modified:   t/types.t

11 years agoFinished basic Struct implementation, tests, docs
Ryan Jendoubi [Sun, 5 Sep 2010 12:41:49 +0000 (13:41 +0100)]
Finished basic Struct implementation, tests, docs

TODO:
  add/remove/splice fields methods
  alignment of parts of structs
  endianness.....

11 years agoLots more work on structs, think it's good now struct_api_change
Ryan Jendoubi [Wed, 1 Sep 2010 12:49:13 +0000 (13:49 +0100)]
Lots more work on structs, think it's good now

General setup now allows assignment and returning of values as
well as returning information about fields.

Next issue is error in alignment I think.

11 years agoWork on Structs
Ryan Jendoubi [Tue, 31 Aug 2010 10:18:59 +0000 (11:18 +0100)]
Work on Structs

Implemented copy() method for all Types (as Structs need their
own copy() of the contents of subclasses' $_fields_).

No good way of using method-style access for Struct members (always
some Perl method names which could hypothetically limit field names
so must use hash-style access ($$struct->{field}).

Now looking at how to return info about fields, so that fields
can know their own name within the struct. Removed tied Field
objects, may reintroduce them in a different way.

11 years agoTests for new Struct API
Ryan Jendoubi [Mon, 23 Aug 2010 23:28:44 +0000 (00:28 +0100)]
Tests for new Struct API

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   t/Struct.t
new file:   t/Struct.t_old
modified:   t/t_POINT.pm

11 years agoMore pod for Pointer.pm
Ryan Jendoubi [Sat, 21 Aug 2010 10:58:30 +0000 (11:58 +0100)]
More pod for Pointer.pm

modified:   lib/Ctypes/Type/Pointer.pm
modified:   t/Pointer.t
modified:   t/pod-coverage.t
modified:   t/types.t

11 years agoMore docs, plus fixed rounding error for integers
Ryan Jendoubi [Mon, 16 Aug 2010 18:39:08 +0000 (19:39 +0100)]
More docs, plus fixed rounding error for integers

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Pointer.pm
modified:   lib/Ctypes/Type/Simple.pm
modified:   t/Array.t
modified:   t/Pointer.t
modified:   t/Struct.t
modified:   t/pod-coverage.t
modified:   t/types.t

11 years agoRemoved unfinished unions from master
Ryan Jendoubi [Mon, 16 Aug 2010 16:44:07 +0000 (17:44 +0100)]
Removed unfinished unions from master

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
deleted:    lib/Ctypes/Type/Union.pm
deleted:    t/Union.t

11 years agoInitial commit for branch unions unions
Ryan Jendoubi [Mon, 16 Aug 2010 16:40:59 +0000 (17:40 +0100)]
Initial commit for branch unions

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Union.pm

11 years agoMany changes
Ryan Jendoubi [Mon, 16 Aug 2010 16:32:30 +0000 (17:32 +0100)]
Many changes

Moved Type::Simple to new file, work on Unions (unfinished)

modified:   Ctypes.xs
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Pointer.pm
new file:   lib/Ctypes/Type/Simple.pm
modified:   lib/Ctypes/Type/Struct.pm
new file:   lib/Ctypes/Type/Union.pm
modified:   t/Array.t
modified:   t/Pointer.t
modified:   t/Struct.t
new file:   t/Union.t
modified:   t/pod-coverage.t
modified:   t/types.t

11 years agoMerge http://git.gitorious.org/perl-ctypes/perl-ctypes
Reini Urban [Mon, 16 Aug 2010 10:16:33 +0000 (12:16 +0200)]
Merge git.gitorious.org/perl-ctypes/perl-ctypes

11 years agoStruct indirection working
Ryan Jendoubi [Sun, 15 Aug 2010 11:50:57 +0000 (12:50 +0100)]
Struct indirection working

modified:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   t/Struct.t

11 years agoMore tightening and tests for Structs
Ryan Jendoubi [Sun, 15 Aug 2010 05:58:16 +0000 (06:58 +0100)]
More tightening and tests for Structs

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Pointer.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   t/Struct.t

11 years agoMore interface trials
Ryan Jendoubi [Sat, 14 Aug 2010 23:17:22 +0000 (00:17 +0100)]
More interface trials

modified:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   t/Struct.t

11 years agoMore work Struct interface
Ryan Jendoubi [Sat, 14 Aug 2010 22:04:12 +0000 (23:04 +0100)]
More work Struct interface

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
new file:   lib/Ctypes/Type/Field.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   t/Struct.t
renamed:    t/Struct.t -> t/Struct.t_pyguides
modified:   t/t_Daffodil.pm
modified:   t/t_Flower.pm
modified:   t/t_POINT.pm

11 years agoSome progress on Structs, instantiation interface
Ryan Jendoubi [Fri, 13 Aug 2010 16:48:28 +0000 (17:48 +0100)]
Some progress on Structs, instantiation interface

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Struct.pm
modified:   t/Struct.t
deleted:    t/Struct.t_
deleted:    t/pod-coverage.t_
new file:   t/t_Daffodil.pm
new file:   t/t_Flower.pm
new file:   t/t_POINT.pm

11 years agoCompleted update of data ownership chaining
Ryan Jendoubi [Fri, 13 Aug 2010 00:02:31 +0000 (01:02 +0100)]
Completed update of data ownership chaining

Today's work was important for moving on to Structs.

The main principle was the same as used in the Python version, of
objects having an _owner attribute set when they become part of a
bigger data structure, like an Array or Struct. When an object
becomes owned by another, the owner will set two attributes in
the owned object:
1) {_owner}, set to the owner object (is undef on instantiation,
   although most tests on it check for truth rather than definedness)
2) {_index}, set to the offset of the owned object's data inside
   the owner object's data, *in bytes*. It is Not an array or
   pseudohash index. It is used in substr operations, so that owned
   objects can check in the owner's data if their data has been
   modified, instead of owners having to repopulate Every owned
   object with data when it is updated (although this is sometimes
   necessary, when an owner's data is updated without an index
   indicating what has changed).

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Pointer.pm
modified:   t/Array.t
modified:   t/Pointer.t
new file:   t/Struct.t

11 years agoMerge branch 'master' of http://git.gitorious.org/perl-ctypes/perl-ctypes
Reini Urban [Thu, 12 Aug 2010 14:07:48 +0000 (16:07 +0200)]
Merge branch 'master' of git.gitorious.org/perl-ctypes/perl-ctypes

11 years agoAdd Devel::CheckLib
Reini Urban [Thu, 12 Aug 2010 14:07:23 +0000 (16:07 +0200)]
Add Devel::CheckLib

11 years agoStarting reorganisation for C::B::C
Ryan Jendoubi [Thu, 12 Aug 2010 10:24:48 +0000 (11:24 +0100)]
Starting reorganisation for C::B::C

Now using Ctypes::Type ABC to track 'owner' objects, data fields

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Pointer.pm
new file:   lib/Ctypes/Type/Struct.pm
new file:   t/Struct.t_

11 years agoFixes and added tests for Pointers
Ryan Jendoubi [Wed, 11 Aug 2010 11:43:07 +0000 (12:43 +0100)]
Fixes and added tests for Pointers

Earstwhile bug in reading from end of data now fixed (I think), but
not sure how to test for it. Also, Test::More's diag() is showing
up strange behaviour; see Pointer.t.

modified:   lib/Ctypes/Type/Pointer.pm
modified:   t/Pointer.t

11 years agoReintroduced enhanced error message
Ryan Jendoubi [Wed, 11 Aug 2010 02:48:55 +0000 (03:48 +0100)]
Reintroduced enhanced error message

modified:   lib/Ctypes/Type/Pointer.pm

11 years agoFixed multiple indirection on Pointers / Arrays
Ryan Jendoubi [Wed, 11 Aug 2010 02:41:40 +0000 (03:41 +0100)]
Fixed multiple indirection on Pointers / Arrays

At the minute, the object that was finally passed must either be
explicitly ->_update_'d, or must be the first used after the
call returns (in which case it updates itself automatically).

This should be made automatic using paramflags.

Alternatively, _as_param_ could take an argument of a reference
to the requesting object, or the place the data will be stored and
worked upon. Then data could be 'chased up' the object chain to
ensure freshness.
Interface should probably be through _update_, with objects free
to use their own internal mechanism to know whether their own
data is fresh (i.e. has it been stored again since it was given
out?).

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   lib/Ctypes/Type/Pointer.pm
modified:   t/Array.t
modified:   t/Pointer.t

11 years agoPointer objects
Ryan Jendoubi [Tue, 10 Aug 2010 22:06:36 +0000 (23:06 +0100)]
Pointer objects

See t/Pointers.t for usage.

In general, '$ptr' for methods on the object and '$$ptr' for using
the pointer behaviour, e.g.

$$ptr[0] = 5;

The notable exception is that pointer arithmetic is done to the
object:

$ptr++;
$ptr->offset(6);

If you do $$ptr++ Ctypes attempts to construct a new pointer to
the numeric representation of the address of the object (I think);
there's a decent error message for this.

modified:   MANIFEST
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
new file:   lib/Ctypes/Type/Pointer.pm
modified:   t/Array.t
new file:   t/Pointer.t

11 years agoLittle modifications
Ryan Jendoubi [Tue, 10 Aug 2010 12:28:30 +0000 (13:28 +0100)]
Little modifications

$simpleType->typecode method now called ->_typecode_, more
  consistent.

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   t/Array.t
modified:   t/types.t

11 years agoMultidimensional arrays
Ryan Jendoubi [Tue, 10 Aug 2010 02:28:40 +0000 (03:28 +0100)]
Multidimensional arrays

Implementing this involved a lot of backtracking and fleshing out
ideas half-implemented before, like the _as_param_ method thing.
All types including arrays must now have an _as_param_ method,
an _update_ method, and a _typecode_. In Ctypes types these are
woven in with FETCH and STORE, but using this standard we *should*
be able to work with user-defined types in calling Functions, etc.

Full write up to follow: API description in docs, technical detail
in blog post.

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   t/Array.t
modified:   t/types.t

11 years agoSubstanitally simplified Types, a la Arrays
Ryan Jendoubi [Mon, 9 Aug 2010 03:54:23 +0000 (04:54 +0100)]
Substanitally simplified Types, a la Arrays

No more $type->val; now it's just $$type (overloaded scalar deref)
Removed code deref, as well as hash (Ctypes users should know what
 they're doing, can blow sh*t up if they want).

modified:   Ctypes.xs
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   t/Array.t
modified:   t/types.t

11 years agoFixed bug with short values in callbacks
Ryan Jendoubi [Sun, 8 Aug 2010 15:30:16 +0000 (16:30 +0100)]
Fixed bug with short values in callbacks

modified:   Ctypes.xs
modified:   t/Array.t
modified:   t/callbacks.t

11 years agoArrays now work as function args (*NB)
Ryan Jendoubi [Sun, 8 Aug 2010 14:18:12 +0000 (15:18 +0100)]
Arrays now work as function args (*NB)

NB: _as_param_ funcs need to return references to the attributes
    containing C data (e.g. {_as_param_}, {_data}, whatever). I
    guess this was obvious but never had to use them before. In
    any case, clients of _as_param_() methods need to be aware
    of that.
Need to find somewhere in the docs for general info on the
  'Ctypes object protocol': _as_param_, _typecode_ and how to
  use them.

modified:   Ctypes.xs
modified:   MANIFEST
modified:   lib/Ctypes/Type/Array.pm
modified:   src/obj_util.c
modified:   t/Array.t

11 years agoBasic Fetch/Store working for Arrays
Ryan Jendoubi [Sun, 8 Aug 2010 11:32:05 +0000 (12:32 +0100)]
Basic Fetch/Store working for Arrays

Passing them into function calls squashes them, however. Need to
revisit Function.pm

modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type/Array.pm
modified:   t/Array.t

11 years agoFirst crack at Array objects
Ryan Jendoubi [Sat, 7 Aug 2010 20:30:31 +0000 (21:30 +0100)]
First crack at Array objects

modified:   MANIFEST
modified:   Makefile.PL
modified:   const-xs.inc
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
new file:   lib/Ctypes/Type/Array.pm
new file:   t/Array.t
modified:   t/types.t

11 years agoFixed limits for float, double & long double types
Ryan Jendoubi [Sat, 7 Aug 2010 17:29:54 +0000 (18:29 +0100)]
Fixed limits for float, double & long double types

Apparently C's < and > operators aren't fullproof. _validate_for_type
was thinking that 0 was smaller than DBL_MIN. Fixed along the lines
of if( (a - b) > DBL_EPSILON ).

modified:   Ctypes.xs

11 years agoMake all attrs unsettable apart from allow_overflo
Ryan Jendoubi [Fri, 6 Aug 2010 18:45:12 +0000 (19:45 +0100)]
Make all attrs unsettable apart from allow_overflo

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoHandle numeric casting of utf8 chars
Ryan Jendoubi [Fri, 6 Aug 2010 13:31:00 +0000 (14:31 +0100)]
Handle numeric casting of utf8 chars

Only done for c_int, other numeric types are TODO.
Relies on SvUTF8, which seems only to be set when when 'use utf8'
  in user script. Can't see another way around that...

modified:   Ctypes.xs
modified:   t/types.t

11 years agoMerge branch 'types_obj'
Ryan Jendoubi [Fri, 6 Aug 2010 12:00:28 +0000 (13:00 +0100)]
Merge branch 'types_obj'

11 years agoMake _cast for 'c' and 'C' more robust
Ryan Jendoubi [Fri, 6 Aug 2010 10:36:51 +0000 (11:36 +0100)]
Make _cast for 'c' and 'C' more robust

Still confused about "Argument 'Y' isn't numeric in pack" error
for these types. Should we be using 'A'?

modified:   Ctypes.xs

11 years agoTest fix: change checking access for Type attrs
Ryan Jendoubi [Fri, 6 Aug 2010 08:38:05 +0000 (09:38 +0100)]
Test fix: change checking access for Type attrs

Necessary after moving _make_arrayref and _check_invalid_types
to Ctypes.pm

modified:   lib/Ctypes/Type.pm
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Function.pm

11 years agoSeparated out _make_types_arrayref
Ryan Jendoubi [Thu, 5 Aug 2010 19:27:08 +0000 (20:27 +0100)]
Separated out _make_types_arrayref

Needed _make_arrayref logic for Ctypes::Array()
Other func is _check_invalid_types (named that way for a reason)

modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm

11 years agoFixed _valid_for_type for s and S types
Ryan Jendoubi [Thu, 5 Aug 2010 08:25:53 +0000 (09:25 +0100)]
Fixed _valid_for_type for s and S types

modified:   Ctypes.xs

11 years agoAdd _valid_for_type for c_void, Ct::Type::_types()
Ryan Jendoubi [Thu, 5 Aug 2010 08:07:48 +0000 (09:07 +0100)]
Add _valid_for_type for c_void, Ct::Type::_types()

_types() simply returns $_types hashref (_perltypes or _pytypes)

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm

11 years agoWe can haz Types.
Ryan Jendoubi [Thu, 5 Aug 2010 07:51:35 +0000 (08:51 +0100)]
We can haz Types.

All current tests passing. More to come.

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm
modified:   t/002-Function.t

11 years agoTypes parameterised, allllmost finished
Ryan Jendoubi [Thu, 5 Aug 2010 06:07:41 +0000 (07:07 +0100)]
Types parameterised, allllmost finished

. $type->name doesn't seem to work
. Warning about packed value not numeric for char type
. Need lots more tests for the various types

modified:   Ctypes.xs
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm
modified:   src/obj_util.c
modified:   t/002-Function.t
modified:   t/types.t
modified:   t/win-proto.t

11 years agoFixed Ctypes::Type::value broken last commit
Ryan Jendoubi [Wed, 4 Aug 2010 15:20:10 +0000 (16:20 +0100)]
Fixed Ctypes::Type::value broken last commit

Also progress on _cast, _valid_for_type.

...Yea, that's right, segfaults are progress. "Wanna fight about it?"

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm

11 years agoFilled out Ctypes::_cast, not yet tested
Ryan Jendoubi [Wed, 4 Aug 2010 13:13:46 +0000 (14:13 +0100)]
Filled out Ctypes::_cast, not yet tested

Need to finish _valid_for_type first, and parameterize generation
of types to have different type objects to test with.

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm

11 years agoAdd tests for ->typecode and ->_data accessors
Ryan Jendoubi [Tue, 3 Aug 2010 17:42:19 +0000 (18:42 +0100)]
Add tests for ->typecode and ->_data accessors

modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoMerge branch 'callbacks'
Ryan Jendoubi [Tue, 3 Aug 2010 17:24:00 +0000 (18:24 +0100)]
Merge branch 'callbacks'

11 years agoFixed $typeobj++ and --, plus tests
Ryan Jendoubi [Tue, 3 Aug 2010 17:18:27 +0000 (18:18 +0100)]
Fixed $typeobj++ and --, plus tests

Tests before weren't showing up that mutator operators weren't
working. How embarassing~

Also made Type object attributes inaccessible from outside the
Ctypes package - users must use the approved accessors.

modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years ago$typeobj->val works as lvalue, updated tests
Ryan Jendoubi [Tue, 3 Aug 2010 13:08:52 +0000 (14:08 +0100)]
$typeobj->val works as lvalue, updated tests

Done by tie'ing $self->{val}.

modified:   lib/Ctypes/Type.pm
modified:   t/002-Function.t
modified:   t/pod-coverage.t
modified:   t/types.t

11 years agoType object attribute name changes
Ryan Jendoubi [Sun, 1 Aug 2010 17:03:36 +0000 (18:03 +0100)]
Type object attribute name changes

data->_as_param_, typecode->_typecode_

Simplifies code by allowing Type objects to be queried the same
way as user-defined types/objects (see _make_types_arrayref, esp.
l450+)

modified:   Ctypes.xs
modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm

11 years agoargtypes allow objs, no longer convert->typecodes
Ryan Jendoubi [Sun, 1 Aug 2010 16:42:43 +0000 (17:42 +0100)]
argtypes allow objs, no longer convert->typecodes

Renamed Type overload functions to be consistent with Function.

* Overloaded Types may make internal functions involving argtypes
  more tricky.

modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm
modified:   t/callbacks.t
modified:   t/types.t

11 years agot/types.t passes as much as with old call logic
Ryan Jendoubi [Sun, 1 Aug 2010 10:39:17 +0000 (11:39 +0100)]
t/types.t passes as much as with old call logic

Now back to working on Types!

modified:   Ctypes.xs
modified:   src/obj_util.c

11 years agot/callbacks.t passing with new call code
Ryan Jendoubi [Sun, 1 Aug 2010 10:00:18 +0000 (11:00 +0100)]
t/callbacks.t passing with new call code

modified:   lib/Ctypes/Function.pm

11 years agoBasic tests passing with new call logic
Ryan Jendoubi [Sun, 1 Aug 2010 09:46:18 +0000 (10:46 +0100)]
Basic tests passing with new call logic

Failing: callbacks, types

modified:   Ctypes.xs
modified:   lib/Ctypes/Function.pm
modified:   src/obj_util.c

11 years agoFix more mistakes, now C actually compiles
Ryan Jendoubi [Thu, 29 Jul 2010 21:35:29 +0000 (22:35 +0100)]
Fix more mistakes, now C actually compiles

modified:   Ctypes.xs
modified:   src/obj_util.c
modified:   src/util.c

11 years agoFixed lots of silly mistakes
Ryan Jendoubi [Thu, 29 Jul 2010 07:56:24 +0000 (08:56 +0100)]
Fixed lots of silly mistakes

Sometimes one forgets to check things when finishing up around 5am.

modified:   Ctypes.xs
modified:   MANIFEST
modified:   src/obj_util.c

11 years agoFinished new _call (can't test yet)
Ryan Jendoubi [Wed, 28 Jul 2010 04:30:04 +0000 (05:30 +0100)]
Finished new _call (can't test yet)

Need more work in Perl space first, e.g. _CallProc (now removed
from C)

modified:   Ctypes.xs

11 years agoFinish ConvArg, rename things
Ryan Jendoubi [Wed, 28 Jul 2010 04:01:24 +0000 (05:01 +0100)]
Finish ConvArg, rename things

"pack-style", "pack codes" -> type-codes
  This is to reduce the change of users assuming all the
  type-codes are exactly the same as in pack / FFI.pm.
  Updated naming in code and textual references to the term
  pack and pack-style in POD.

modified:   Ctypes.xs
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Function.pm
modified:   lib/Ctypes/Type.pm
renamed:    src/py_funcs.c -> src/obj_util.c

11 years agoGoing down a wrong route with _CallProc
Ryan Jendoubi [Tue, 27 Jul 2010 15:39:50 +0000 (16:39 +0100)]
Going down a wrong route with _CallProc

Should be doing that in Perl.
About to start on new _call function which takes type objects.
Old _call to be renamed_call_raw

modified:   Ctypes.xs

11 years agoFinished some Py func equivalents
Ryan Jendoubi [Tue, 27 Jul 2010 06:04:02 +0000 (07:04 +0100)]
Finished some Py func equivalents

Back to working in _CallProc now.

modified:   Ctypes.xs
modified:   include/Ctypes.h
modified:   src/py_funcs.c

11 years agoSubstantial restructure of C code, add Licenses
Ryan Jendoubi [Tue, 27 Jul 2010 01:05:04 +0000 (02:05 +0100)]
Substantial restructure of C code, add Licenses

Prompted by basically translating Python's _CallPoc into Perl C.
Very annoying that .c files have to be #included instead of just
specified to MakeMaker in some way.

modified:   Ctypes.xs
new file:   LICENSES
modified:   MANIFEST
modified:   Makefile.PL
modified:   README
new file:   include/Ctypes.h
modified:   lib/Ctypes.pm
modified:   lib/Ctypes/Function.pm
new file:   src/py_funcs.c
new file:   src/util.c

11 years agoAbout 1/2 way through Py style calling
Ryan Jendoubi [Sun, 25 Jul 2010 21:59:17 +0000 (22:59 +0100)]
About 1/2 way through Py style calling

See the following:

http://svn.python.org/projects/external/ctypes/source/callproc.c
(21-60), (417-442)

http://svn.python.org/projects/external/ctypes/source/ctypes.h
(193-258)

http://docs.python.org/library/ctypes.html
Particularly 15.16.2 (Reference section)

modified:   lib/Ctypes/Function.pm
        modified:   lib/Ctypes/Type.pm
  modified:   t/types.t

11 years agoCall c_int::new without initializer
Ryan Jendoubi [Sat, 24 Jul 2010 19:09:15 +0000 (20:09 +0100)]
Call c_int::new without initializer

modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoCleaning up leftover old code in _cast_value
Ryan Jendoubi [Fri, 23 Jul 2010 05:24:24 +0000 (06:24 +0100)]
Cleaning up leftover old code in _cast_value

modified:   Ctypes.xs

11 years agoClean up, use std C macros for type range checks
Ryan Jendoubi [Fri, 23 Jul 2010 05:08:22 +0000 (06:08 +0100)]
Clean up, use std C macros for type range checks

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoVery faulty logic in _cast_value
Ryan Jendoubi [Thu, 22 Jul 2010 22:50:16 +0000 (23:50 +0100)]
Very faulty logic in _cast_value

Just wanted to make a note of it before changing

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm

11 years agoRemoved extraneous tie'ing of $self->{val}
Ryan Jendoubi [Thu, 22 Jul 2010 00:46:20 +0000 (01:46 +0100)]
Removed extraneous tie'ing of $self->{val}

modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoSubtest for setting new val, fixed $DEBUG value
Ryan Jendoubi [Wed, 21 Jul 2010 13:44:16 +0000 (14:44 +0100)]
Subtest for setting new val, fixed $DEBUG value

modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoMade ->(num) work for changing value of Type obj
Ryan Jendoubi [Mon, 19 Jul 2010 00:52:20 +0000 (01:52 +0100)]
Made ->(num) work for changing value of Type obj

modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoCleaned up this example, but...
Ryan Jendoubi [Sun, 18 Jul 2010 05:24:03 +0000 (06:24 +0100)]
Cleaned up this example, but...

This implementation won't work because assigning:

  $char_var = $int_var;

...will change $char_var into a c_int object, instead
of just giving the value as is expected.

Need to change around when tie is done and what overload
funcs do...

modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoWas using tie wrongly
Ryan Jendoubi [Sun, 18 Jul 2010 05:01:01 +0000 (06:01 +0100)]
Was using tie wrongly

Was storing the value manipulated by STORE and FETCH in the same
  part of the object that was tied - the point of course is to
  put it somewhere else.

modified:   lib/Ctypes/Type.pm
modified:   t/types.t

11 years agoFirst (failed) attempt at type objects
Ryan Jendoubi [Sun, 18 Jul 2010 03:54:39 +0000 (04:54 +0100)]
First (failed) attempt at type objects

See lib/Ctypes/Type.pm. Tried to use tie'ing for FETCHing and
  STOREing Type values. 2 problems:
  a) trying to encorporate all in same class is complex
  b) FETCH seems to set its tied var to the value returned
Going to try to fix b) by using overloading instead, then look
  at a) again.

modified:   Ctypes.xs
modified:   lib/Ctypes/Type.pm
new file:   t/types.t

11 years agoFixed Function::new and _form_sig
Ryan Jendoubi [Sat, 17 Jul 2010 14:00:05 +0000 (15:00 +0100)]
Fixed Function::new and _form_sig

_form_sig had never been called before last commit.

modified:   lib/Ctypes/Function.pm

11 years agoFix win32 file perm
doubi [Sat, 17 Jul 2010 02:14:49 +0000 (03:14 +0100)]
Fix win32 file perm

modified:   t/win-proto.t

11 years agoCleaned up debug output messages
doubi [Thu, 15 Jul 2010 16:49:32 +0000 (17:49 +0100)]
Cleaned up debug output messages

Also removed const-c.inc from git

modified:   Ctypes.xs
deleted:    const-c.inc
modified:   lib/Ctypes/Callback.pm
modified:   t/callbacks.t

11 years agoSomewhat ameliorated failing win-proto test
Ryan Jendoubi [Tue, 13 Jul 2010 04:39:24 +0000 (05:39 +0100)]
Somewhat ameliorated failing win-proto test

modified:   MANIFEST
modified:   MANIFEST.SKIP
new file:   lib/Ctypes/WinTypes.pm
modified:   t/win-proto.t

11 years agoFixed win32 func-access.t to match Function::new
Ryan Jendoubi [Tue, 13 Jul 2010 02:32:48 +0000 (03:32 +0100)]
Fixed win32 func-access.t to match Function::new

We die on the attempted creation of a non-extant Function obj
  rather than returning a useless object.

modified:   lib/Ctypes.pm
modified:   t/func-access.t

11 years agoFixed callbacks.t & updated ignore files
Ryan Jendoubi [Mon, 12 Jul 2010 16:53:33 +0000 (17:53 +0100)]
Fixed callbacks.t & updated ignore files

modified:   .gitignore
modified:   MANIFEST.SKIP
modified:   Makefile.PL
modified:   const-c.inc
modified:   ignore.txt
modified:   t/callbacks.t

11 years agoCallbacks work but leak memory
Ryan Jendoubi [Mon, 12 Jul 2010 02:54:30 +0000 (03:54 +0100)]
Callbacks work but leak memory

The closure object seems faulty after ffi_prep_closure_loc.
Tests pass but callbacks.t registers as FAIL due to aborting
  while trying to free closure in global destruction
Also pulled in fixes for other tests from branch py_style_calls.

modified:   Ctypes.xs
modified:   MANIFEST
modified:   lib/Ctypes/Callback.pm
modified:   lib/Ctypes/Type.pm
modified:   t/callbacks.t
modified:   t/pod-coverage.t
modified:   t/win-proto.t

11 years agoRemoved _writable attr, store in cb_data_t
Ryan Jendoubi [Tue, 6 Jul 2010 04:24:47 +0000 (05:24 +0100)]
Removed _writable attr, store in cb_data_t

Allocated ffi_closure (the 'writable' address) now stored in $obj's
cb_data_t struct, exposing less data unnecessarily to Perl-space.

modified:   Ctypes.xs
modified:   lib/Ctypes/Callback.pm
modified:   t/callbacks.t

11 years agoRemoved memory lead in Ctypes::_call
Ryan Jendoubi [Sun, 4 Jul 2010 12:04:32 +0000 (13:04 +0100)]
Removed memory lead in Ctypes::_call

Before memory was not allocated for 'p' argtypes so free'ing was
only done for non 'p' types. Pointer argtypes have been allocated
for a few revisions though; just brought free'ing up to date.

modified:   Ctypes.xs
modified:   t/callbacks.t

11 years ago_perl_cb_call now managing stack correctly
Ryan Jendoubi [Sun, 4 Jul 2010 11:55:56 +0000 (12:55 +0100)]
_perl_cb_call now managing stack correctly

modified:   Ctypes.xs

11 years agoFixed accessing args** from _perl_cb_call
Ryan Jendoubi [Sat, 3 Jul 2010 11:04:16 +0000 (12:04 +0100)]
Fixed accessing args** from _perl_cb_call

See [0]; before the cif was Newx'd but its arg_types is a
/pointer/ to the values given locally in _make_callback,
not a copy. Newx'ing argtypes (Ctypes.xs:461) solves the
problem (with matching Safefree line 532).

To do now:
- Management of Perl stack in _perl_cb_call is wrong somehow,
  values not appearing in @_ in Perl space.
- _make_callback needs cleaned up.
- qsort's $cb currently defined in callbacks.t as taking 2 ints,
  but really requires 2 pointers. Will this become a problem?
  If changed to pointers values will need unpack'd in Perl cb

[0]:
http://old.nabble.com/shallow-copying-in-ffi_prep_cif-td28082268.html

modified:   Ctypes.xs
modified:   t/callbacks.t

11 years agoReally fixed _make_callback now
Ryan Jendoubi [Fri, 2 Jul 2010 20:21:16 +0000 (21:21 +0100)]
Really fixed _make_callback now

... I think. At any rate, now working in both debugging and non-
debugging perls.

Also some cleanup.

modified:   Ctypes.xs
modified:   lib/Ctypes.pm
modified:   t/callbacks.t

11 years agoFixed segfault due to local perlcall_cif
Ryan Jendoubi [Fri, 2 Jul 2010 11:53:16 +0000 (12:53 +0100)]
Fixed segfault due to local perlcall_cif

Noticed _perl_cb_call wasn't receiving the right cif. Clearly
ffi_prep_closure_loc just stores a Pointer to the cif, not by val.
perlcall_cif was just a local variable in _make_closure; now
allocated (and added to struct _perl_cb_data for free'ing later).

Now segfaulting on pushing vars to Perl stack but this should
be simpler.

modified:   Ctypes.xs