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

Add chan_send_(int|double|buf), chan_recv_(int|double|buf). #8

Merged
merged 3 commits into from
Sep 5, 2014

Conversation

mattn
Copy link
Contributor

@mattn mattn commented Sep 4, 2014

Related issue #7

Sorry I'm not native specker. I may add mis-spelling or broken phrase. So I didn't write comment.

@mattn
Copy link
Contributor Author

mattn commented Sep 4, 2014

Best way maybe include chan_type in chan_t and validate with CHAN_TYPE_INT/CHAN_TYPE_DOUBLE/etc .

@tylertreat
Copy link
Owner

Can you explain what you mean by that?


int chan_send_int(chan_t* chan, int data)
{
int* wrapped = malloc(sizeof(int));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably check if wrapped == NULL just to be completely safe.

int* wrapped = malloc(sizeof(int));
if (!wrapped)
{
    return -1;
}

@mattn
Copy link
Contributor Author

mattn commented Sep 5, 2014

Can you explain what you mean by that?

go's chan is a typed as specified. chan string chan int. But this product doesn't handle type. So I'm thinking it need to check whether receiving type is a type sent.

@mattn
Copy link
Contributor Author

mattn commented Sep 5, 2014

Done

@tylertreat
Copy link
Owner

I'm not sure how you would implement typed channels. I think the typed
send/recv is a good solution. Do you have anything in mind?
On Sep 4, 2014 8:29 PM, "mattn" [email protected] wrote:

Can you explain what you mean by that?

go's chan is a typed as specified. chan string chan int. But this product
doesn't handle type. So I'm thinking it need to check whether receiving
type is a type sent.


Reply to this email directly or view it on GitHub
#8 (comment).

@mattn
Copy link
Contributor Author

mattn commented Sep 5, 2014

For example:

raw_chan = chan_init(0);

This chan doesn't check a type for sending type.

typed_chan = chan_init_with_type(0, CHAN_TYPE_INT)

This chan check a type for sending type.

@tylertreat
Copy link
Owner

I see what you mean. Enforcing the type might be important since if you have multiple producers sending different data types, you don't know how to receive them. Maybe chan_init should require a type?

typedef int chan_type;
#define CHAN_RAW 0
#define CHAN_INT 1
#define CHAN_DOUBLE 2
chan_t* chan_init(size_t capacity, chan_type type);

@mattn
Copy link
Contributor Author

mattn commented Sep 5, 2014

Maybe chan_init should require a type?

Yes, I'm thinking so.

@tylertreat
Copy link
Owner

I will merge this and the type checking can be added later.

tylertreat added a commit that referenced this pull request Sep 5, 2014
Add chan_send_(int|double|buf), chan_recv_(int|double|buf).
@tylertreat tylertreat merged commit a8a33b2 into tylertreat:master Sep 5, 2014
@tylertreat tylertreat mentioned this pull request Sep 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants