Skip to content

Commit 3d02b66

Browse files
committed
RB12-051 Bindings for GIOChannel, GPollFD, GSpawn have been added
Change-Id: If42dcc556229e398edb68a052072a9e5e540d2a6
1 parent 4e6de5f commit 3d02b66

17 files changed

+2119
-15
lines changed

contrib/adaformat.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,14 @@ def convert_from_c(self):
781781
self.cparam, # name of C type for out parameters
782782
c) # convert from previous line to Ada type
783783

784+
def record_field_type(self, pkg=None):
785+
if self.isArray and self.array_fixed_size is not None:
786+
return "%s (1 .. %s)" % (
787+
self.as_ada_param(pkg=pkg),
788+
self.array_fixed_size)
789+
else:
790+
return self.as_c_param(pkg=pkg)
791+
784792

785793
class AdaNaming(object):
786794

@@ -925,6 +933,9 @@ def type(self, name="", cname=None, pkg=None, isArray=False,
925933
elif name in ("array_of_gdouble", ):
926934
t = AdaTypeArray("gdouble")
927935
isArray = True
936+
elif name in ("array_of_gchar", ):
937+
t = AdaTypeArray("gchar")
938+
isArray = True
928939
elif cname == "void":
929940
return None
930941
elif name == "utf8" or cname == "gchar*" or cname == "char*":
@@ -1348,11 +1359,13 @@ def as_call(self, pkg, lang="ada", value=None):
13481359

13491360
class Parameter(Local_Var):
13501361
__slots__ = ["name", "type", "default", "aliased", "mode", "doc",
1351-
"ada_binding", "for_function", "is_temporary_variable"]
1362+
"ada_binding", "for_function", "is_temporary_variable",
1363+
"c_mode", "ownership", "is_caller_allocates"]
13521364

13531365
def __init__(self, name, type, default="", doc="", mode="in",
13541366
for_function=False, ada_binding=True,
1355-
is_temporary_variable=False):
1367+
is_temporary_variable=False, c_mode="in", ownership="none",
1368+
is_caller_allocates=False):
13561369
"""
13571370
'mode' is the mode for the Ada subprogram, and is automatically
13581371
converted when generating a subprogram as a direct C import.
@@ -1367,6 +1380,13 @@ def __init__(self, name, type, default="", doc="", mode="in",
13671380
:param is_temporary_variable: True if this parameter represents a
13681381
local variable. In this case, we can sometimes avoid creating
13691382
other such variables, a minor optimization.
1383+
1384+
:param 'c_mode' is the original mode of parameter in C
1385+
1386+
:param 'ownership' means that caller should free memory if 'full'
1387+
1388+
:param is_caller_allocates: True if memory for the parameter should
1389+
be allocated by method caller
13701390
"""
13711391
assert mode in ("in", "out", "in out", "not null access",
13721392
"access"), "Incorrect mode: %s" % mode
@@ -1377,6 +1397,9 @@ def __init__(self, name, type, default="", doc="", mode="in",
13771397
self.ada_binding = ada_binding
13781398
self.for_function = for_function
13791399
self.is_temporary_variable = is_temporary_variable
1400+
self.c_mode = c_mode
1401+
self.ownership = ownership
1402+
self.is_caller_allocates = is_caller_allocates
13801403

13811404
def _type(self, lang, pkg):
13821405
mode = self.mode

contrib/binding.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,23 @@ def c_params(self, localvars, code):
449449
n = p.name
450450
is_temporary = False
451451

452-
if self.returns is not None and p.mode != "in" and p.ada_binding:
452+
# Restore original mode only for arrays now
453+
# because generator is not adopted for c_mode = p.c_mod and
454+
# generates incorrect code for example for instance parameters
455+
c_mode = p.mode
456+
if p.type.isArray and p.c_mode == "out" \
457+
and p.is_caller_allocates:
458+
# C expects an allocated array like for "in out" mode
459+
# so we will pass an address of buffer's first element
460+
# and do not expect allocation in C
461+
c_mode = "in"
462+
463+
# Pass the array as is, without creating temporary variable
464+
as_array = p.type.isArray and p.is_caller_allocates \
465+
and p.c_mode in ("in", "in out", "out")
466+
467+
if self.returns is not None and p.mode != "in" and p.ada_binding \
468+
and as_array is False:
453469
n = "Acc_%s" % p.name
454470
var = Local_Var(
455471
name=n,
@@ -476,11 +492,14 @@ def c_params(self, localvars, code):
476492
# end up with Interfaces.C.Strings.chars_ptr=""
477493

478494
result.append(Parameter(
479-
name=n, mode=p.mode, type=p.type,
495+
name=n, mode=c_mode, type=p.type,
480496
for_function=self.returns is not None,
481497
default=p.default if not p.ada_binding else None,
482498
is_temporary_variable=is_temporary,
483-
ada_binding=p.ada_binding))
499+
ada_binding=p.ada_binding,
500+
c_mode=p.c_mode,
501+
ownership=p.ownership,
502+
is_caller_allocates=p.is_caller_allocates))
484503

485504
return result
486505

@@ -645,17 +664,25 @@ def _parameters(self, c, gtkmethod, pkg):
645664
assert direction in ("in", "out", "inout", "access"), \
646665
"Invalid value for direction: '%s'" % direction
647666

667+
is_allocated = (gtkparam.get_caller_allocates() or
668+
p.get("caller-allocates", None)) == "1"
669+
670+
ownership = (gtkparam.get_transfer_ownership() or
671+
p.get("transfer-ownership", "none")) == "full"
672+
648673
if direction == "inout":
649-
mode = "in out"
674+
c_mode = "in out"
650675
elif direction in ("out", "access"):
651-
mode = direction
676+
c_mode = direction
652677
elif type.is_ptr:
653-
mode = "in out"
678+
c_mode = "in out"
654679
else:
655-
mode = "in"
680+
c_mode = "in"
656681

657682
if is_function and direction not in ("in", "access"):
658683
mode = "access"
684+
else:
685+
mode = c_mode
659686

660687
doc = _get_clean_doc(p)
661688
if doc:
@@ -667,7 +694,10 @@ def _parameters(self, c, gtkmethod, pkg):
667694
mode=mode,
668695
default=default,
669696
ada_binding=ada_binding,
670-
doc=doc))
697+
doc=doc,
698+
c_mode=c_mode,
699+
ownership=ownership,
700+
is_caller_allocates=is_allocated))
671701

672702
return result
673703

0 commit comments

Comments
 (0)