8 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/
modified:   lib/Ctypes/
modified:   lib/Ctypes/Type/
modified:   lib/Ctypes/Type/
modified:   t/Array.t
modified:   t/Pointer.t
new file:   t/Struct.t

8 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/
modified:   lib/Ctypes/Type/
modified:   lib/Ctypes/Type/
new file:   lib/Ctypes/Type/
new file:   t/Struct.t_

8 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/
modified:   t/Pointer.t

8 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/

8 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

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

8 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


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/
modified:   lib/Ctypes/
modified:   lib/Ctypes/Type/
new file:   lib/Ctypes/Type/
modified:   t/Array.t
new file:   t/Pointer.t

8 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

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

8 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/
modified:   lib/Ctypes/Type/
modified:   t/Array.t
modified:   t/types.t

8 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/
modified:   lib/Ctypes/
modified:   lib/Ctypes/Type/
modified:   t/Array.t
modified:   t/types.t

8 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

8 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/
modified:   src/obj_util.c
modified:   t/Array.t

8 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

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

8 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:   lib/
modified:   lib/Ctypes/
new file:   lib/Ctypes/Type/
new file:   t/Array.t
modified:   t/types.t

8 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

8 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/
modified:   lib/Ctypes/
modified:   lib/Ctypes/
modified:   t/types.t

8 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

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

8 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

8 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

modified:   lib/Ctypes/
modified:   lib/
modified:   lib/Ctypes/

8 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/
modified:   lib/Ctypes/

8 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

8 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/

8 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/
modified:   lib/Ctypes/
modified:   lib/Ctypes/
modified:   t/002-Function.t

8 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/
modified:   lib/Ctypes/
modified:   lib/Ctypes/
modified:   src/obj_util.c
modified:   t/002-Function.t
modified:   t/types.t
modified:   t/win-proto.t

8 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/

8 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/

8 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/
modified:   lib/Ctypes/
modified:   t/types.t

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

8 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/
modified:   t/types.t

8 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/
modified:   t/002-Function.t
modified:   t/pod-coverage.t
modified:   t/types.t

8 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.

modified:   Ctypes.xs
modified:   lib/Ctypes/
modified:   lib/Ctypes/

8 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/
modified:   lib/Ctypes/
modified:   t/callbacks.t
modified:   t/types.t

8 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

8 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/

8 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/
modified:   src/obj_util.c

8 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

8 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

8 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

8 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 /
  Updated naming in code and textual references to the term
  pack and pack-style in POD.

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

8 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

8 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

8 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/
modified:   lib/Ctypes/
new file:   src/py_funcs.c
new file:   src/util.c

8 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:
(21-60), (417-442)
Particularly 15.16.2 (Reference section)

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

8 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/
modified:   t/types.t

8 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

8 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/
modified:   t/types.t

8 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/

8 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/
modified:   t/types.t

8 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/
modified:   t/types.t

8 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/
modified:   t/types.t

8 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/
modified:   t/types.t

8 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/
modified:   t/types.t

8 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/ 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/
new file:   t/types.t

8 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/

8 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

8 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 from git

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

8 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/
modified:   t/win-proto.t

8 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/
modified:   t/func-access.t

8 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:   ignore.txt
modified:   t/callbacks.t

8 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/
modified:   lib/Ctypes/
modified:   t/callbacks.t
modified:   t/pod-coverage.t
modified:   t/win-proto.t

8 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/
modified:   t/callbacks.t

8 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

8 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

8 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


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

8 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/
modified:   t/callbacks.t

8 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

8 years agoChanged casts to stop compile warnings
Ryan Jendoubi [Fri, 2 Jul 2010 11:12:20 +0000 (12:12 +0100)]
Changed casts to stop compile warnings

All I can think to try now is change the way ptrs are assigned
to the way it was before. Will require changes in a few places.

modified:   Ctypes.xs

8 years agoCleanup, better explanatory debug output
Ryan Jendoubi [Fri, 2 Jul 2010 08:57:27 +0000 (09:57 +0100)]
Cleanup, better explanatory debug output

Still segfaulting in ffi_call on non-debug perl. gdb time.

modified:   Ctypes.xs

8 years agoCleanup / better explanatory debug messages
Ryan Jendoubi [Fri, 2 Jul 2010 08:56:22 +0000 (09:56 +0100)]
Cleanup / better explanatory debug messages

