Skip to content

Commit

Permalink
Type size cleanliness
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Mar 5, 2010
1 parent 7df9844 commit 2dcaba6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
64 changes: 29 additions & 35 deletions src/Compact.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ac_handle_sort

SV **htab;
int shift;
int hused;
UV hused;
};

int ac_free_handle_magic(pTHX_ SV* sv, MAGIC* mg);
Expand Down Expand Up @@ -63,11 +63,12 @@ struct ac_class

void *first_page;
void *last_page;
int total_objects;
int total_pages;
int obj_size_bytes;
UV total_objects;
UV total_pages;
UV obj_size_bytes;
UV obj_alloc_bits;

int used_objects;
UV used_objects;
ac_object freelist_head;

/* TODO implement compacter
Expand All @@ -86,7 +87,7 @@ struct ac_class
#define AC_LIFE_REF 3
#define AC_LIFE_REF8 4

struct ac_class *ac_new_class(struct ac_type *ty, int nbytes, int lifetime,
struct ac_class *ac_new_class(struct ac_type *ty, UV nbytes, int lifetime,
SV *metaclass, HV *stash);

ac_object ac_new_object(struct ac_class *cl);
Expand All @@ -101,10 +102,10 @@ ac_object ac_forward_object(ac_object o);
*/

/* These should not be assumed to work above 32 */
UV ac_object_fetch(ac_object o, int bitoff, int count);
IV ac_object_fetch_signed(ac_object o, int bitoff, int count);
/* does no error checking, deliberately */
void ac_object_store(ac_object o, int bitoff, int count, UV val);
UV ac_object_fetch(ac_object o, UV bitoff, UV count);
IV ac_object_fetch_signed(ac_object o, UV bitoff, UV count);
/* does no value checking, deliberately */
void ac_object_store(ac_object o, UV bitoff, UV count, UV val);

/*
* Things you can do with a (sub)object of some type. These functions fall
Expand All @@ -116,38 +117,35 @@ void ac_object_store(ac_object o, int bitoff, int count, UV val);
struct ac_type_ops
{
/*
* Locate a subobject. Should croak if the subobject does not exist. If
* the subobject is actually a Perl scalar, it can be returned instead (for
* the perl_array and perl_hash types).
* Locate a subobject. Should croak if the subobject does not exist.
*/
void (*subobject)(struct ac_type *ty, ac_object obj, int bit_in_obj,
SV *name, ac_object *oret, int *bret, struct ac_type **tyret,
SV **pret);
void (*subobject)(struct ac_type *ty, ac_object obj, UV bit_in_obj,
SV *name, ac_object *oret, UV *bret, struct ac_type **tyret);

