slice error

alversonalverson Member Dennis AlversonOrganization: Braxton TechnologiesProject: Orbital Analysis

I have upgraded to 3.7 and my current ice files are getting slice errors that did not occur under 3.6.2. It has to do with forward declarations. I've narrowed it down to the smallest example I could. It is as follows:

module Bt
{
interface SupervisorService;

interface ScheduledActivity
{
    SupervisorService *supervisor();
};

};

When a I slice this file, I get the following error:

C:/dev/AcePremier/AP4-CORE-IDS/Common/BtIceInterface/ScheduledActivity.ice:10: return type uses a proxy for undefined type ::Bt::SupervisorService'C:/dev/AcePremier/AP4-CORE-IDS/Common/BtIceInterface/ScheduledActivity.ice:10: return type uses a proxy for undefined type::Bt::SupervisorService'

Has this functionality changed under 3.7? Or am I missing something about using forward declarartions?

Best Answer

  • bernardbernard Jupiter, FLBernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Accepted Answer

    Forward declarations allow you to define types that refer to each others. For example, an operation on your SupervisorService can take a ScheduledActivity* parameter while an operation on ScheduledActivity returns a SupervisorService*. This functionality has not changed in Ice 3.7.

    What changed is the ability to forward declare a type and then marshal it without defining it - this worked in prior releases even though this was never a documented feature.

    In C++, this undocumented feature relied on helper functions, and you would get a link error if you did not link the generated code for the full definition of the forward declared type. This setup was doable because we used our own smart pointer classes. With the C++11 mapping introduced in Ice 3.7, which relies on standard std::shared_ptr, this is no longer doable. So we fixed the Slice parser to require full definition of forward declared types that get marshaled or unmarshaled.

    Best regards,
    Bernard

Answers

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff

    Hi Dennis,

    We did indeed clarify / change the rule for forward declared types in Ice 3.7 and neglected to mention this change in the Release Notes. Thank you for pointing this out, we'll fix the release notes.

    From the Forward Declarations page:

    The definition of a forward-declared interface or class must appear in the same translation unit if that type is used as a proxy, or if that type is used in any context in which it could be marshaled

    In prior releases, you could forward declare a Slice type and define it an unrelated Slice file, even though the old Forward Declarations page did not describe this situation.

    Best regards,
    Bernard

  • alversonalverson Member Dennis AlversonOrganization: Braxton TechnologiesProject: Orbital Analysis

    Does that mean in my example SupervisorService has to be completely defined in the same ice file as ScheduleActivity? If so, doesn't that defeat the purpose and usefulness of forward declarations.

  • alversonalverson Member Dennis AlversonOrganization: Braxton TechnologiesProject: Orbital Analysis

    This was not a limitation in previous releases. What was the reasoning behind the change?

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Accepted Answer

    Forward declarations allow you to define types that refer to each others. For example, an operation on your SupervisorService can take a ScheduledActivity* parameter while an operation on ScheduledActivity returns a SupervisorService*. This functionality has not changed in Ice 3.7.

    What changed is the ability to forward declare a type and then marshal it without defining it - this worked in prior releases even though this was never a documented feature.

    In C++, this undocumented feature relied on helper functions, and you would get a link error if you did not link the generated code for the full definition of the forward declared type. This setup was doable because we used our own smart pointer classes. With the C++11 mapping introduced in Ice 3.7, which relies on standard std::shared_ptr, this is no longer doable. So we fixed the Slice parser to require full definition of forward declared types that get marshaled or unmarshaled.

    Best regards,
    Bernard

  • alversonalverson Member Dennis AlversonOrganization: Braxton TechnologiesProject: Orbital Analysis

    Gotcha...thanks

Sign In or Register to comment.