modified:   Ctypes.xs

8 years agoPut ptrs from Perl in more predictable place,but...
Ryan Jendoubi [Fri, 2 Jul 2010 08:43:26 +0000 (09:43 +0100)]
Put ptrs from Perl in more predictable place,but...

Still segfault in non-debugging perl

modified:   Ctypes.xs

8 years agoMore callbacks work
Ryan Jendoubi [Thu, 1 Jul 2010 21:47:46 +0000 (22:47 +0100)]
More callbacks work

Test gets to different points with different build options and
debugging/non-debugging perl.

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

8 years agoIncorporate improved ::Function::sig from branch
Ryan Jendoubi [Thu, 1 Jul 2010 10:23:04 +0000 (11:23 +0100)]
Incorporate improved ::Function::sig from branch

Pulled in from callbacks branch

modified:   lib/Ctypes/

8 years agoImproved new sub sig() in
Ryan Jendoubi [Thu, 1 Jul 2010 10:21:04 +0000 (11:21 +0100)]
Improved new sub sig() in

Check if $self->{argtypes} exists before appending to
abi + restype (which are always given a value on instantiation).

modified:   lib/Ctypes/

8 years agoFixed returning 3 args from _make_callback
Ryan Jendoubi [Thu, 1 Jul 2010 10:13:42 +0000 (11:13 +0100)]
Fixed returning 3 args from _make_callback

Returning pcb_data wasn't working without supplying length of
  pointer to newSVpv.
If dumped with Devel::Peek both _executable and _writable look
  like they have the same value back in Perl. Problem?

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

8 years agoChased down segfault to improper ffi_prep_cif
Ryan Jendoubi [Wed, 30 Jun 2010 23:39:14 +0000 (00:39 +0100)]
Chased down segfault to improper ffi_prep_cif

Also modified ::Function->sig() to create sig if none exists.

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

8 years agoMore callbacks work, much debugging needed
Ryan Jendoubi [Wed, 30 Jun 2010 20:45:47 +0000 (21:45 +0100)]
More callbacks work, much debugging needed

::Callback object now keeps ptr to its own perl_cb_data struct
  for free'ing later.
At one point I'd added the writable closure address to
  perl_cb_data but damned if I can remember why now...
  so removed it.

Results for '"ffi_prep_closure_loc" lang:c' on Google codesearch
  used as reference.

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

8 years agoChange of tactic
Ryan Jendoubi [Wed, 30 Jun 2010 16:53:35 +0000 (17:53 +0100)]
Change of tactic

Callback::new now constructs obj in Perl, calls to _make_callback
in XS to get writable and executable ptrs from ffi_closure_alloc etc.

Everything still v. unfinished

modified:   Ctypes.xs
new file:   lib/Ctypes/

8 years agoCreated perl_cb_data struct
Ryan Jendoubi [Wed, 30 Jun 2010 15:58:59 +0000 (16:58 +0100)]
Created perl_cb_data struct

modified:   Ctypes.xs

8 years agoStart of callbacks work
Ryan Jendoubi [Wed, 30 Jun 2010 12:02:02 +0000 (13:02 +0100)]
Start of callbacks work

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

8 years agoCleanup _call variable declarations
Ryan Jendoubi [Tue, 29 Jun 2010 18:11:14 +0000 (19:11 +0100)]
Cleanup _call variable declarations

modified:   Ctypes.xs

8 years agoMerge branch 'master' of into callbacks
Ryan Jendoubi [Tue, 29 Jun 2010 17:38:34 +0000 (18:38 +0100)]
Merge branch 'master' of into callbacks

8 years agoCleanup _call args
Ryan Jendoubi [Tue, 29 Jun 2010 17:37:50 +0000 (18:37 +0100)]
Cleanup _call args

modified:   Ctypes.xs

8 years agoMerge types and prototypes API.
Reini Urban [Mon, 28 Jun 2010 19:16:10 +0000 (21:16 +0200)]
Merge types and prototypes API.
Improve pod, and add API for the utilities.

8 years agoBetter _call error detection, improve test coverage
Reini Urban [Sun, 27 Jun 2010 10:06:59 +0000 (12:06 +0200)]
Better _call error detection, improve test coverage

Strict check sig for string, otherwise the first arg can be stringified to
  something which looks like a sig.
Test wrong _call usage: coverage 43% - only the types are missing now

8 years agomore DLL docs
Reini Urban [Thu, 24 Jun 2010 20:16:44 +0000 (22:16 +0200)]
more DLL docs

8 years agoMore reading of python ctypes:
Reini Urban [Thu, 24 Jun 2010 20:05:49 +0000 (22:05 +0200)]
More reading of python ctypes:
  renamed rtype => restype, atypes => argtypes
  restype is a DLL default

enhanced POD
out-commented const-*.inc

8 years agoSupport pack-style strings for atypes (brevity)
Reini Urban [Thu, 24 Jun 2010 19:12:14 +0000 (21:12 +0200)]
Support pack-style strings for atypes (brevity)
Fix pod sample.

8 years agoReorder private funcs
Ryan Jendoubi [Thu, 24 Jun 2010 10:33:45 +0000 (11:33 +0100)]
Reorder private funcs

modified:   lib/Ctypes/

8 years agoMerge branch 'master' of
Ryan Jendoubi [Thu, 24 Jun 2010 10:30:52 +0000 (11:30 +0100)]
Merge branch 'master' of

8 years agoFinished adding rurban's logic to Function::new
Ryan Jendoubi [Thu, 24 Jun 2010 10:29:07 +0000 (11:29 +0100)]
Finished adding rurban's logic to Function::new

Defaults now set for $rtype and $abi, checking done on latter.
_call also becomes much simpler.

modified:   lib/Ctypes/

8 years agoremove pod for unused validate_types
Reini Urban [Wed, 23 Jun 2010 19:52:22 +0000 (21:52 +0200)]
remove pod for unused validate_types

8 years ago::Function API more like C::DynaLib/Python ctypes
Ryan Jendoubi [Wed, 23 Jun 2010 19:19:01 +0000 (20:19 +0100)]
::Function API more like C::DynaLib/Python ctypes

Should be more internally consistent. Get/set sig now updates
abi, rtype, atypes. Actual sig passed at call time put together
from these three attributes.
See new POD.

modified:   lib/Ctypes/

8 years agoMerge branch 'master' of
Reini Urban [Tue, 22 Jun 2010 18:34:05 +0000 (20:34 +0200)]
Merge branch 'master' of

Protect from no arg definitions in sig.
func-access.t: skips needs the number
  fix sig (again)


8 years agoRename base class Ctypes::Library to Ctypes:DLL which sounds more natural.
Reini Urban [Tue, 22 Jun 2010 18:22:49 +0000 (20:22 +0200)]
Rename base class  Ctypes::Library to Ctypes:DLL which sounds more natural.
More pod and fix some tests. sigs not sound still.

8 years agoSubstantially simplified rules for sig/abi/rtype
Ryan Jendoubi [Tue, 22 Jun 2010 14:37:17 +0000 (15:37 +0100)]
Substantially simplified rules for sig/abi/rtype

sig must Always be present and will Always be taken to mean
<abi><rtype><arg types>. If abi or rtype are defined separately
they will be substituted in at call time (and sig redefined to

Updated POD and tests to match.

modified:   lib/Ctypes/
modified:   t/002-Function.t
modified:   t/func-access.t
modified:   t/library.t

8 years agoUpdated Ctypes.xs, working on x86_64
Ryan Jendoubi [Tue, 22 Jun 2010 11:22:15 +0000 (12:22 +0100)]
Updated Ctypes.xs, working on x86_64

From branch 'abi_default'

8 years agoMerge, and simplified abi_default
Ryan Jendoubi [Tue, 22 Jun 2010 11:09:45 +0000 (12:09 +0100)]
Merge, and simplified abi_default


8 years agoMake function decl and calls via libraries work
Reini Urban [Tue, 22 Jun 2010 08:13:28 +0000 (10:13 +0200)]
Make function decl and calls via libraries work
t/library.t passes

8 years agoFixed the default _abi for libraries
Reini Urban [Tue, 22 Jun 2010 07:43:01 +0000 (09:43 +0200)]
Fixed the default _abi for libraries
  (compile-time __PACKAGE__ to run-time ref)

8 years agoChange back from atypes to sig, though this is really confusing and NOT
Reini Urban [Tue, 22 Jun 2010 07:22:31 +0000 (09:22 +0200)]
Change back from atypes to sig, though this is really confusing and NOT
the recommended API. You should really keep atypes, or let the user use
the whole sig for simplicity.
Improve pod. Function tests passes now.