/*
* Does a subobject with the given name exist?
*/
int (*subobject_exists)(struct ac_type *ty, ac_object obj, int bit_in_obj,
int (*subobject_exists)(struct ac_type *ty, ac_object obj, UV bit_in_obj,
SV *name);

/* TODO - subobject interrogation and editing, for mutable types */

/* Copy a value out of the (sub)object. */
void (*scalar_get)(struct ac_type *ty, ac_object obj, int bit_in_obj,
void (*scalar_get)(struct ac_type *ty, ac_object obj, UV bit_in_obj,
SV *ret);

/* Copy in. Croaks if data validation error. */
void (*scalar_put)(struct ac_type *ty, ac_object obj, int bit_in_obj,
void (*scalar_put)(struct ac_type *ty, ac_object obj, UV bit_in_obj,
SV *from);

/*
* Bring an *uninitialized* block of memory to some zero/default state;
* it will already have been zeroed.
*/
void (*initialize)(struct ac_type *ty, ac_object obj, int bit_in_obj);
void (*initialize)(struct ac_type *ty, ac_object obj, UV bit_in_obj);

/* Drop references so an object can be deleted. */
void (*destroy)(struct ac_type *ty, ac_object obj, int bit_in_obj);
void (*destroy)(struct ac_type *ty, ac_object obj, UV bit_in_obj);

/*
* Translocate an object while preserving external back references. This
Expand All @@ -156,7 +154,7 @@ struct ac_type_ops
* when this is called.
*/
void (*translocate)(struct ac_type *ty, ac_object oldo, ac_object newo,
int bit_in_obj);
UV bit_in_obj);

/*
* Generic hook for post-compaction cleanup. Ref hash tables need to
Expand All @@ -167,13 +165,13 @@ struct ac_type_ops
/*
* Mark the targets of all pointers which point into GCable zones.
*/
void (*mark)(struct ac_type *ty, ac_object obj, int bit_in_obj);
void (*mark)(struct ac_type *ty, ac_object obj, UV bit_in_obj);

/*
* Run all pointers through the forwarding system, in the final phase of
* the compaction process.
*/
void (*forwardize)(struct ac_type *ty, ac_object obj, int bit_in_obj);
void (*forwardize)(struct ac_type *ty, ac_object obj, UV bit_in_obj);

/* Convert to a string for diagnostics */
void (*deparse)(struct ac_type *ty, SV *strbuf);
Expand All @@ -187,7 +185,7 @@ struct ac_type_ops
struct ac_type
{
struct ac_type_ops *ops;
unsigned int inline_size;
UV inline_size;
unsigned int flags;
#define AC_INITIALIZE_USED 1
#define AC_DESTROY_USED 2
Expand All @@ -211,6 +209,8 @@ struct ac_type *ac_make_float_type(int expbits, int sigbits);
struct ac_type *ac_make_nv_type(void);
struct ac_type *ac_make_iv_type(void);
struct ac_type *ac_make_uv_type(void);
struct ac_type *ac_make_numish_type(void);
struct ac_type *ac_make_intish_type(void);

/* An 8-bit character in some charset. */
struct ac_type *ac_make_natl_char_type(SV *encode_instance);
Expand Down Expand Up @@ -241,27 +241,21 @@ struct ac_type *ac_make_ref_type(void);

struct ac_type *ac_make_weak_ref_type(void);

/* Holds a reference to one SV */
struct ac_type *ac_make_perl_scalar_type(void);

struct ac_type *ac_make_perl_ref_type(void);
struct ac_type *ac_make_perl_weakref_type(void);

struct ac_type *ac_make_perl_array_type(void);
struct ac_type *ac_make_perl_hash_type(void);
struct ac_type *ac_make_perl_glob_type(void);
struct ac_type *ac_make_perl_filehandle_ref_type(void);

struct ac_type *ac_make_void_type(void);

/* These functions automatically handle croaking */

void ac_do_subobject(struct ac_type **typ, ac_object **op, int **offp,
void ac_do_subobject(struct ac_type **typ, ac_object *op, UV *offp,
SV *selector);

void ac_do_set(struct ac_type *ty, ac_object o, int off, SV *val);
void ac_do_get(struct ac_type *ty, ac_object o, int off, SV *ret);
void ac_do_set(struct ac_type *ty, ac_object o, UV off, SV *val);
void ac_do_get(struct ac_type *ty, ac_object o, UV off, SV *ret);

int ac_child_exists(struct ac_type *ty, ac_object o, int off, SV *sel);
int ac_child_exists(struct ac_type *ty, ac_object o, UV off, SV *sel);

#endif
4 changes: 2 additions & 2 deletions src/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <perl.h>
#include "Compact.h"

#define HASHPTR(p,s) (((0x9E3779B9U * PTR2UV(p)) & 0xFFFFFFFFU) >> s)
#define HASHPTR(p,s) (((0x9E3779B9UL * PTR2UV(p)) & 0xFFFFFFFFUL) >> s)

/*
* This file implements a system of idiotproof Perl->C handles - scalars which
Expand Down Expand Up @@ -92,7 +92,7 @@ SV *ac_rehandle(pTHX_ struct ac_handle_sort *kind, void *val)

/* TODO: rehashing */

int hash = HASHPTR(val, kind->shift);
UV hash = (UV)HASHPTR(val, kind->shift);
mg->mg_obj = kind->htab[hash];
kind->htab[hash] = sv;
}
Expand Down
14 changes: 5 additions & 9 deletions src/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
* fragmentation, we put pages into an ordered sequence, and allow objects to
* span pages. This means that object storage is OFTEN DISCONTIGUOUS.
*
* TODO: This module is not 64 bit clean, and will have problems with systems
* that have -interesting- pointer formats. Improve.
*
* TODO: This module isn't global destruction clean either.
*
* TODO: Abstract the allocation logic and make it threadsafe.
Expand All @@ -39,14 +36,14 @@ struct page_header
struct ac_class *claz;
struct page_header *nextp;
struct page_header *prevp;
int serialno;
UV serialno;
};

struct page_header *free_page;

static void ac_delete_class(void *clp);

AC_DEFINE_HANDLE_SORT(class, NULL, ac_delete_class, 0);
AC_DEFINE_HANDLE_SORT(class, 0, ac_delete_class, 0);

struct ac_class *ac_new_class(struct ac_type *ty, int nbytes, int lifetime,
SV *metaclass, HV *stash)
Expand Down Expand Up @@ -119,7 +116,6 @@ static void ac_free_handle(ac_object o) {

ac_object ac_new_object(struct ac_class *cl) {
ac_object o;
int rc = 0;

if (!cl->freelist_head)
ac_refill(cl);
Expand Down Expand Up @@ -161,6 +157,6 @@ void ac_ref_object(ac_object o) {
void ac_unref_object(ac_object o) {
}

UV ac_object_fetch(ac_object o, int bitoff, int count);
IV ac_object_fetch_signed(ac_object o, int bitoff, int count);
void ac_object_store(ac_object o, int bitoff, int count, UV val);
UV ac_object_fetch(ac_object o, UV bitoff, UV count);
IV ac_object_fetch_signed(ac_object o, UV bitoff, UV count);
void ac_object_store(ac_object o, UV bitoff, UV count, UV val);

0 comments on commit 2dcaba6

Please sign in to comment.