Skip to content

Commit

Permalink
Make sure Socket defaults to use the Parrot_default_encoding_ptr, lik…
Browse files Browse the repository at this point in the history
…e it does in master. Refactor some of the encoding logic into Handle to avoid duplication. Socket now has settable encodings. I'm still not happy with the way we store the encoding name as a string and look it up for every IO request.
  • Loading branch information
Whiteknight committed Jun 27, 2012
1 parent 2c2a61b commit 4408cbb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/io/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ io_socket_get_encoding(PARROT_INTERP, ARGIN(PMC *handle))
GETATTR_Socket_encoding(interp, handle, encoding_str);
if (!STRING_IS_NULL(encoding_str))
return Parrot_find_encoding_by_string(interp, encoding_str);
return NULL;
return Parrot_default_encoding_ptr;
}

/*
Expand Down
26 changes: 0 additions & 26 deletions src/pmc/filehandle.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pmclass FileHandle extends Handle auto_attrs {
ATTR INTVAL flags; /* Filehandle flags */
ATTR STRING *filename; /* The opened path and filename */
ATTR STRING *mode; /* The mode string used in open */
ATTR STRING *encoding; /* The encoding for read/write */
ATTR INTVAL process_id; /* Child process on pipes */
ATTR INTVAL exit_status; /* Child exit status on pipes */
ATTR PIOOFF_T file_pos; /* Current real file pointer */
Expand Down Expand Up @@ -537,31 +536,6 @@ Retrieve the read mode string for the filehandle.
RETURN(STRING *mode);
}


/*

=item C<METHOD encoding(STRING *new_encoding)>

Set or retrieve the encoding attribute (a string name of the selected encoding
scheme) for the filehandle.

=cut

*/

METHOD encoding(STRING *new_encoding :optional, INTVAL got_encoding :opt_flag) {
STRING *encoding;

if (got_encoding) {
SET_ATTR_encoding(INTERP, SELF, new_encoding);
RETURN(STRING *new_encoding);
}

GET_ATTR_encoding(INTERP, SELF, encoding);
RETURN(STRING *encoding);
}


/*

=item C<METHOD eof()>
Expand Down
23 changes: 23 additions & 0 deletions src/pmc/handle.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pmclass Handle provides Handle manual_attrs {
ATTR IO_VTABLE *io_vtable; /* Function dispatch table */
ATTR IO_BUFFER *read_buffer; /* Read Buffer */
ATTR IO_BUFFER *write_buffer; /* Write Buffer */
ATTR STRING *encoding; /* The encoding for read/write */


VTABLE void init() {
Expand Down Expand Up @@ -232,6 +233,28 @@ Close the handle.
RETURN(INTVAL status);
}

/*

=item C<METHOD encoding(STRING *new_encoding)>

Set or retrieve the encoding attribute (a string name of the selected encoding
scheme) for the filehandle.

=cut

*/

METHOD encoding(STRING *new_encoding :optional, INTVAL got_encoding :opt_flag) {
STRING *encoding;

if (got_encoding) {
SET_ATTR_encoding(INTERP, SELF, new_encoding);
RETURN(STRING *new_encoding);
}

GET_ATTR_encoding(INTERP, SELF, encoding);
RETURN(STRING *encoding);
}
}

/*
Expand Down
1 change: 0 additions & 1 deletion src/pmc/socket.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pmclass Socket extends Handle provides socket auto_attrs {
ATTR INTVAL family;
ATTR INTVAL type;
ATTR INTVAL protocol;
ATTR STRING *encoding;

/*

Expand Down
26 changes: 1 addition & 25 deletions src/pmc/stringhandle.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ pmclass StringHandle extends Handle auto_attrs {
ATTR INTVAL flags; /* Filehandle flags */
ATTR STRING *stringhandle; /* The string data */
ATTR STRING *mode; /* The mode string used in open */
ATTR STRING *encoding; /* The encoding for read/write */
ATTR STRING *filename; /* A mock path and filename */
ATTR INTVAL read_offset; /* Position, for reading bytes */

Expand All @@ -86,7 +85,7 @@ Initializes a newly created StringHandle object.
data_struct->flags = 0;
data_struct->stringhandle = NULL;
data_struct->mode = NULL;
data_struct->encoding = NULL;
data_struct->encoding = STRINGNULL;
data_struct->filename = NULL;
data_struct->read_offset = 0;
data_struct->io_vtable = (IO_VTABLE *)Parrot_io_get_vtable(interp,
Expand Down Expand Up @@ -366,29 +365,6 @@ Retrieve the read mode string for the stringhandle.

/*

=item C<METHOD encoding(STRING *new_encoding)>

Set or retrieve the encoding attribute (a string name of the selected encoding
scheme) for the stringhandle.

=cut

*/

METHOD encoding(STRING *new_encoding :optional, INTVAL got_encoding :opt_flag) {
STRING *encoding;

if (got_encoding) {
SET_ATTR_encoding(INTERP, SELF, new_encoding);
RETURN(STRING *new_encoding);
}

GET_ATTR_encoding(INTERP, SELF, encoding);
RETURN(STRING *encoding);
}

/*

=item C<METHOD eof()>

Check if the StringHandle is at end-of-file (if it has read to the end of the
Expand Down

0 comments on commit 4408cbb

Please sign in to comment.