[Patch, fortran] PR 51808 Heap allocate binding labels

Janne Blomqvist blomqvist.janne@gmail.com
Sun Jan 29 17:22:00 GMT 2012

On Wed, Jan 18, 2012 at 14:45, Mikael Morin <mikael.morin@sfr.fr> wrote:
> On 18.01.2012 10:12, Tobias Burnus wrote:
>> Dear Janne,
>>> the attached patch changes the binding labels that are needed for
>>> bind(C) symbols to be heap allocated rather than, as currently, being
>>> fixed size arrays of size 127 (or 64 in module.c!?).
>>  wonder whether it would have been smarter to use string matching rather
>> than the manual matching in gfc_match_name_C to obtain longer strings.
>> (Cf. PR 36275. Different but related binding label issue: PR 38839.)
>> On the other hand, that's separate issues, deserving patches on their own.
>>> --- a/gcc/fortran/resolve.c
>>> +++ b/gcc/fortran/resolve.c
>>> @@ -2744,14 +2747,16 @@ gfc_iso_c_func_interface (gfc_symbol *sym,
>>>        {
>>>          /* two args.  */
>>>          sprintf (name, "%s_2", sym->name);
>>> -         sprintf (binding_label, "%s_2", sym->binding_label);
>>> +         if (sym->binding_label)
>>> +           sprintf (binding_label, "%s_2", sym->binding_label);
>>>          optional_arg = 1;
>> I wonder whether one can get rid of all those binding names. I think
>> they date back to the time when a libgfortran function was called for
>> ISOCBINDING_ASSOCIATED instead of just generating in trans-intrinsics.c
>> one (ptr != NULL) or two (ptr != NULL&&  ptr == tgt) pointer comparisons.
>> I also believe that C_LOC and C_FUNLOC are (now) handled in
>> trans-intrinsics.c. Thus, you could confirm that no binding name is
>> needed and remove them.
>> Otherwise, the patch looks relatively mechnical and is OK.
>> Tobias
> Hello,
> We could consider using gfc_get_string (instead of the many strcpy) to ease
> memory management.

Taking into account the suggestions by Tobias and Mikael, attached is
the patch I just committed. Thanks for the reviews!

2012-01-29  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/51808
	* decl.c (set_binding_label): Move prototype from match.h to here.
	(curr_binding_label): Make a pointer rather than static array.
	(build_sym): Check sym->binding_label pointer rather than array,
	update set_binding_label call, handle curr_binding_label changes.
	(set_binding_label): Handle new curr_binding_label, dest_label
	double ptr, and sym->binding_label.
	(verify_bind_c_sym): Handle sym->binding_label being a pointer.
	(set_verify_bind_c_sym): Check sym->binding_label pointer rather
	than array, update set_binding_label call.
	(gfc_match_bind_c_stmt): Handle curr_binding_label change.
	(match_procedure_decl): Update set_binding_label call.
	(gfc_match_bind_c): Change binding_label to pointer, update
	gfc_match_name_C call.
	* gfortran.h (GFC_MAX_BINDING_LABEL_LEN): Remove macro.
	(gfc_symbol): Make binding_label a pointer.
	(gfc_common_head): Likewise.
	* match.c (gfc_match_name_C): Heap allocate bind(C) name.
	* match.h (gfc_match_name_C): Change prototype argument.
	(set_binding_label): Move prototype to decl.c.
	* module.c (struct pointer_info): Make binding_label a pointer.
	(free_pi_tree): Free unused binding_label.
	(mio_read_string): New function.
	(mio_write_string): New function.
	(load_commons): Redo reading of binding_label.
	(read_module): Likewise.
	(write_common_0): Change to write empty string instead of name if
	no binding_label.
	(write_blank_common): Write empty string for binding label.
	(write_symbol): Change to write empty string instead of name if no
	* resolve.c (gfc_iso_c_func_interface): Don't set binding_label.
	(set_name_and_label): Make binding_label double pointer, use
	(gfc_iso_c_sub_interface): Make binding_label a pointer.
	(resolve_bind_c_comms): Handle cases if
	gfc_common_head->binding_label is NULL.
	(gfc_verify_binding_labels): sym->binding_label is a pointer.
	* symbol.c (gfc_free_symbol): Free binding_label.
	(gfc_new_symbol): Rely on XCNEW zero init for binding_label.
	(gen_special_c_interop_ptr): Don't set binding label.
	(generate_isocbinding_symbol): Insert binding_label into symbol
	(get_iso_c_sym): Use pointer assignment instead of strcpy.
	* trans-common.c (gfc_sym_mangled_common_id): Handle
	com->binding_label being a pointer.
	* trans-decl.c (gfc_sym_mangled_identifier): Handle
	sym->binding_label being a pointer.
	(gfc_sym_mangled_function_id): Likewise.

testsuite ChangeLog

2012-01-29  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/51808
	* gfortran.dg/module_md5_1.f90: Update MD5 sum.

Janne Blomqvist
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr51808.v2.diff
Type: text/x-patch
Size: 28740 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20120129/1e828c1e/attachment.bin>

More information about the Gcc-patches mailing list