Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C/C++: parameters enqueueing as pointers should be deprecated #48

Closed
vassik opened this issue Apr 28, 2014 · 0 comments
Closed

C/C++: parameters enqueueing as pointers should be deprecated #48

vassik opened this issue Apr 28, 2014 · 0 comments

Comments

@vassik
Copy link
Contributor

vassik commented Apr 28, 2014

Following discussion with Franck, we should deprecate enqueueing of a message parameter as a pointer to this parameter. Even though it can work when the parameter is allocated in the heap (e.g. the ThingML String type is generated as char*) and things are run on the same machine.

Moreover, ports and messages are concepts which may be used to communicate between things on different machines; thus, a pointer does not make sense.

In addition, please consider the following erroneous example in ThingML:

thing fragment Messages {
    message send_bytes(mbytes : Byte[32]);
}

thing Sender includes Messages {
....
        state SBytes {
            on entry do
                var data : Byte[32]
                data[0] = '0'
                data[1] = '1' 
                datasender!send_bytes(data)
            end         
....
        }

and generated code for the 'on entry' block in C

void Sender_send_datasender_send_bytes(struct Sender_Instance *_instance, uint8_t* mbytes);

void Sender_Behavior_OnEntry(int state, struct Sender_Instance *_instance) {
...
case SENDER_BEHAVIOR_SBYTES_STATE:
{
uint8_t data[32];
data[0] = '0';
data[1] = '1';
cout << "Send bytes "<<data[0]<< data[1] << endl;
Sender_send_datasender_send_bytes(_instance, data);
}
break;
...
}

Since the message handling happens asynchronously, and we pass a pointer to a value (mbytes) on the stack, the pointer contents is changed.

@vassik vassik changed the title C/C++: parameters enqueueing as pointers should be depricated C/C++: parameters enqueueing as pointers should be deprecated Apr 28, 2014
@brice-morin brice-morin added this to the ThingML v1 milestone Apr 28, 2014
@brice-morin brice-morin assigned nharrand and unassigned ffleurey Oct 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants