pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:1:   /* -*- c -*-   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin.cmod,v 1.194 2008/02/27 23:59:12 grubba Exp $ + || $Id: builtin.cmod,v 1.195 2008/03/09 20:46:47 grubba Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"
pike.git/src/builtin.cmod:2908:   #define EXIT_BLOCK(NODE) do { \    if ((NODE)->prev) { \    free_list_node((NODE)->prev); \    } \    if ((NODE)->next) { \    free_list_node((NODE)->next); \    } \    free_svalue(&(NODE)->val); \    } while(0)    - BLOCK_ALLOC_FILL_PAGES(list_node, 4); + BLOCK_ALLOC_FILL_PAGES(pike_list_node, 4);    - PMOD_EXPORT void free_list_node(struct list_node *node) + PMOD_EXPORT void free_list_node(struct pike_list_node *node)   {    if (!sub_ref(node)) { -  really_free_list_node(node); +  really_free_pike_list_node(node);    }   }    - PMOD_EXPORT void unlink_list_node(struct list_node *n) + PMOD_EXPORT void unlink_list_node(struct pike_list_node *n)   {   #ifdef PIKE_DEBUG    if (!n) {    Pike_fatal("Unlinking NULL node.\n");    }    if (!n->next || !n->prev) {    Pike_fatal("Unlinking unlinked node.\n");    }   #endif /* PIKE_DEBUG */    if (n->prev->next == n) {
pike.git/src/builtin.cmod:2951:   #ifdef PIKE_DEBUG    if (n->next->prev == n) {    Pike_fatal("Partially detached node.\n");    }   #endif /* PIKE_DEBUG */    /* The node is already detached. */    n->next = n->prev = NULL;    }   }    - PMOD_EXPORT void detach_list_node(struct list_node *n) + PMOD_EXPORT void detach_list_node(struct pike_list_node *n)   {   #ifdef PIKE_DEBUG    if (!n) {    Pike_fatal("Detaching NULL node.\n");    }    if (!n->next || !n->prev) {    Pike_fatal("Detaching unlinked node.\n");    }   #endif /* PIKE_DEBUG */    if (n->prev->next == n) {
pike.git/src/builtin.cmod:2982:    /* We've lost two references. */    free_list_node(n);    free_list_node(n);   #ifdef PIKE_DEBUG    } else if (n->next->prev == n) {    Pike_fatal("Partially detached node.\n");   #endif /* PIKE_DEBUG */    }   }    - PMOD_EXPORT void prepend_list_node(struct list_node *node, -  struct list_node *new_node) + PMOD_EXPORT void prepend_list_node(struct pike_list_node *node, +  struct pike_list_node *new_node)   {   #ifdef PIKE_DEBUG    if (!node) {    Pike_fatal("No node to prepend.\n");    }    if (!node->prev) {    Pike_fatal("Prepending unhooked node.\n");    }    if (!new_node) {    Pike_fatal("Prepending NULL node.\n");
pike.git/src/builtin.cmod:3006:    Pike_fatal("Prepending hooked node.\n");    }   #endif /* PIKE_DEBUG */    new_node->next = node;    new_node->prev = node->prev;    new_node->prev->next = node->prev = new_node;    add_ref(new_node);    add_ref(new_node);   }    - PMOD_EXPORT void append_list_node(struct list_node *node, -  struct list_node *new_node) + PMOD_EXPORT void append_list_node(struct pike_list_node *node, +  struct pike_list_node *new_node)   {   #ifdef PIKE_DEBUG    if (!node) {    Pike_fatal("No node to append.\n");    }    if (!node->next) {    Pike_fatal("Appending unhooked node.\n");    }    if (!new_node) {    Pike_fatal("Appending NULL node.\n");
pike.git/src/builtin.cmod:3039:      /*! @module ADT    */      /*! @class List    *!    *! Linked list of values.    */   PIKECLASS List   { -  CVAR struct list_node *head; +  CVAR struct pike_list_node *head;    CVAR INT32 head_sentinel_refs; -  CVAR struct list_node *tail; /* Always NULL. */ +  CVAR struct pike_list_node *tail; /* Always NULL. */    CVAR INT32 tail_sentinel_refs; -  CVAR struct list_node *tail_pred; +  CVAR struct pike_list_node *tail_pred;    CVAR INT32 num_elems;    - #define HEAD_SENTINEL(this) ((struct list_node *)(&this->head)) - #define TAIL_SENTINEL(this) ((struct list_node *)(&this->tail)) + #define HEAD_SENTINEL(this) ((struct pike_list_node *)(&this->head)) + #define TAIL_SENTINEL(this) ((struct pike_list_node *)(&this->tail))       /* Sentinel overlap description:    *    * List Head sentinel Tail sentinel    * head next    * head_sentinel_refs refs    * tail prev next    * tail_sentinel_refs refs    * tail_pred prev    */
pike.git/src/builtin.cmod:3084:    {    THIS->tail = NULL;    THIS->head = TAIL_SENTINEL(THIS);    THIS->tail_pred = HEAD_SENTINEL(THIS);    THIS->head_sentinel_refs = THIS->tail_sentinel_refs = 2;    THIS->num_elems = 0;    }       EXIT    { -  struct list_node *node = THIS->head; -  struct list_node *next; +  struct pike_list_node *node = THIS->head; +  struct pike_list_node *next;    while ((next = node->next)) {   #ifdef PIKE_DEBUG    if (node->refs != 2) {    Pike_fatal("Unexpected number of references for node: %d\n",    node->refs);    }   #endif /* PIKE_DEBUG */    unlink_list_node(node);    node = next;    }    }       /* These two functions perform the same thing,    * but are optimized to minimize recursion.    */ -  static void gc_check_list_node_backward(struct list_node *node, +  static void gc_check_list_node_backward(struct pike_list_node *node,    const char *msg); -  static void gc_check_list_node_forward(struct list_node *node, +  static void gc_check_list_node_forward(struct pike_list_node *node,    const char *msg)    {    while (node && !debug_gc_check(&node->refs, msg)) {    if (node->next)    debug_gc_check_svalues(&node->val, 1, " as a list node value");    gc_check_list_node_backward(node->prev, msg);    node = node->next;    }    }    -  static void gc_check_list_node_backward(struct list_node *node, +  static void gc_check_list_node_backward(struct pike_list_node *node,    const char *msg)    {    while (node && !debug_gc_check(&node->refs, msg)) {    if (node->prev)    debug_gc_check_svalues(&node->val, 1, " as a list node value");    gc_check_list_node_forward(node->next, msg);    node = node->prev;    }    }       /* Called at gc_check time. */    GC_CHECK    {    gc_check_list_node_backward(HEAD_SENTINEL(THIS), " as a list node");    gc_check_list_node_forward(TAIL_SENTINEL(THIS), " as a list node");    }       /* Called at gc_mark time */    GC_RECURSE    { -  struct list_node *node = THIS->head; -  struct list_node *next; +  struct pike_list_node *node = THIS->head; +  struct pike_list_node *next;    while ((next = node->next)) {    gc_recurse_svalues(&node->val, 1);    node = next;    }    }       /*! @decl int(0..1) is_empty()    *!    *! Check if the list is empty.    *!
pike.git/src/builtin.cmod:3179:    *!    *! @seealso    *! @[sprintf()], @[lfun::_sprintf()]    */    PIKEFUN string _sprintf(int c, mapping(string:mixed)|void attr)    flags ID_STATIC;    {    if (!THIS->num_elems) {    push_constant_text("ADT.List(/* empty */)");    } else if (c == 'O') { -  struct list_node *node = THIS->head; +  struct pike_list_node *node = THIS->head;    if (THIS->num_elems == 1) {    push_constant_text("ADT.List(/* 1 element */\n");    } else {    push_constant_text("ADT.List(/* %d elements */\n");    push_int(THIS->num_elems);    f_sprintf(2);    }    while (node->next) {    if (node->next->next) {    push_constant_text(" %O,\n");
pike.git/src/builtin.cmod:3283:       /*! @decl void append(mixed ... values)    *!    *! Append @[values] to the end of the list.    *!    *! @seealso    *! @[insert()]    */    PIKEFUN void append(mixed ... values)    { -  struct list_node *node = TAIL_SENTINEL(THIS); +  struct pike_list_node *node = TAIL_SENTINEL(THIS);    while (args--) { -  struct list_node *new_node = alloc_list_node(); +  struct pike_list_node *new_node = alloc_pike_list_node();    new_node->val = *(--Pike_sp);    prepend_list_node(node, new_node);    free_list_node(node = new_node);    THIS->num_elems++;    }    push_int(0);    }       /*! @decl void insert(mixed ... values)    *!    *! Insert @[values] at the front of the list.    *!    *! @seealso    *! @[append()]    */    PIKEFUN void insert(mixed ... values)    { -  struct list_node *node = THIS->head; +  struct pike_list_node *node = THIS->head;    while (args--) { -  struct list_node *new_node = alloc_list_node(); +  struct pike_list_node *new_node = alloc_pike_list_node();    new_node->val = *(--Pike_sp);    prepend_list_node(node, new_node);    free_list_node(node = new_node);    THIS->num_elems++;    }    push_int(0);    }       /*! @decl void create(mixed ... values)    *!
pike.git/src/builtin.cmod:3336:    }       /*! @class _get_iterator    *!    *! @[Iterator] that loops over the @[List].    */    PIKECLASS _get_iterator    program_flags PROGRAM_USES_PARENT;    flags ID_STATIC;    { -  CVAR struct list_node *cur; +  CVAR struct pike_list_node *cur;    CVAR INT32 ind; /* Not meaningful, but requred by the API. */       /* NOTE: cur may never refer to an unlinked node.    * cur may however refer to a detached node, or to sentinels.    */       static struct List_struct *List__get_iterator_find_parent()    {    struct external_variable_context loc;   
pike.git/src/builtin.cmod:3378:       /* Called at gc_check time. */    GC_CHECK    {    gc_check_list_node_forward(THIS->cur, " held by an iterator");    }       /* These two functions perform the same thing,    * but are optimized to minimize recursion.    */ -  static void gc_recurse_list_node_tree_backward(struct list_node *node, -  struct list_node *back); -  static void gc_recurse_list_node_tree_forward(struct list_node *node, -  struct list_node *back) +  static void gc_recurse_list_node_tree_backward(struct pike_list_node *node, +  struct pike_list_node *back); +  static void gc_recurse_list_node_tree_forward(struct pike_list_node *node, +  struct pike_list_node *back)    {    if (!node || !node->next) return;    if (node->next->prev == node) {    /* List member. Recursed from the list recurse code. */   #ifdef PIKE_DEBUG    if (node->prev->next != node) {    Pike_fatal("Partially detached node.\n");    }   #endif /* PIKE_DEBUG */    return;
pike.git/src/builtin.cmod:3421:    break;    }   #ifdef PIKE_DEBUG    if (node->prev->next == node) {    Pike_fatal("Partially detached node.\n");    }   #endif /* PIKE_DEBUG */    }    }    -  static void gc_recurse_list_node_tree_backward(struct list_node *node, -  struct list_node *next) +  static void gc_recurse_list_node_tree_backward(struct pike_list_node *node, +  struct pike_list_node *next)    {    if (!node || !node->prev) return;    if (node->prev->next == node) {    /* List member. Checked from the list check code. */   #ifdef PIKE_DEBUG    if (node->next->prev != node) {    Pike_fatal("Partially detached node.\n");    }   #endif /* PIKE_DEBUG */    return;
pike.git/src/builtin.cmod:3562:    *!    *! @returns    *! Returns @expr{1@} on success, and @expr{0@} (zero)    *! at the end of the list.    *!    *! @seealso    *! @[prev()]    */    PIKEFUN int(0..1) next()    { -  struct list_node *next; +  struct pike_list_node *next;    if ((next = THIS->cur->next)) {    free_list_node(THIS->cur);    add_ref(THIS->cur = next);    THIS->ind++;    if (next->next) {    pop_n_elems(args);    push_int(1);    return;    }    }
pike.git/src/builtin.cmod:3590:    *!    *! @returns    *! Returns @expr{1@} on success, and @expr{0@} (zero)    *! at the beginning of the list.    *!    *! @seealso    *! @[next()]    */    PIKEFUN int(0..1) prev()    { -  struct list_node *prev; +  struct pike_list_node *prev;    if ((prev = THIS->cur->prev)) {    free_list_node(THIS->cur);    add_ref(THIS->cur = prev);    THIS->ind--;    if (prev->prev) {    pop_n_elems(args);    push_int(1);    return;    }    }
pike.git/src/builtin.cmod:3639:       /*! @decl void insert(mixed val)    *!    *! Insert @[val] at the current position.    *!    *! @seealso    *! @[append()], @[delete()], @[set()]    */    PIKEFUN void insert(mixed val)    { -  struct list_node *new_node; +  struct pike_list_node *new_node;    if (!THIS->cur->prev) {    Pike_error("Attempt to insert before the start sentinel.\n");    } -  new_node = alloc_list_node(); +  new_node = alloc_pike_list_node();    assign_svalue_no_free(&new_node->val, val);    prepend_list_node(THIS->cur, new_node);    free_list_node(THIS->cur);    THIS->cur = new_node;    List__get_iterator_find_parent()->num_elems++;    pop_n_elems(args);    push_int(0);    }       /*! @decl void append(mixed val)    *!    *! Append @[val] after the current position.    *!    *! @seealso    *! @[insert()], @[delete()], @[set()]    */    PIKEFUN void append(mixed val)    { -  struct list_node *new_node; +  struct pike_list_node *new_node;    if (!THIS->cur->next) {    Pike_error("Attempt to append after the end sentinel.\n");    } -  new_node = alloc_list_node(); +  new_node = alloc_pike_list_node();    assign_svalue_no_free(&new_node->val, val);    append_list_node(THIS->cur, new_node);    free_list_node(new_node);    List__get_iterator_find_parent()->num_elems++;    pop_n_elems(args);    push_int(0);    }       /*! @decl void delete()    *!
pike.git/src/builtin.cmod:3688:    *!    *! The current position will advance to the next node.    *! This function thus performes the reverse operation    *! of @[insert()].    *!    *! @seealso    *! @[insert()], @[append()], @[set()]    */    PIKEFUN void delete()    { -  struct list_node *next; +  struct pike_list_node *next;    if (!(next = THIS->cur->next) || !THIS->cur->prev) {    Pike_error("Attempt to delete a sentinel.\n");    }    add_ref(next);    if (next->prev == THIS->cur) {    if (THIS->cur->refs == 3) {    unlink_list_node(THIS->cur);    } else {    /* There's some other iterator holding references to this node. */    detach_list_node(THIS->cur);
pike.git/src/builtin.cmod:3736:    */   }   /*! @endclass    */      /*! @endmodule    */      void init_builtin(void)   { -  init_list_node_blocks(); +  init_pike_list_node_blocks();   INIT   }      void exit_builtin(void)   {   EXIT -  free_all_list_node_blocks(); +  free_all_pike_list_node_blocks();   }